Skip to content

Commit

Permalink
Context length is not retryable
Browse files Browse the repository at this point in the history
  • Loading branch information
mattzh72 committed Nov 27, 2024
1 parent c347e27 commit ef8983f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions letta/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,17 @@ def _get_ai_reply(
stream_interface=self.interface,
)

# This is not retryable, hence RuntimeError v.s. ValueError
if response.choices[0].finish_reason == "length":
raise RuntimeError("Finish reason was length (maximum context length)")

# These bottom two are retryable
if len(response.choices) == 0 or response.choices[0] is None:
raise ValueError(f"API call returned an empty message: {response}")

if response.choices[0].finish_reason not in ["stop", "function_call", "tool_calls"]:
raise ValueError(f"Bad finish reason from API: {response.choices[0].finish_reason}")

# This is not retryable, hence RuntimeError v.s. ValueError
if response.choices[0].finish_reason == "length":
raise RuntimeError("Finish reason was length (maximum context length)")

return response

except ValueError as ve:
Expand Down

0 comments on commit ef8983f

Please sign in to comment.