-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial test for llm spans * llm input messages * llm tool definitions * llm tool calls * record tests * nix encoder
- Loading branch information
1 parent
8c71f4a
commit 2784a6b
Showing
13 changed files
with
551 additions
and
70 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
python/instrumentation/openinference-instrumentation-smolagents/examples/openai_model.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,22 @@ | ||
import os | ||
|
||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import ( | ||
SimpleSpanProcessor, | ||
) | ||
from smolagents import OpenAIServerModel | ||
|
||
from openinference.instrumentation.smolagents import SmolagentsInstrumentor | ||
|
||
endpoint = "http://0.0.0.0:6006/v1/traces" | ||
trace_provider = TracerProvider() | ||
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) | ||
|
||
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider, skip_dep_check=True) | ||
|
||
model = OpenAIServerModel( | ||
model_id="gpt-4o", api_key=os.environ["OPENAI_API_KEY"], api_base="https://api.openai.com/v1" | ||
) | ||
output = model(messages=[{"role": "user", "content": "hello world"}]) | ||
print(output) |
42 changes: 42 additions & 0 deletions
42
...strumentation/openinference-instrumentation-smolagents/examples/openai_model_tool_call.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,42 @@ | ||
import os | ||
|
||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import ( | ||
SimpleSpanProcessor, | ||
) | ||
from smolagents import OpenAIServerModel | ||
from smolagents.tools import Tool | ||
|
||
from openinference.instrumentation.smolagents import SmolagentsInstrumentor | ||
|
||
endpoint = "http://0.0.0.0:6006/v1/traces" | ||
trace_provider = TracerProvider() | ||
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) | ||
|
||
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider, skip_dep_check=True) | ||
|
||
|
||
class GetWeatherTool(Tool): | ||
name = "get_weather" | ||
description = "Get the weather for a given city" | ||
inputs = {"location": {"type": "string", "description": "The city to get the weather for"}} | ||
output_type = "string" | ||
|
||
def forward(self, location: str) -> str: | ||
return "sunny" | ||
|
||
|
||
model = OpenAIServerModel( | ||
model_id="gpt-4o", api_key=os.environ["OPENAI_API_KEY"], api_base="https://api.openai.com/v1" | ||
) | ||
output_message = model( | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "What is the weather in Paris?", | ||
} | ||
], | ||
tools_to_call_from=[GetWeatherTool()], | ||
) | ||
print(output_message) |
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
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
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.