diff --git a/pkg/core/bootutils/deps.py b/pkg/core/bootutils/deps.py index 4adf132..da0ae07 100644 --- a/pkg/core/bootutils/deps.py +++ b/pkg/core/bootutils/deps.py @@ -14,6 +14,7 @@ required_deps = { "yaml": "pyyaml", "aiohttp": "aiohttp", "psutil": "psutil", + "async_lru": "async-lru", } diff --git a/pkg/provider/entities.py b/pkg/provider/entities.py index b892b89..3b87f5c 100644 --- a/pkg/provider/entities.py +++ b/pkg/provider/entities.py @@ -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): diff --git a/pkg/provider/modelmgr/apis/chatcmpl.py b/pkg/provider/modelmgr/apis/chatcmpl.py index 709a65a..028b208 100644 --- a/pkg/provider/modelmgr/apis/chatcmpl.py +++ b/pkg/provider/modelmgr/apis/chatcmpl.py @@ -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, diff --git a/requirements.txt b/requirements.txt index e43f9f0..44bc285 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ pydantic websockets urllib3 psutil +async-lru \ No newline at end of file