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