This commit is contained in:
minecraft1024a
2025-09-26 22:08:57 +08:00
2 changed files with 4 additions and 4 deletions

View File

@@ -145,7 +145,7 @@ class LLMUsageRecorder:
LLM使用情况记录器SQLAlchemy版本 LLM使用情况记录器SQLAlchemy版本
""" """
def record_usage_to_database( async def record_usage_to_database(
self, self,
model_info: ModelInfo, model_info: ModelInfo,
model_usage: UsageRecord, model_usage: UsageRecord,

View File

@@ -891,7 +891,7 @@ class LLMRequest:
max_tokens=self.model_for_task.max_tokens if max_tokens is None else max_tokens, max_tokens=self.model_for_task.max_tokens if max_tokens is None else max_tokens,
) )
self._record_usage(model_info, response.usage, time.time() - start_time, "/chat/completions") await self._record_usage(model_info, response.usage, time.time() - start_time, "/chat/completions")
if not response.content and not response.tool_calls: if not response.content and not response.tool_calls:
if raise_when_empty: if raise_when_empty:
@@ -916,14 +916,14 @@ class LLMRequest:
embedding_input=embedding_input embedding_input=embedding_input
) )
self._record_usage(model_info, response.usage, time.time() - start_time, "/embeddings") await self._record_usage(model_info, response.usage, time.time() - start_time, "/embeddings")
if not response.embedding: if not response.embedding:
raise RuntimeError("获取embedding失败") raise RuntimeError("获取embedding失败")
return response.embedding, model_info.name return response.embedding, model_info.name
def _record_usage(self, model_info: ModelInfo, usage: Optional[UsageRecord], time_cost: float, endpoint: str): async def _record_usage(self, model_info: ModelInfo, usage: Optional[UsageRecord], time_cost: float, endpoint: str):
""" """
记录模型使用情况。 记录模型使用情况。