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

Grok x.ai support #261

Open
jbvsmo opened this issue Dec 14, 2024 · 2 comments
Open

Grok x.ai support #261

jbvsmo opened this issue Dec 14, 2024 · 2 comments

Comments

@jbvsmo
Copy link

jbvsmo commented Dec 14, 2024

Hi, are there plans to support models from x.ai?
This new grok-2-1212 release from this week make it very appealing and also I would like to put their free API credits to good use.

I see there is an option to write my own model subclass, but just checking first if someone going to do it.

One last question, what is the policy here for adding more APIs?

@samuelcolvin
Copy link
Member

Thanks the policy is here https://ai.pydantic.dev/contributing/#new-model-rules

@jbvsmo
Copy link
Author

jbvsmo commented Dec 16, 2024

@samuelcolvin Thank you for your reply.

According to this, https://docs.x.ai/api/integrations#openai-sdk
The x.ai integration works on either openai or anthropic sdks which would qualify it for inclusion in the docs only right?

For any other model that's just a custom URL and API key, we're happy to add a one-paragraph description
with a link and instructions on the URL to use

I got it working for a basic query with this:

model = OpenAIModel(
    'grok-2-1212',
    openai_client=AsyncOpenAI(base_url='https://api.x.ai/v1', api_key=os.environ['XAI_API_KEY']),
)
agent = Agent(model)
result = agent.run_sync('which model are you?')
print(result)

Although when passing result_type=SomeThing to the agent it will consistently fail the result validation with the following:

pydantic_ai.exceptions.UnexpectedModelBehavior: Exceeded maximum retries (1) for result validation

Maybe something else is missing?

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

No branches or pull requests

2 participants