-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Handling Anthropic JSON Re-Asks #559
Comments
Hey @mdsavarese, great to see you back! Hope you're doing well. Thank you for providing the detailed information. It seems like the issue arises due to the difference in the structure of the response object in To resolve this issue, we can add a conditional check for def reask_messages(response: ChatCompletion, mode: Mode, exception: Exception):
if mode == Mode.ANTHROPIC_TOOLS:
yield {
"role": "user",
"content": f"Validation Error found:\n{exception}\nRecall the function correctly, fix the errors",
}
return
if mode == Mode.ANTHROPIC_JSON:
# Handle the response for ANTHROPIC_JSON mode
# Adjust the way to access the message content based on the actual structure of Anthropic Message objects
yield {
"role": "user",
"content": f"Anthropic JSON response handling:\n{exception}",
}
return
yield dump_message(response.choices[0].message) In this modification, a new conditional branch for Regarding the structure of an Anthropic Message object, the instructor codebase does not provide a direct definition. However, the code provides functionality for converting Pydantic models to XML format and vice versa, which gives insights into the expected structure of an Anthropic Message when working with XML and models. The structure includes a description of a tool or function, along with detailed parameters that can include types, descriptions, nested parameters, and enums. The structure is flexible and designed to support complex parameter definitions. Unfortunately, I couldn't find the exact structure of an Anthropic Message object in the I hope this helps! If you have any further questions or need more clarification, feel free to ask. Sources
|
See #560 |
What Model are you using?
claude-3-haiku-20240307
Describe the bug
The control flow within the "reask_messages" function in the retry.py module fails when running Mode.ANTHROPIC_JSON.
The function attempts to extract the message from the response object by calling response.choices[0].message; this only works with OpenAI completions, since the Anthropic Message object has no choices attribute.
The bug does not show up in Mode.ANTHROPIC_TOOLS, as the problematic "yield dump_message(response.choices[0].message" line comes after handling the ANTRHROPIC_TOOLS case.
Relevant code below:
To Reproduce
Code to reproduce:
Error from reproduction:
Expected behavior
Code should handle ANTHROPIC_JSON case explicitly. Ideally, we would also avoid calling response.choices[0].message anywhere in the library, and instead have a parser function that can flexibly handle both Anthropic and OpenAI-format responses.
The text was updated successfully, but these errors were encountered: