mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
perf: 为图片base64函数添加lru
This commit is contained in:
parent
37ef1c9fab
commit
91e23b8c11
|
@ -14,6 +14,7 @@ required_deps = {
|
|||
"yaml": "pyyaml",
|
||||
"aiohttp": "aiohttp",
|
||||
"psutil": "psutil",
|
||||
"async_lru": "async-lru",
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@ class ToolCall(pydantic.BaseModel):
|
|||
class ImageURLContentObject(pydantic.BaseModel):
|
||||
url: str
|
||||
|
||||
def __str__(self):
|
||||
return self.url[:128] + ('...' if len(self.url) > 128 else '')
|
||||
|
||||
|
||||
class ContentElement(pydantic.BaseModel):
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import openai
|
|||
import openai.types.chat.chat_completion as chat_completion
|
||||
import httpx
|
||||
import aiohttp
|
||||
import async_lru
|
||||
|
||||
from .. import api, entities, errors
|
||||
from ....core import entities as core_entities, app
|
||||
|
@ -46,7 +47,6 @@ class OpenAIChatCompletions(api.LLMAPIRequester):
|
|||
self,
|
||||
args: dict,
|
||||
) -> chat_completion.ChatCompletion:
|
||||
self.ap.logger.debug(f"req chat_completion with args {args}")
|
||||
return await self.client.chat.completions.create(**args)
|
||||
|
||||
async def _make_msg(
|
||||
|
@ -124,6 +124,7 @@ class OpenAIChatCompletions(api.LLMAPIRequester):
|
|||
except openai.APIError as e:
|
||||
raise errors.RequesterError(f'请求错误: {e.message}')
|
||||
|
||||
@async_lru.alru_cache(maxsize=128)
|
||||
async def get_base64_str(
|
||||
self,
|
||||
original_url: str,
|
||||
|
|
|
@ -14,3 +14,4 @@ pydantic
|
|||
websockets
|
||||
urllib3
|
||||
psutil
|
||||
async-lru
|
Loading…
Reference in New Issue
Block a user