Skip to content

Conversation

@jgieringer
Copy link
Collaborator

@jgieringer jgieringer commented Jan 15, 2026

Description

Simulated conversations continued even if an error occured due to generate_response returning an error as a string:
chatbot: Error generating response: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.2: all messages must have non-empty content except for the optional final assistant message'}, 'request_id': 'req_011CX84UXrNZGnUz2i9YM7AX'}

This PR implements a retry function for specific errors, like rate limit responses (429) and the like, and only breaks the app if max retries is reached.

Issue

Resolves SAF-163

@jgieringer jgieringer changed the base branch from main to jgieringer/llm-return-str January 15, 2026 00:19
Copy link
Collaborator

@emily-vanark emily-vanark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments... Mostly I'm wondering if / how the retry logic can be tested.

@jgieringer
Copy link
Collaborator Author

@emily-vanark thanks for your review! Yes tests were missing. They're added at test_llm_interface.py 🚀

Base automatically changed from jgieringer/llm-return-str to main January 16, 2026 18:15

def __init__(self, name: str, system_prompt: Optional[str] = None):
def __init__(
self, name: str, system_prompt: Optional[str] = None, max_retries: int = 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until now I have tried to avoid (not always successfully) putting defaults outside of the main entry point, as it might introduce subtle bugs.

while it makes the script code a little longer, i wonder if putting an optional arg there and passing it down makes it more coherent with the existing codebase?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course, this opens a new question: all the functions are getting bloated, and maybe an config file/arg is now needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!
yeah, I don't like the bloat! I noticed langchain also supports max_retries, but that's only for langchain-supported endpoints.
I'll revisit this after tending to the other bloat which are the other open PRs 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants