LLM输出的内容先通过正则清理多余内容

This commit is contained in:
2025-08-28 14:29:19 +08:00
parent 660b5f6561
commit abc868225a
5 changed files with 95 additions and 119 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ class APIKeyManager:
# 密钥使用计数和上次使用时间
_key_usage: Dict[str, Dict] = {}
# 当前正在使用的密钥索引
_current_index = 0
_current_index = -1
api_file_path = "api_key.txt"
+2 -2
View File
@@ -200,7 +200,7 @@ class OpenAiLLM:
except Exception as e:
retry_count += 1
if retry_count == max_retries:
raise RuntimeError(f"OpenAiLLM:invoke:error:{str(e)}.api_key:{api_key}") from e
raise RuntimeError(f"OpenAiLLM:invoke:error:{str(e)}") from e
else:
time.sleep(5*retry_count) # 重试前等待5秒*重试次数
else:
@@ -215,7 +215,7 @@ class OpenAiLLM:
)
return completion.choices[0].message
except Exception as e:
raise RuntimeError(f"OpenAiLLM:invoke:error:{str(e)}.api_key:{api_key}") from e
raise RuntimeError(f"OpenAiLLM:invoke:error:{str(e)}") from e
async def ainvoke(self, user_prompt="你是谁?", **extra_kwargs):
"""异步调用OpenAI API"""