Fix some errors found in calc examples

This commit is contained in:
Timothyxxx
2024-01-28 21:19:18 +08:00
parent 353ab6607d
commit cc21c3a6b1
9 changed files with 186 additions and 125 deletions

View File

@@ -505,6 +505,7 @@ class GPT4v_Agent:
@backoff.on_exception(
backoff.expo,
(APIError, RateLimitError, APIConnectionError, ServiceUnavailableError, InvalidRequestError),
max_tries=3
)
def call_llm(self, payload):
response = requests.post(
@@ -514,6 +515,18 @@ class GPT4v_Agent:
)
if response.status_code != 200:
if response.json()['error']['code'] == "context_length_exceeded":
print("Context length exceeded. Retrying with a smaller context.")
payload["messages"] = payload["messages"][-1:]
retry_response = requests.post(
"https://api.openai.com/v1/chat/completions",
headers=self.headers,
json=payload
)
if retry_response.status_code != 200:
print("Failed to call LLM: " + retry_response.text)
return ""
print("Failed to call LLM: " + response.text)
return ""
else: