Update agent.py claude
This commit is contained in:
@@ -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
|
||||||
|
else:
|
||||||
logger.error("Failed to call LLM: " + response.text)
|
logger.error(f"Failed to call LLM: {response.text}")
|
||||||
time.sleep(5)
|
time.sleep(10)
|
||||||
return ""
|
attempt += 1
|
||||||
# else:
|
|
||||||
# return response.json()['content'][0]['text']
|
|
||||||
else:
|
else:
|
||||||
return response.json()['choices'][0]['message']['content']
|
print("Exceeded maximum attempts to call LLM.")
|
||||||
|
result = ""
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
elif self.model.startswith("mistral"):
|
elif self.model.startswith("mistral"):
|
||||||
|
|||||||
Reference in New Issue
Block a user