97e91a83f3
Ruff / Ruff (push) Waiting to run
Test / Core Tests (push) Waiting to run
Test / Offline Coverage Tests (Python 3.10) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.11) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.12) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.13) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.9) (push) Waiting to run
Test / Full Coverage (Python 3.11) (push) Waiting to run
Test / Core Provider Tests (OpenAI) (push) Blocked by required conditions
Test / Core Provider Tests (Anthropic) (push) Blocked by required conditions
Test / Core Provider Tests (Google) (push) Blocked by required conditions
Test / Core Provider Tests (Other) (push) Blocked by required conditions
Test / Anthropic Tests (push) Blocked by required conditions
Test / Gemini Tests (push) Blocked by required conditions
Test / Google GenAI Tests (push) Blocked by required conditions
Test / Vertex AI Tests (push) Blocked by required conditions
Test / OpenAI Tests (push) Blocked by required conditions
Test / Writer Tests (push) Blocked by required conditions
Test / Auto Client Tests (push) Blocked by required conditions
ty / type-check (push) Waiting to run
36 lines
908 B
Python
36 lines
908 B
Python
import os
|
|
import openai
|
|
from pydantic import BaseModel
|
|
import instructor
|
|
|
|
client = openai.OpenAI(
|
|
base_url="https://api.together.xyz/v1",
|
|
api_key=os.environ["TOGETHER_API_KEY"],
|
|
)
|
|
|
|
|
|
# By default, the patch function will patch the ChatCompletion.create and ChatCompletion.acreate methods. to support response_model parameter
|
|
client = instructor.from_openai(client, mode=instructor.Mode.TOOLS)
|
|
|
|
|
|
# Now, we can use the response_model parameter using only a base model
|
|
# rather than having to use the ResponseSchema class
|
|
class UserExtract(BaseModel):
|
|
name: str
|
|
age: int
|
|
|
|
|
|
user: UserExtract = client.chat.completions.create(
|
|
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
response_model=UserExtract,
|
|
messages=[
|
|
{"role": "user", "content": "Extract jason is 25 years old"},
|
|
],
|
|
) # type: ignore
|
|
|
|
print(user.model_dump_json(indent=2))
|
|
{
|
|
"name": "Jason",
|
|
"age": 25,
|
|
}
|