diff --git a/src/plugins/schedule/schedule_llm_module.py b/src/plugins/schedule/schedule_llm_module.py index cf88a865..1fcad52d 100644 --- a/src/plugins/schedule/schedule_llm_module.py +++ b/src/plugins/schedule/schedule_llm_module.py @@ -23,7 +23,7 @@ class LLMModel: self.model_name = model_name self.params = kwargs - async def generate_response(self, prompt: str) -> Tuple[str, str]: + def generate_response(self, prompt: str) -> Tuple[str, str]: """根据输入的提示生成模型的响应""" headers = { "Authorization": f"Bearer {self.api_key}", @@ -42,17 +42,16 @@ class LLMModel: api_url = f"{self.base_url.rstrip('/')}/chat/completions" try: - async with aiohttp.ClientSession() as session: - async with session.post(api_url, headers=headers, json=data) as response: - response.raise_for_status() # 检查响应状态 - - result = await response.json() - if "choices" in result and len(result["choices"]) > 0: - content = result["choices"][0]["message"]["content"] - reasoning_content = result["choices"][0]["message"].get("reasoning_content", "") - return content, reasoning_content # 返回内容和推理内容 - return "没有返回结果", "" # 返回两个值 - + response = requests.post(api_url, headers=headers, json=data) + response.raise_for_status() # 检查响应状态 + + result = response.json() + if "choices" in result and len(result["choices"]) > 0: + content = result["choices"][0]["message"]["content"] + reasoning_content = result["choices"][0]["message"].get("reasoning_content", "") + return content, reasoning_content # 返回内容和推理内容 + return "没有返回结果", "" # 返回两个值 + except Exception as e: return f"请求失败: {str(e)}", "" # 返回错误信息和空字符串