This commit is contained in:
zchengrong@yeah.net
2025-10-24 05:19:08 +00:00
parent dc02022da3
commit 62dec64a0a
6 changed files with 21 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import asyncio
import json
import logging
import os
import uuid
from typing import List, Dict
@@ -33,7 +34,7 @@ class LCAgent(ls.LitAPI):
key_prefix=settings.REDIS_HISTORY_KEY_PREFIX
)
self.vector_db = VectorDatabase(
vector_db_dir=settings.VECTOR_DB_DIR,
vector_db_dir=os.getenv('VECTOR_DB_DIR', '/app/app/db'),
collection_name=settings.COLLECTION_NAME,
embedding_model_name=settings.EMBEDDING_MODEL_NAME
)
@@ -44,6 +45,16 @@ class LCAgent(ls.LitAPI):
}
async def decode_request(self, request: AgentRequestModel):
"""
[自动生成文档]
该方法将 HTTP 请求体解码为模型所需的输入格式。
Args:
request: 包含 prompt, history, temperature 的 ChatBotRequest 对象。
Returns:
prompt, history, temperature
"""
logger.info(f"request: {request.model_dump()}")
return request
@@ -81,10 +92,12 @@ class LCAgent(ls.LitAPI):
history_messages = self.redis.get_history(user_id)
input_message = "\n".join([f"{msg.role.value}: {msg.content}" for msg in history_messages])
# 临时调用 LLM 或使用本地逻辑生成总结
summary = await self.llm.generate_response(history=[Message(role=Role.USER, content=input_message)], system_prompt=SUMMARY_PROMPT)
summary = await self.llm.generate_response(history=[Message(role=Role.USER, content=input_message)],
system_prompt=SUMMARY_PROMPT)
return summary
async def recommend_outfit(self, request_summary: str, stylist_name: str, start_outfit=None, num_outfits: int = 1, user_id: str = "test"):
async def recommend_outfit(self, request_summary: str, stylist_name: str, start_outfit=None, num_outfits: int = 1,
user_id: str = "test"):
"""
基于用户的对话历史和需求,推荐一套搭配。