jupyter-ai
jupyter-ai copied to clipboard
When CohereAPIError happens, error is not propagated to Jupyter AI, langchain is stuck in the loop
trafficstars
Description
When CohereAPIError happens, error is not propagated to Jupyter AI, langchain is stuck in the loop
Reproduce
- Choose Cohere model, use bad API key
- Attempt to send a chat message
- Note that there is no response from Jupyternaut, note terminal error messages and server getting stuck in a loop
Current conversation:
Human: test
AI:
Retrying langchain.llms.cohere.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised CohereAPIError: invalid api token.
Retrying langchain.llms.cohere.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised CohereAPIError: invalid api token.
Retrying langchain.llms.cohere.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised CohereAPIError: invalid api token.
Expected behavior
Usual behavior: error is propagated to Jupyter AI, caught by ChatHandler, Jupyternaut sends error stack trace to user.
Tried implementing a workaround without success:
- handling exception via
try-except cohere.CohereAPIErrorblock toCohereProvider._acall() - handling exception via
try-except cohere.CohereAPIErrorinBaseProvider._generate_in_executor()andBaseProvider._call_in_executor()
This is still an issue after recent revisions to the Cohere models in #584 and #594.