stock-ai-agent/backend/app/services/llm_service.py
2026-02-03 21:16:36 +08:00

49 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
LLM服务 - 兼容层,使用多模型服务
"""
from typing import Optional, List, Dict, Any
from app.services.multi_llm_service import multi_llm_service
from app.utils.logger import logger
class LLMService:
"""LLM服务类兼容层"""
def __init__(self):
"""初始化LLM服务"""
self.multi_service = multi_llm_service
self.client = multi_llm_service.current_model # 兼容性
def chat(
self,
messages: List[Dict[str, str]],
model: str = None,
temperature: float = 0.7,
max_tokens: int = 2000
) -> Optional[str]:
"""
调用LLM进行对话
Args:
messages: 消息列表
model: 模型名称(忽略,使用当前选择的模型)
temperature: 温度参数
max_tokens: 最大token数
Returns:
LLM响应文本
"""
return self.multi_service.chat(
messages=messages,
temperature=temperature,
max_tokens=max_tokens
)
def analyze_intent(self, user_message: str) -> Dict[str, Any]:
"""使用LLM分析用户意图"""
return self.multi_service.analyze_intent(user_message)
# 创建全局实例
llm_service = LLMService()