-
Notifications
You must be signed in to change notification settings - Fork 52
feat(ai): add error handling to python ai sdk #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| client = OpenAI(api_key="test-key", posthog_client=mock_client) | ||
| with pytest.raises(Exception): | ||
| client.chat.completions.create(model="gpt-4", messages=[{"role": "user", "content": "Hello"}]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's an HTTP error, say a 400, do we still capture the $ai_error content then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it will raise the BadRequest exception: https://github.com/openai/openai-python/blob/main/src/openai/_exceptions.py
| client = OpenAI(api_key="test-key", posthog_client=mock_client) | ||
| with pytest.raises(Exception): | ||
| client.chat.completions.create(model="gpt-4", messages=[{"role": "user", "content": "Hello"}]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it will raise the BadRequest exception: https://github.com/openai/openai-python/blob/main/src/openai/_exceptions.py
Add
$ai_errorand$ai_is_errorproperties to LangChain callback handler, OpenAI, and Anthropic.