LLM输出的内容先通过正则清理多余内容
This commit is contained in:
@@ -30,7 +30,7 @@ class APIKeyManager:
|
||||
# 密钥使用计数和上次使用时间
|
||||
_key_usage: Dict[str, Dict] = {}
|
||||
# 当前正在使用的密钥索引
|
||||
_current_index = 0
|
||||
_current_index = -1
|
||||
|
||||
api_file_path = "api_key.txt"
|
||||
|
||||
|
||||
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user