A reliable structured output client.
Project description
Pulsar: Structured LLM Output Parser
Pulsar is the today and next-generation tool to build AI applicatios by providing structured output parsing. It allow use with any model hosted in an API compatible with OpenAIAPI, even if that doesn't support json, or function calling (OpenAI o1, Qwen QwQ, DeepSeek R1 ..) and models multi-modal.
Installation
pip install pulsar-struct
Quick Start
from pulsar.client import Client
from pydantic import BaseModel
# Define your output structure
class UserInfo(BaseModel):
name: str
age: int
interests: List[str]
# Initialize client
client = Client()
# Get structured response
response, metadata = client.chat_completion(
messages=[{"role": "user", "content": "Extract: John, 25 years old, likes reading and hiking"}],
model="openai/gpt-4o-mini",
response_type=UserInfo
)
print(response) # UserInfo(name='John', age=25, interests=['reading', 'hiking'])
Provider Configuration
Current supported providers:
- OpenAI
- Anthropic
- Gemini
- Groq
- OpenRouter
- Ollama
- OpenAIAPILike
Each provider can be configured with specific options:
# Anthropic
client = AnthropicClient(api_key="your-anthropic-key")
# OpenAI
client = OpenAIClient(api_key="your-openai-key")
# Groq
client = GroqClient(api_key="your-groq-key")
# Ollama
client = OllamaClient() # or set the enpoint using base_url="http://host:port"
# default is "http://localhost:11434"
Advanced Usage
Structured output parsing handle all in background for you:
- Convert LLM responses to Pydantic models
- Automatic type coercion
- Handle imperfect JSON responses
- Support for complex data types (enums, literals, nested models)
Custom Response Types
from typing import List, Optional
from pydantic import BaseModel
from enum import Enum
class Sentiment(Enum):
POSITIVE = "positive"
NEGATIVE = "negative"
NEUTRAL = "neutral"
class Analysis(BaseModel):
sentiment: Sentiment
confidence: float
keywords: List[str]
summary: Optional[str]
response, metadata = client.chat_completion(
system="Analyse the products",
messages=[{"role": "user", "content": "Analyze: Great product, highly recommend!"}],
model="claude-2",
response_type=Analysis
)
Endpoint Retries
response, _ = client.chat_completion(
messages=[...],
model="gpt-4",
max_retries=3
)
Streaming Support
client = Client()
for chunk, _ in client.chat_completion(
messages=[...],
model="groq/llama-3.3-70b-versatile",
stream=True
):
print(chunk, end="")
JSON Parsing Features
- Handle unquoted strings
- Fix missing commas and brackets
- Support for partial objects (streaming)
- Automatic type coercion
- Handle embedded type information
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pulsar_struct-0.2.0.dev0.tar.gz
(52.8 kB
view details)
Built Distribution
File details
Details for the file pulsar_struct-0.2.0.dev0.tar.gz
.
File metadata
- Download URL: pulsar_struct-0.2.0.dev0.tar.gz
- Upload date:
- Size: 52.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc97dc82f43d75282c2ad421e1c3b64145b7945db4b620f32333fd4aa313b76f |
|
MD5 | 436831ea504f1532e8e3ae4e40f3c2f7 |
|
BLAKE2b-256 | a045e1bae363a3b008cf253371a62e82439c91e966fb41d5826332d3147d7cfe |
File details
Details for the file pulsar_struct-0.2.0.dev0-py3-none-any.whl
.
File metadata
- Download URL: pulsar_struct-0.2.0.dev0-py3-none-any.whl
- Upload date:
- Size: 49.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f2b20692c7c2829758cef7c3adf51c4b217f33b14d744eccc534eaeff191e4b |
|
MD5 | aa2d9a552f8661862e25b6fd4a1bfb2f |
|
BLAKE2b-256 | 176bc1cc53a6711537193cf08de3a2094acd30a221d6004efdf6738c7dc892aa |