Skip to content

Commit bd9fd42

Browse files
committed
feat:更新环境依赖,使用uv管理
1 parent 37e7d78 commit bd9fd42

File tree

15 files changed

+4848
-177
lines changed

15 files changed

+4848
-177
lines changed

src/backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ WORKDIR /app
44

55
COPY ./ ./
66

7-
RUN poetry config virtualenvs.create false
8-
RUN poetry update --without dev
7+
RUN uv pip install -r <(uv pip compile pyproject.toml --upgrade) --system --no-cache-dir && \
8+
uv cache clean
99

1010
# patch langchain-openai lib. remove this when langchain-openai support reasoning_content
1111
RUN patch -p1 < /app/bisheng/patches/langchain_openai.patch /usr/local/lib/python3.10/site-packages/langchain_openai/chat_models/base.py

src/backend/base.Dockerfile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ RUN apt-get update && \
1111
apt-get install -y --no-install-recommends \
1212
gcc g++ curl build-essential libreoffice \
1313
wget procps vim fonts-wqy-zenhei \
14-
libglib2.0-0 libsm6 libxrender1 libxext6 libgl1 ffmpeg \
14+
libglib2.0-0 libsm6 libxrender1 libxext6 libgl1 \
1515
&& rm -rf /var/lib/apt/lists/*
1616

17+
# 安装 FFmpeg
18+
RUN apt-get install -y ffmpeg && \
19+
rm -rf /var/lib/apt/lists/*
20+
1721

1822
# 安装 pandoc
1923
RUN mkdir -p /opt/pandoc && \
@@ -27,16 +31,21 @@ RUN mkdir -p /opt/pandoc && \
2731
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
2832

2933
# 安装 Poetry
30-
RUN curl -sSL https://install.python-poetry.org | python3 - --version 1.8.2
34+
#RUN curl -sSL https://install.python-poetry.org | python3 - --version 1.8.2
3135

3236
# 拷贝项目依赖文件
3337
COPY ./pyproject.toml ./
3438

3539
# 安装 Python 依赖
3640
RUN python -m pip install --upgrade pip && \
37-
pip install shapely==2.0.1 && \
38-
poetry config virtualenvs.create false && \
39-
poetry install --no-interaction --no-ansi --without dev
41+
uv pip install -r <(uv pip compile pyproject.toml) --system --no-cache-dir && \
42+
uv cache clean
43+
44+
45+
#RUN python -m pip install --upgrade pip && \
46+
# pip install shapely==2.0.1 && \
47+
# poetry config virtualenvs.create false && \
48+
# poetry install --no-interaction --no-ansi --without dev
4049

4150
# 安装 NLTK 数据
4251
RUN python -c "import nltk; nltk.download('punkt'); nltk.download('punkt_tab'); nltk.download('averaged_perceptron_tagger'); nltk.download('averaged_perceptron_tagger_eng')"

src/backend/bisheng/core/ai/rerank/xinference/__init__.py

Whitespace-only changes.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Copyright 2022-2024 XProbe Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from typing import Dict, Iterable, List, Literal, Optional, Union
15+
16+
from pydantic.version import VERSION as PYDANTIC_VERSION
17+
18+
PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
19+
20+
21+
if PYDANTIC_V2:
22+
from pydantic.v1 import ( # noqa: F401
23+
BaseModel,
24+
Field,
25+
Protocol,
26+
ValidationError,
27+
create_model,
28+
create_model_from_namedtuple,
29+
create_model_from_typeddict,
30+
parse_file_as,
31+
validate_arguments,
32+
validator,
33+
)
34+
from pydantic.v1.error_wrappers import ErrorWrapper # noqa: F401
35+
from pydantic.v1.parse import load_str_bytes # noqa: F401
36+
from pydantic.v1.types import StrBytes # noqa: F401
37+
from pydantic.v1.utils import ROOT_KEY # noqa: F401
38+
else:
39+
from pydantic import ( # noqa: F401
40+
BaseModel,
41+
Field,
42+
Protocol,
43+
ValidationError,
44+
create_model,
45+
create_model_from_namedtuple,
46+
create_model_from_typeddict,
47+
parse_file_as,
48+
validate_arguments,
49+
validator,
50+
)
51+
from pydantic.error_wrappers import ErrorWrapper # noqa: F401
52+
from pydantic.parse import load_str_bytes # noqa: F401
53+
from pydantic.types import StrBytes # noqa: F401
54+
from pydantic.utils import ROOT_KEY # noqa: F401
55+
56+
from openai.types.chat.chat_completion_named_tool_choice_param import (
57+
ChatCompletionNamedToolChoiceParam,
58+
)
59+
from openai.types.chat.chat_completion_stream_options_param import (
60+
ChatCompletionStreamOptionsParam,
61+
)
62+
from openai.types.chat.chat_completion_tool_param import ChatCompletionToolParam
63+
from openai.types.shared_params.response_format_json_object import (
64+
ResponseFormatJSONObject,
65+
)
66+
from openai.types.shared_params.response_format_text import ResponseFormatText
67+
68+
OpenAIChatCompletionStreamOptionsParam = create_model_from_typeddict(
69+
ChatCompletionStreamOptionsParam
70+
)
71+
OpenAIChatCompletionToolParam = create_model_from_typeddict(ChatCompletionToolParam)
72+
OpenAIChatCompletionNamedToolChoiceParam = create_model_from_typeddict(
73+
ChatCompletionNamedToolChoiceParam
74+
)
75+
from openai._types import Body
76+
77+
78+
class JSONSchema(BaseModel):
79+
name: str
80+
description: Optional[str] = None
81+
schema_: Optional[Dict[str, object]] = Field(alias="schema", default=None)
82+
strict: Optional[bool] = None
83+
84+
85+
class ResponseFormatJSONSchema(BaseModel):
86+
json_schema: JSONSchema
87+
type: Literal["json_schema"]
88+
89+
90+
ResponseFormat = Union[
91+
ResponseFormatText, ResponseFormatJSONObject, ResponseFormatJSONSchema
92+
]
93+
94+
95+
class CreateChatCompletionOpenAI(BaseModel):
96+
"""
97+
Comes from source code: https://github.com/openai/openai-python/blob/main/src/openai/types/chat/completion_create_params.py
98+
"""
99+
100+
messages: List[Dict]
101+
model: str
102+
frequency_penalty: Optional[float]
103+
logit_bias: Optional[Dict[str, int]]
104+
logprobs: Optional[bool]
105+
max_completion_tokens: Optional[int]
106+
max_tokens: Optional[int]
107+
n: Optional[int]
108+
parallel_tool_calls: Optional[bool]
109+
presence_penalty: Optional[float]
110+
response_format: Optional[ResponseFormat]
111+
seed: Optional[int]
112+
service_tier: Optional[Literal["auto", "default"]]
113+
stop: Union[Optional[str], List[str]]
114+
stream_options: Optional[OpenAIChatCompletionStreamOptionsParam] # type: ignore
115+
temperature: Optional[float]
116+
tool_choice: Optional[ # type: ignore
117+
Union[
118+
Literal["none", "auto", "required"],
119+
OpenAIChatCompletionNamedToolChoiceParam,
120+
]
121+
]
122+
tools: Optional[Iterable[OpenAIChatCompletionToolParam]] # type: ignore
123+
top_logprobs: Optional[int]
124+
top_p: Optional[float]
125+
extra_body: Optional[Body]
126+
user: Optional[str]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2022-2023 XProbe Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from .restful.async_restful_client import AsyncClient
16+
from .restful.restful_client import Client
17+
18+
# For compatibility
19+
RESTfulClient = Client
20+
AsyncRESTfulClient = AsyncClient
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Copyright 2022-2023 XProbe Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
from typing import Any, AsyncIterator, Iterator, Union
17+
18+
19+
def convert_float_to_int_or_str(model_size: float) -> Union[int, str]:
20+
"""convert float to int or string
21+
22+
if float can be presented as int, convert it to int, otherwise convert it to string
23+
"""
24+
if int(model_size) == model_size:
25+
return int(model_size)
26+
else:
27+
return str(model_size)
28+
29+
30+
def streaming_response_iterator(
31+
response_lines: Iterator[bytes],
32+
) -> Iterator[Any]:
33+
"""
34+
Create an Iterator to handle the streaming type of generation.
35+
36+
Note
37+
----------
38+
This method is for compatible with openai. Please refer to:
39+
https://github.com/openai/openai-python/blob/v0.28.1/openai/api_requestor.py#L99
40+
41+
Parameters
42+
----------
43+
response_lines: Iterator[bytes]
44+
Generated lines by the Model Generator.
45+
46+
Returns
47+
-------
48+
Iterator["CompletionChunk"]
49+
Iterator of CompletionChunks generated by models.
50+
51+
"""
52+
53+
for line in response_lines:
54+
line = line.strip()
55+
if line.startswith(b"data:"):
56+
json_str = line[len(b"data:") :].strip()
57+
if json_str == b"[DONE]":
58+
continue
59+
data = json.loads(json_str.decode("utf-8"))
60+
error = data.get("error", None)
61+
if error is not None:
62+
raise Exception(str(error))
63+
yield data
64+
65+
66+
async def async_streaming_response_iterator(
67+
response_lines: AsyncIterator[bytes],
68+
) -> AsyncIterator[Any]:
69+
"""
70+
Create an AsyncIterator to handle the streaming type of generation.
71+
72+
Note
73+
----------
74+
This method is for compatible with openai. Please refer to:
75+
https://github.com/openai/openai-python/blob/v0.28.1/openai/api_requestor.py#L99
76+
77+
Parameters
78+
----------
79+
response_lines: AsyncIterator[bytes]
80+
Generated lines by the Model Generator.
81+
82+
Returns
83+
-------
84+
AsyncIterator["CompletionChunk"]
85+
AsyncIterator of CompletionChunks generated by models.
86+
87+
"""
88+
89+
async for line in response_lines:
90+
line = line.strip()
91+
if line.startswith(b"data:"):
92+
json_str = line[len(b"data:") :].strip()
93+
if json_str == b"[DONE]":
94+
continue
95+
data = json.loads(json_str.decode("utf-8"))
96+
error = data.get("error", None)
97+
if error is not None:
98+
raise Exception(str(error))
99+
yield data
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from .restful.async_restful_client import ( # noqa: F401
2+
AsyncRESTfulAudioModelHandle as AsyncAudioModelHandle,
3+
)
4+
from .restful.async_restful_client import ( # noqa: F401
5+
AsyncRESTfulChatModelHandle as AsyncChatModelHandle,
6+
)
7+
from .restful.async_restful_client import ( # noqa: F401
8+
AsyncRESTfulEmbeddingModelHandle as AsyncEmbeddingModelHandle,
9+
)
10+
from .restful.async_restful_client import ( # noqa: F401
11+
AsyncRESTfulGenerateModelHandle as AsyncGenerateModelHandle,
12+
)
13+
from .restful.async_restful_client import ( # noqa: F401
14+
AsyncRESTfulImageModelHandle as AsyncImageModelHandle,
15+
)
16+
from .restful.async_restful_client import ( # noqa: F401
17+
AsyncRESTfulVideoModelHandle as AsyncVideoModelHandle,
18+
)
19+
from .restful.restful_client import ( # noqa: F401
20+
RESTfulAudioModelHandle as AudioModelHandle,
21+
)
22+
from .restful.restful_client import ( # noqa: F401
23+
RESTfulChatModelHandle as ChatModelHandle,
24+
)
25+
from .restful.restful_client import ( # noqa: F401
26+
RESTfulEmbeddingModelHandle as EmbeddingModelHandle,
27+
)
28+
from .restful.restful_client import ( # noqa: F401
29+
RESTfulGenerateModelHandle as GenerateModelHandle,
30+
)
31+
from .restful.restful_client import ( # noqa: F401
32+
RESTfulImageModelHandle as ImageModelHandle,
33+
)
34+
from .restful.restful_client import ( # noqa: F401
35+
RESTfulVideoModelHandle as VideoModelHandle,
36+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2022-2023 XProbe Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

0 commit comments

Comments
 (0)