Skip to content
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

Anthropic Parsing Lists of non-objects #515

Open
2 of 8 tasks
Cruppelt opened this issue Mar 20, 2024 · 8 comments
Open
2 of 8 tasks

Anthropic Parsing Lists of non-objects #515

Cruppelt opened this issue Mar 20, 2024 · 8 comments

Comments

@Cruppelt
Copy link
Contributor

  • This is an actually a bug report.
  • I am not getting good LLM Results
  • I have tried asking for help in the community on discord or discussions and have not received a response.
  • I have tried searching the documentation and have not found an answer.

What Model are you using?

  • gpt-3.5-turbo
  • gpt-4-turbo
  • gpt-4
  • Other - claude-3-opus-20240229 (Model does not affect this bug)

Describe the bug
Code hard fails on trying to get the $ref key.

/instructor/anthropic_utils.py", line 88, in _add_params
_resolve_reference(references, details["items"]["$ref"]),
~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: '$ref'

To Reproduce

from typing import List

import anthropic
import instructor
from pydantic import BaseModel


class CountedNumbers(BaseModel):
    numbers: List[int]


def main():
    anthropic_client = instructor.patch(
        create=anthropic.Anthropic().messages.create, mode=instructor.Mode.ANTHROPIC_TOOLS
    )

    user_response = anthropic_client(
        model="claude-3-opus-20240229",
        max_tokens=1024,
        max_retries=0,
        system="Count all the numbers up to the given number.",
        messages=[
            {
                "role": "user",
                "content": "3",
            }
        ],
        response_model=CountedNumbers,
    )  # type: ignore

    print(user_response.model_dump_json(indent=2))


if __name__ == "__main__":
    main()

Expected behavior
I'd expect to get a pydantic model with model_dump_json like

{
  "numbers": [
    1,
    2,
    3
  ]
}
@jxnl jxnl added the anthropic label Mar 21, 2024
@Cruppelt
Copy link
Contributor Author

@jxnl I have a local fix for this, looks like some permission issue to push for a PR?

@shreya-51
Copy link
Contributor

hey! check this out: #521

@Cruppelt
Copy link
Contributor Author

hey! check this out: #521

Awesome, appreciate it! Am I able to get access to push? few prompt clean up things I'd like to PR

@jxnl
Copy link
Owner

jxnl commented Mar 21, 2024

I'll get this in and you can fork and make a PR

@akarshghale
Copy link

Hi guys,

Facing this issue, is there any fix implemented other than the Opus suggestion?

@jxnl
Copy link
Owner

jxnl commented Mar 29, 2024

@akarshghale can you update and then try mode=Mode.ANTHROPIC_JSON

@akarshghale
Copy link

@akarshghale can you update and then try mode=Mode.ANTHROPIC_JSON

Yep it is working now!

@jxnl
Copy link
Owner

jxnl commented Mar 30, 2024

great we'll have better support in the future, we'll set it to default in v1.0

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

No branches or pull requests

4 participants