Update agent.py claude

This commit is contained in:
Fangyu Lei
2024-03-21 07:52:58 +08:00
committed by GitHub
parent 04a9df627c
commit 3e581c8108

View File

@@ -555,13 +555,20 @@ class PromptAgent:
# "content-type": "application/json"
# }
# headers = {
# "Accept": "application / json",
# "Authorization": "Bearer " + os.environ["ANTHROPIC_API_KEY"],
# "User-Agent": "Apifox/1.0.0 (https://apifox.com)",
# "Content-Type": "application/json"
# }
headers = {
"Accept": "application / json",
"Authorization": "Bearer " + os.environ["ANTHROPIC_API_KEY"],
"User-Agent": "Apifox/1.0.0 (https://apifox.com)",
"Authorization": os.environ["ANTHROPIC_API_KEY"],
"Content-Type": "application/json"
}
payload = {
"model": self.model,
"max_tokens": max_tokens,
@@ -570,22 +577,23 @@ class PromptAgent:
"top_p": top_p
}
response = requests.post(
# "https://chat.claude.com/v1/chat/completions",
"https://api.aigcbest.top/v1/chat/completions",
headers=headers,
json=payload
)
if response.status_code != 200:
logger.error("Failed to call LLM: " + response.text)
time.sleep(5)
return ""
# else:
# return response.json()['content'][0]['text']
max_attempts = 20
attempt = 0
while attempt < max_attempts:
# response = requests.post("https://api.aigcbest.top/v1/chat/completions", headers=headers, json=payload)
response = requests.post("https://token.cluade-chat.top/v1/chat/completions", headers=headers, json=payload)
if response.status_code == 200:
result = response.json()['choices'][0]['message']['content']
break
else:
logger.error(f"Failed to call LLM: {response.text}")
time.sleep(10)
attempt += 1
else:
return response.json()['choices'][0]['message']['content']
print("Exceeded maximum attempts to call LLM.")
result = ""
return result
elif self.model.startswith("mistral"):