It's OpenTelemetry instrumentation (python) for OpenAI's library.
Project site: https://github.com/cartermp/opentelemetry-instrument-openai-py
Supported APIs:
- Chat
- Embeddings
- Moderation
- Image (generation, edit, variation)
- Audio (transcribe, translate)
- Completion (GPT-3)
- Edit (GPT-3)
Simple! First, install this package.
With autoinstrumentation agent:
poetry add opentelemetry-instrument-openai
poetry run opentelemetry-bootstrap -a install
poetry run opentelemetry-instrument python your_app.py
If you prefer to do it in code, you can do that too:
import openai
from dotenv import load_dotenv
from opentelemetry.instrument.openai import OpenAIInstrumentor
OpenAIInstrumentor().instrument()
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role":"user", "content":"Tell me a joke about opentelemetry"}],
)
You can then run your app normally with your own opentelemetry initialization.
Get poetry.
Now install and run tests:
poetry install
poetry run pytest
Now you can develop and run tests as you go!
Click the example folder and read the README.