-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bd830c
commit 50be6c8
Showing
14 changed files
with
461 additions
and
376 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
python/instrumentation/openinference-instrumentation-openai/examples/chat_completions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import openai | ||
from openinference.instrumentation.openai import OpenAIInstrumentor | ||
from opentelemetry import trace as trace_api | ||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
from opentelemetry.sdk import trace as trace_sdk | ||
from opentelemetry.sdk.resources import Resource | ||
from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
|
||
resource = Resource(attributes={}) | ||
tracer_provider = trace_sdk.TracerProvider(resource=resource) | ||
span_exporter = OTLPSpanExporter(endpoint="http://127.0.0.1:6006/v1/traces") | ||
span_processor = SimpleSpanProcessor(span_exporter=span_exporter) | ||
tracer_provider.add_span_processor(span_processor=span_processor) | ||
trace_api.set_tracer_provider(tracer_provider=tracer_provider) | ||
|
||
OpenAIInstrumentor().instrument() | ||
|
||
|
||
if __name__ == "__main__": | ||
response = openai.OpenAI().chat.completions.create( | ||
model="gpt-3.5-turbo", | ||
messages=[{"role": "user", "content": "Write a haiku."}], | ||
max_tokens=20, | ||
) | ||
print(response.choices[0].message.content) |
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
python/instrumentation/openinference-instrumentation-openai/examples/embeddings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import openai | ||
from openinference.instrumentation.openai import OpenAIInstrumentor | ||
from opentelemetry import trace as trace_api | ||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
from opentelemetry.sdk import trace as trace_sdk | ||
from opentelemetry.sdk.resources import Resource | ||
from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
|
||
resource = Resource(attributes={}) | ||
tracer_provider = trace_sdk.TracerProvider(resource=resource) | ||
span_exporter = OTLPSpanExporter(endpoint="http://127.0.0.1:6006/v1/traces") | ||
span_processor = SimpleSpanProcessor(span_exporter=span_exporter) | ||
tracer_provider.add_span_processor(span_processor=span_processor) | ||
trace_api.set_tracer_provider(tracer_provider=tracer_provider) | ||
|
||
OpenAIInstrumentor().instrument() | ||
|
||
|
||
if __name__ == "__main__": | ||
response = openai.OpenAI().embeddings.create( | ||
model="text-embedding-ada-002", | ||
input="hello world", | ||
) | ||
print(response.data[0].embedding) |
29 changes: 29 additions & 0 deletions
29
.../instrumentation/openinference-instrumentation-openai/examples/with_httpx_instrumentor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from importlib import import_module | ||
|
||
from openinference.instrumentation.openai import OpenAIInstrumentor | ||
from opentelemetry import trace as trace_api | ||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor | ||
from opentelemetry.sdk import trace as trace_sdk | ||
from opentelemetry.sdk.resources import Resource | ||
from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
|
||
resource = Resource(attributes={}) | ||
tracer_provider = trace_sdk.TracerProvider(resource=resource) | ||
span_exporter = OTLPSpanExporter(endpoint="http://127.0.0.1:6006/v1/traces") | ||
span_processor = SimpleSpanProcessor(span_exporter=span_exporter) | ||
tracer_provider.add_span_processor(span_processor=span_processor) | ||
trace_api.set_tracer_provider(tracer_provider=tracer_provider) | ||
|
||
HTTPXClientInstrumentor().instrument() | ||
OpenAIInstrumentor().instrument() | ||
|
||
|
||
if __name__ == "__main__": | ||
openai = import_module("openai") | ||
response = openai.OpenAI().chat.completions.create( | ||
model="gpt-3.5-turbo", | ||
messages=[{"role": "user", "content": "Write a haiku."}], | ||
max_tokens=20, | ||
) | ||
print(response.choices[0].message.content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.