-
Notifications
You must be signed in to change notification settings - Fork 828
Extra details returned by the model is not tracked by Usage class #1579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ThachNgocTran I agree it would be useful to store these timings and let you access them, but this is not what Since the official OpenAI API doesn't have the Would it be an option to subclass |
@DouweM Thank you for your repsonse. 🙏 Because different models return different sets of "extra details" (not a unified standard), it'd be best to extend the class I'm not super familiar with the source code. Where do you think is best to override a function that extracts extra details of LLM response to fill up the field |
@ThachNgocTran Unfortunately In #1549, we're storing additional (int) details from the Anthropic API, but it wouldn't make sense to do that on the OpenAIModel because the official OpenAI API doesn't return timings. I'm afraid that until one of the official APIs returns timings, we can't support this natively. Note that if you use our observability platform https://pydantic.dev/logfire with |
@DouweM To sum up, the best strategy for my use-case:
Through this way, I don't need any modification of code from pydantic-ai side. What do you think? 😊 |
@ThachNgocTran That's a good route to take for now. In #1238, we're looking at adding a |
Initial Checks
Description
Description
After a LLM finishes a call (request), it also returns some statistics, for example, number of prompt tokens, completion token. This is tracked by the class
Usage
(pydantic-ai/pydantic_ai_slim/pydantic_ai/usage.py
(link))According to the class' Documentation (link), as of 04.2025, the attribute
details
should contain "any extra details returned by the model." But this is not the case with the latest version ofPydantic AI
(version0.1.3
).I use llama-server (part of llama-cpp) as the backend to host a LLM model (in form of GGUF file). Using
tcpflow
(link) to capture the communication between Server and Client, I can see the last messsage sent from the Server as followed:The
completion_tokens
andprompt_tokens
are well-captured by theUsage
class (respectively,response_tokens
andrequest_tokens
). But all about the time taken to process, e.g.prompt_ms
,prompt_per_token_ms
are missed in the fielddetails
ofUsage
class. Unless I am mistaken, the field should contain any extra details returned by the model.Expectation
The field
details
ofUsage
class should contain any extra details returned by the model, e.g.timings
orprompt_per_token_ms
.Example Code
Python, Pydantic AI & LLM client version
The text was updated successfully, but these errors were encountered: