Skip to main content

OpenInference Instructor Instrumentation

Project description

OpenInference Instructor Instrumentation

pypi

Python auto-instrumentation library for the (Instructor)[https://github.com/jxnl/instructor] library

Installation

pip install openinference-instrumentation-instructor

Quickstart

This quickstart shows you how to instrument Instructor

Install required packages.

pip install instructor arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp

Start Phoenix in the background as a collector. By default, it listens on http://localhost:6006. You can visit the app via a browser at the same address. (Phoenix does not send data over the internet. It only operates locally on your machine.)

python -m phoenix.server.main serve

Set up InstructorInstrumentor to trace your application and send the traces to Phoenix at the endpoint defined below.

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
from openinference.instrumentation.instructor import InstructorInstrumentor
from openinference.instrumentation.openai import OpenAIInstrumentor

InstructorInstrumentor().instrument(tracer_provider=tracer_provider)

# Optionally instrument the OpenAI SDK to get additional observability
OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)

Simple Instructor example

import instructor
from pydantic import BaseModel
from openai import OpenAI


# Define your desired output structure
class UserInfo(BaseModel):
    name: str
    age: int


# Patch the OpenAI client
client = instructor.from_openai(OpenAI())

# Extract structured data from natural language
user_info = client.chat.completions.create(
    model="gpt-3.5-turbo",
    response_model=UserInfo,
    messages=[{"role": "user", "content": "John Doe is 30 years old."}],
)

More Info

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

Built Distribution

File details

Details for the file openinference_instrumentation_instructor-0.1.2.tar.gz.

File metadata

File hashes

Hashes for openinference_instrumentation_instructor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6f970930951ebcc46e05031930bc1577e819301608959bdc9d6e04d171b5a073
MD5 161277ccb5495dd4d8bfc3808d771d0d
BLAKE2b-256 8b85853ad67f4042a2a5df05d56af40635eebe928090addd265f778a57536cd5

See more details on using hashes here.

File details

Details for the file openinference_instrumentation_instructor-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for openinference_instrumentation_instructor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1ac3e63aaba8d99a79f6ec111cd5a320d6121049fdd3e655bfdbfa03693541ae
MD5 3674d5e140630ae453c332106bb9b270
BLAKE2b-256 a9d4c4bd19e9e8c620f98b63f2d65df20e89ec5abc6e1484a6e212dfeecadb44

See more details on using hashes here.

Supported by

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