mirror of https://github.com/Mai-with-u/MaiBot.git
修复了日程异步bug
parent
b98314da4f
commit
304562d93a
|
|
@ -23,7 +23,7 @@ class LLMModel:
|
||||||
self.model_name = model_name
|
self.model_name = model_name
|
||||||
self.params = kwargs
|
self.params = kwargs
|
||||||
|
|
||||||
async def generate_response(self, prompt: str) -> Tuple[str, str]:
|
def generate_response(self, prompt: str) -> Tuple[str, str]:
|
||||||
"""根据输入的提示生成模型的响应"""
|
"""根据输入的提示生成模型的响应"""
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {self.api_key}",
|
"Authorization": f"Bearer {self.api_key}",
|
||||||
|
|
@ -42,17 +42,16 @@ class LLMModel:
|
||||||
api_url = f"{self.base_url.rstrip('/')}/chat/completions"
|
api_url = f"{self.base_url.rstrip('/')}/chat/completions"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
response = requests.post(api_url, headers=headers, json=data)
|
||||||
async with session.post(api_url, headers=headers, json=data) as response:
|
response.raise_for_status() # 检查响应状态
|
||||||
response.raise_for_status() # 检查响应状态
|
|
||||||
|
result = response.json()
|
||||||
result = await response.json()
|
if "choices" in result and len(result["choices"]) > 0:
|
||||||
if "choices" in result and len(result["choices"]) > 0:
|
content = result["choices"][0]["message"]["content"]
|
||||||
content = result["choices"][0]["message"]["content"]
|
reasoning_content = result["choices"][0]["message"].get("reasoning_content", "")
|
||||||
reasoning_content = result["choices"][0]["message"].get("reasoning_content", "")
|
return content, reasoning_content # 返回内容和推理内容
|
||||||
return content, reasoning_content # 返回内容和推理内容
|
return "没有返回结果", "" # 返回两个值
|
||||||
return "没有返回结果", "" # 返回两个值
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"请求失败: {str(e)}", "" # 返回错误信息和空字符串
|
return f"请求失败: {str(e)}", "" # 返回错误信息和空字符串
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue