Skip to main content

Overview

Direct is a simplified interface for LLM interactions without the overhead of agents. It provides fast, direct communication with language models for scenarios where you don’t need memory management or tool orchestration.

Key Features

  • High Performance: Eliminates agent overhead for maximum speed
  • Structured Outputs: Built-in support for Pydantic models
  • Document Processing: Native support for PDFs and images
  • Fluent Interface: Easy configuration switching
  • Async Support: Full async/await support
  • Simple API: Minimal configuration required

Example

from upsonic import Direct, Task
from pydantic import BaseModel

# Create Direct instance
direct = Direct(model="openai/gpt-4o")

# Define structured output
class Response(BaseModel):
    answer: str
    confidence: float

# Create and execute task
task = Task(
    description="What is 2 + 2? Provide confidence.",
    response_format=Response
)

result = direct.do(task)
print(f"Answer: {result.answer}")
print(f"Confidence: {result.confidence}")