Ideas on how to implement the Tracing API in the Modelmetry Python SDK #3
lazharichir
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This tracks how to implement a clean, intuitive, yet flexible Tracing API to the Modelmetry Python SDK.
By instrumenting their code with our tracing APIs, developers can generate data (traces, spans, events, findings) that can be visualized and analyzed using the Modelmetry frontend. This will empower users to gain insights into various LLM metrics based on their specific use cases and model outputs.
The main benefits include:
Key Concepts
Example Use Case
For example, a company has a customer service chatbot. One of their customers interacts with the chatbot asking for some help. The developers need to a few steps to get this right:
GetOrderInformation
,RequestRefund
,Escalate
).GetOrderInformation
which you call and send the response to the LLM so it can write a proper response to the user.All of this happened within 3 to 5 seconds. You can trace this operation and see how long each step took, what the LLM did, and what the response was. You can also attach events to each step to see what the LLM was thinking at each step.
The entire operation could have been a single trace named
chatbot.turn
with spansllm.generate
,llm.tools.get_user_message
,llm.generate_final
, andllm.response_check
. Each span could have events attached to them to show what the LLM was thinking at each step. Some findings could be attached to the spans (e.g.,input_tokens
,output_tokens
,response_safe_score
).Technical Design
The Python SDK will be extended with APIs for creating and managing traces, spans, events, and findings.
The backend –and the OpenAPI spec– are already defined. So our implementation needs to elegantly wrap the following entities:
IngestSignalsV1RequestBody
– the data structure that the backend expects.CreateEventParams
,CreateFindingParams
,CreateSpanParams
, andCreateTraceParams
classes.The Tracing API must allow users to:
Span
or aTrace
).Implementation Details
client.flushAll()
call at the end of the request to send all data collected to the backend.Pseudocode just to illustrate the API on a high level
Create a finding for a span
Create an event for a span
Testing
Future Considerations
Beta Was this translation helpful? Give feedback.
All reactions