commit
295783b549
|
|
@ -14,7 +14,6 @@ from langchain.chat_models import ChatOpenAI
|
||||||
import httpx
|
import httpx
|
||||||
from typing import Literal, Optional, Callable, Generator, Dict, Any, Awaitable, Union
|
from typing import Literal, Optional, Callable, Generator, Dict, Any, Awaitable, Union
|
||||||
|
|
||||||
|
|
||||||
thread_pool = ThreadPoolExecutor(os.cpu_count())
|
thread_pool = ThreadPoolExecutor(os.cpu_count())
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -68,6 +67,7 @@ class BaseResponse(BaseModel):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ListResponse(BaseResponse):
|
class ListResponse(BaseResponse):
|
||||||
data: List[str] = pydantic.Field(..., description="List of names")
|
data: List[str] = pydantic.Field(..., description="List of names")
|
||||||
|
|
||||||
|
|
@ -115,6 +115,7 @@ class ChatMessage(BaseModel):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def torch_gc():
|
def torch_gc():
|
||||||
import torch
|
import torch
|
||||||
if torch.cuda.is_available():
|
if torch.cuda.is_available():
|
||||||
|
|
@ -131,6 +132,7 @@ def torch_gc():
|
||||||
logger.error(f'{e.__class__.__name__}: {msg}',
|
logger.error(f'{e.__class__.__name__}: {msg}',
|
||||||
exc_info=e if log_verbose else None)
|
exc_info=e if log_verbose else None)
|
||||||
|
|
||||||
|
|
||||||
def run_async(cor):
|
def run_async(cor):
|
||||||
'''
|
'''
|
||||||
在同步环境中运行异步代码.
|
在同步环境中运行异步代码.
|
||||||
|
|
@ -147,12 +149,14 @@ def iter_over_async(ait, loop):
|
||||||
将异步生成器封装成同步生成器.
|
将异步生成器封装成同步生成器.
|
||||||
'''
|
'''
|
||||||
ait = ait.__aiter__()
|
ait = ait.__aiter__()
|
||||||
|
|
||||||
async def get_next():
|
async def get_next():
|
||||||
try:
|
try:
|
||||||
obj = await ait.__anext__()
|
obj = await ait.__anext__()
|
||||||
return False, obj
|
return False, obj
|
||||||
except StopAsyncIteration:
|
except StopAsyncIteration:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
done, obj = loop.run_until_complete(get_next())
|
done, obj = loop.run_until_complete(get_next())
|
||||||
if done:
|
if done:
|
||||||
|
|
@ -245,6 +249,7 @@ def list_embed_models() -> List[str]:
|
||||||
'''
|
'''
|
||||||
return list(MODEL_PATH["embed_model"])
|
return list(MODEL_PATH["embed_model"])
|
||||||
|
|
||||||
|
|
||||||
def list_llm_models() -> Dict[str, List[str]]:
|
def list_llm_models() -> Dict[str, List[str]]:
|
||||||
'''
|
'''
|
||||||
get names of configured llm models with different types.
|
get names of configured llm models with different types.
|
||||||
|
|
@ -508,9 +513,15 @@ def get_httpx_client(
|
||||||
# get proxies from system envionrent
|
# get proxies from system envionrent
|
||||||
# proxy not str empty string, None, False, 0, [] or {}
|
# proxy not str empty string, None, False, 0, [] or {}
|
||||||
default_proxies.update({
|
default_proxies.update({
|
||||||
"http://": os.environ.get("http_proxy") if len(os.environ.get("http_proxy").strip()) > 0 else None,
|
"http://": (os.environ.get("http_proxy")
|
||||||
"https://": os.environ.get("https_proxy") if len(os.environ.get("https_proxy").strip()) > 0 else None,
|
if os.environ.get("http_proxy") and len(os.environ.get("http_proxy").strip())
|
||||||
"all://": os.environ.get("all_proxy") if len(os.environ.get("all_proxy").strip()) > 0 else None,
|
else None),
|
||||||
|
"https://": (os.environ.get("https_proxy")
|
||||||
|
if os.environ.get("https_proxy") and len(os.environ.get("https_proxy").strip())
|
||||||
|
else None),
|
||||||
|
"all://": (os.environ.get("all_proxy")
|
||||||
|
if os.environ.get("all_proxy") and len(os.environ.get("all_proxy").strip())
|
||||||
|
else None),
|
||||||
})
|
})
|
||||||
for host in os.environ.get("no_proxy", "").split(","):
|
for host in os.environ.get("no_proxy", "").split(","):
|
||||||
if host := host.strip():
|
if host := host.strip():
|
||||||
|
|
@ -530,4 +541,3 @@ def get_httpx_client(
|
||||||
return httpx.AsyncClient(**kwargs)
|
return httpx.AsyncClient(**kwargs)
|
||||||
else:
|
else:
|
||||||
return httpx.Client(**kwargs)
|
return httpx.Client(**kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue