mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-02-07 07:23:29 +08:00
python3.8兼容
This commit is contained in:
parent
a6e78f219f
commit
d8352eb8e0
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import Dict, List, Optional, Type, Union, cast
|
from typing import Dict, List, Optional, Type, Union, cast
|
||||||
|
|
||||||
import cohere
|
import cohere
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import List, Optional, Union, cast
|
from typing import List, Optional, Union, cast
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
|
|
||||||
from model_providers.core.model_runtime.entities.llm_entities import (
|
from model_providers.core.model_runtime.entities.llm_entities import (
|
||||||
LLMResult,
|
LLMResult,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from model_providers.core.model_runtime.entities.llm_entities import LLMResult
|
from model_providers.core.model_runtime.entities.llm_entities import LLMResult
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import List, Optional, Union, cast
|
from typing import List, Optional, Union, cast
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import List, Optional, Union, cast
|
from typing import List, Optional, Union, cast
|
||||||
|
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional, Union, cast
|
from typing import List, Optional, Union, cast
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import threading
|
import threading
|
||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import Dict, List, Optional, Type, Union
|
from typing import Dict, List, Optional, Type, Union
|
||||||
|
|
||||||
from model_providers.core.model_runtime.entities.llm_entities import (
|
from model_providers.core.model_runtime.entities.llm_entities import (
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from model_providers.core.model_runtime.entities.llm_entities import LLMResult
|
from model_providers.core.model_runtime.entities.llm_entities import LLMResult
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from typing import Dict, List, Optional, Type, Union
|
from typing import Dict, List, Optional, Type, Union
|
||||||
|
|
||||||
from dashscope import get_tokenizer
|
from dashscope import get_tokenizer
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from collections.abc import Generator, Iterator
|
from typing import Generator, Iterator
|
||||||
|
|
||||||
from typing import Dict, List, Union, cast, Type
|
from typing import Dict, List, Union, cast, Type
|
||||||
|
|
||||||
from openai import (
|
from openai import (
|
||||||
@ -464,7 +465,7 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
|||||||
]
|
]
|
||||||
|
|
||||||
if isinstance(
|
if isinstance(
|
||||||
xinference_model, RESTfulChatModelHandle | RESTfulChatglmCppChatModelHandle
|
xinference_model, (RESTfulChatModelHandle, RESTfulChatglmCppChatModelHandle)
|
||||||
):
|
):
|
||||||
resp = client.chat.completions.create(
|
resp = client.chat.completions.create(
|
||||||
model=credentials["model_uid"],
|
model=credentials["model_uid"],
|
||||||
|
|||||||
@ -15,7 +15,7 @@ from ipaddress import (
|
|||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from re import Pattern
|
from re import Pattern
|
||||||
from types import GeneratorType
|
from types import GeneratorType
|
||||||
from typing import Any, Optional, Union
|
from typing import Any, Optional, Union, Dict, Type, List, Tuple
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
@ -54,7 +54,7 @@ def decimal_encoder(dec_value: Decimal) -> Union[int, float]:
|
|||||||
return float(dec_value)
|
return float(dec_value)
|
||||||
|
|
||||||
|
|
||||||
ENCODERS_BY_TYPE: Dict[type[Any], Callable[[Any], Any]] = {
|
ENCODERS_BY_TYPE: Dict[Type[Any], Callable[[Any], Any]] = {
|
||||||
bytes: lambda o: o.decode(),
|
bytes: lambda o: o.decode(),
|
||||||
Color: str,
|
Color: str,
|
||||||
datetime.date: isoformat,
|
datetime.date: isoformat,
|
||||||
@ -86,8 +86,8 @@ ENCODERS_BY_TYPE: Dict[type[Any], Callable[[Any], Any]] = {
|
|||||||
|
|
||||||
def generate_encoders_by_class_tuples(
|
def generate_encoders_by_class_tuples(
|
||||||
type_encoder_map: Dict[Any, Callable[[Any], Any]],
|
type_encoder_map: Dict[Any, Callable[[Any], Any]],
|
||||||
) -> Dict[Callable[[Any], Any], tuple[Any, ...]]:
|
) -> Dict[Callable[[Any], Any], Tuple[Any, ...]]:
|
||||||
encoders_by_class_tuples: Dict[Callable[[Any], Any], tuple[Any, ...]] = defaultdict(
|
encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[Any, ...]] = defaultdict(
|
||||||
tuple
|
tuple
|
||||||
)
|
)
|
||||||
for type_, encoder in type_encoder_map.items():
|
for type_, encoder in type_encoder_map.items():
|
||||||
@ -104,7 +104,7 @@ def jsonable_encoder(
|
|||||||
exclude_unset: bool = False,
|
exclude_unset: bool = False,
|
||||||
exclude_defaults: bool = False,
|
exclude_defaults: bool = False,
|
||||||
exclude_none: bool = False,
|
exclude_none: bool = False,
|
||||||
custom_encoder: Optional[dict[Any, Callable[[Any], Any]]] = None,
|
custom_encoder: Optional[Dict[Any, Callable[[Any], Any]]] = None,
|
||||||
sqlalchemy_safe: bool = True,
|
sqlalchemy_safe: bool = True,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
custom_encoder = custom_encoder or {}
|
custom_encoder = custom_encoder or {}
|
||||||
@ -192,7 +192,7 @@ def jsonable_encoder(
|
|||||||
)
|
)
|
||||||
encoded_dict[encoded_key] = encoded_value
|
encoded_dict[encoded_key] = encoded_value
|
||||||
return encoded_dict
|
return encoded_dict
|
||||||
if isinstance(obj, list | set | frozenset | GeneratorType | tuple | deque):
|
if isinstance(obj, (list, set, frozenset, GeneratorType, tuple, deque)):
|
||||||
encoded_list = []
|
encoded_list = []
|
||||||
for item in obj:
|
for item in obj:
|
||||||
encoded_list.append(
|
encoded_list.append(
|
||||||
@ -217,8 +217,7 @@ def jsonable_encoder(
|
|||||||
try:
|
try:
|
||||||
data = dict(obj)
|
data = dict(obj)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errors: List[Exception] = []
|
errors: List[Exception] = [e]
|
||||||
errors.append(e)
|
|
||||||
try:
|
try:
|
||||||
data = vars(obj)
|
data = vars(obj)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from collections.abc import Generator
|
from typing import Generator
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user