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