Skip to main content

Respan instrumentation plugin for Instructor

Project description

respan-instrumentation-instructor

Respan instrumentation plugin for Instructor. This package instruments Instructor's native patch() and Instructor.create() paths directly and emits Respan-compatible chat spans without using openinference-instrumentation-instructor.

Configuration

1. Install

pip install respan-instrumentation-instructor

2. Set Environment Variables

Variable Required Description
RESPAN_API_KEY Yes Your Respan API key. Authenticates both proxy and tracing.
RESPAN_BASE_URL No Defaults to https://api.respan.ai/api.

Quickstart

3. Run Script

import os

import instructor
from dotenv import load_dotenv
from openai import OpenAI
from pydantic import BaseModel
from respan import Respan
from respan_instrumentation_instructor import InstructorInstrumentor

load_dotenv()

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")

# Route OpenAI traffic through the Respan gateway.
os.environ["OPENAI_API_KEY"] = respan_api_key
os.environ["OPENAI_BASE_URL"] = respan_base_url


class UserInfo(BaseModel):
    name: str
    age: int


respan = Respan(
    api_key=respan_api_key,
    base_url=respan_base_url,
    app_name="instructor-quickstart",
    instrumentations=[InstructorInstrumentor()],
)

client = instructor.from_openai(OpenAI())
user_info = client.create(
    response_model=UserInfo,
    messages=[{"role": "user", "content": "Ada Lovelace is 36 years old."}],
    model="gpt-4o-mini",
)

print(user_info.model_dump())
respan.flush()

4. View Dashboard

After running the script, traces appear on your Respan dashboard.

Further Reading

Runnable examples with full setup instructions:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

respan_instrumentation_instructor-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file respan_instrumentation_instructor-0.1.0.tar.gz.

File metadata

File hashes

Hashes for respan_instrumentation_instructor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67b5a4350e15959c2e742d15b03bed9cbd1ba752217484372ef31b3527464d36
MD5 e8b19c3c09c518b4b9dda8f71a8466ca
BLAKE2b-256 2a2e890d6ff8fcd37d0148a2fa23ed4bc82cd9e6aecf808a549ac93e04647811

See more details on using hashes here.

File details

Details for the file respan_instrumentation_instructor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_instrumentation_instructor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1a231c97af16eaeacc0242a051fd6807a99293135877f14d136e787a0973eeb
MD5 4988a2f59b2a2d8feeb5aa4be8507c3e
BLAKE2b-256 31347d904fdac58d1fdcd0d56d12e9b41e153e6485a18ec53ff6f10be07639dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page