Release Notes - v0.2.3
Release Notes - v0.2.3
π New Feature: Structured Output
What's New
Conversation now supports structured outputs via the returns parameter. Get validated, type-safe data directly from LLM responses using Pydantic models.
Usage
from pydantic import BaseModel, Field
import chak
class User(BaseModel):
name: str = Field(description="User's full name")
email: str = Field(description="User's email address")
age: int = Field(description="User's age")
conv = chak.Conversation("openai/gpt-4o", api_key="YOUR_KEY")
# Get structured output automatically
user = await conv.asend(
"Create a user: John Doe, john@example.com, 30 years old",
returns=User
)
print(user.name) # "John Doe"
print(user.email) # "john@example.com"
print(user.age) # 30Key Features
- Type-Safe: Automatic validation using Pydantic models
- Multimodal Support: Works with images, documents, and other attachments
- Seamless Integration: No manual parsing, just specify the model
- Provider Compatible: Works with any LLM that supports function calling
Multimodal Example
from chak import Image
class SceneDescription(BaseModel):
main_subject: str
colors: list[str]
mood: str
# Extract structured data from images
scene = await conv.asend(
"Analyze this image and describe the scene",
attachments=[Image("photo.jpg")],
returns=SceneDescription
)Examples
- Basic Structured Output:
examples/structured_output_simple.py - Multimodal Structured Output:
examples/structured_output_multimodal.py
Technical Details
- API: New
returnsparameter inasend()method - Implementation: Uses function calling under the hood
- Validation: Automatic Pydantic validation
- Context Management: Fully integrated with conversation history
Notes
- Requires Pydantic
BaseModelsubclass - Currently async only (
asend(), notsend()) - Some vision models may not support function calling
- Best results with models like OpenAI GPT-4o, Anthropic Claude 3
Full documentation: README.md