97e91a83f3
Ruff / Ruff (push) Has been cancelled
Test / Core Tests (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.10) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.11) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.12) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.13) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.9) (push) Has been cancelled
Test / Full Coverage (Python 3.11) (push) Has been cancelled
Test / Core Provider Tests (OpenAI) (push) Has been cancelled
Test / Core Provider Tests (Anthropic) (push) Has been cancelled
Test / Core Provider Tests (Google) (push) Has been cancelled
Test / Core Provider Tests (Other) (push) Has been cancelled
Test / Anthropic Tests (push) Has been cancelled
Test / Gemini Tests (push) Has been cancelled
Test / Google GenAI Tests (push) Has been cancelled
Test / Vertex AI Tests (push) Has been cancelled
Test / OpenAI Tests (push) Has been cancelled
Test / Writer Tests (push) Has been cancelled
Test / Auto Client Tests (push) Has been cancelled
ty / type-check (push) Has been cancelled
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import os
|
|
from pydantic import BaseModel, Field
|
|
from groq import Groq
|
|
import instructor
|
|
|
|
|
|
class Character(BaseModel):
|
|
name: str
|
|
fact: list[str] = Field(..., description="A list of facts about the subject")
|
|
|
|
|
|
client = Groq(
|
|
api_key=os.environ.get("GROQ_API_KEY"),
|
|
)
|
|
|
|
client = instructor.from_groq(client, mode=instructor.Mode.TOOLS)
|
|
|
|
resp = client.chat.completions.create(
|
|
model="mixtral-8x7b-32768",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": "Tell me about the company Tesla",
|
|
}
|
|
],
|
|
response_model=Character,
|
|
)
|
|
print(resp.model_dump_json(indent=2))
|
|
"""
|
|
{
|
|
"name": "Tesla",
|
|
"fact": [
|
|
"An American electric vehicle and clean energy company.",
|
|
"Co-founded by Elon Musk, JB Straubel, Martin Eberhard, Marc Tarpenning, and Ian Wright in 2003.",
|
|
"Headquartered in Austin, Texas.",
|
|
"Produces electric vehicles, energy storage solutions, and more recently, solar energy products.",
|
|
"Known for its premium electric vehicles, such as the Model S, Model 3, Model X, and Model Y.",
|
|
"One of the world's most valuable car manufacturers by market capitalization.",
|
|
"Tesla's CEO, Elon Musk, is also the CEO of SpaceX, Neuralink, and The Boring Company.",
|
|
"Tesla operates the world's largest global network of electric vehicle supercharging stations.",
|
|
"The company aims to accelerate the world's transition to sustainable transport and energy through innovative technologies and products."
|
|
]
|
|
}
|
|
"""
|