-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Track usage for OpenAI models even when streaming #591
Labels
Comments
Testing my implementation manually: llm -m gpt-4o-mini hi
[
{
"id": "01jbav6h7k7gg9f486p9n0nw58",
"model": "gpt-4o-mini",
"prompt": "hi",
"system": null,
"prompt_json": {
"messages": [
{
"role": "user",
"content": "hi"
}
]
},
"options_json": {},
"response": "Hello! How can I assist you today?",
"response_json": {
"content": "Hello! How can I assist you today?",
"finish_reason": "stop",
"usage": {
"completion_tokens": 9,
"prompt_tokens": 8,
"total_tokens": 17,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0
}
},
"id": "chatcmpl-ANUV2zARjPvOzBEJoeJAHMZztmyMA",
"object": "chat.completion.chunk",
"model": "gpt-4o-mini-2024-07-18",
"created": 1730162148
},
"conversation_id": "01jbav6h7h5ek2fyykq19kb56y",
"duration_ms": 1120,
"datetime_utc": "2024-10-29T00:35:47.471634",
"conversation_name": "hi",
"conversation_model": "gpt-4o-mini",
"attachments": []
}
] With llm -m gpt-4o-mini hi --no-stream [
{
"id": "01jbav9cg9ecktc06rtvmdm0gx",
"model": "gpt-4o-mini",
"prompt": "hi",
"system": null,
"prompt_json": {
"messages": [
{
"role": "user",
"content": "hi"
}
]
},
"options_json": {},
"response": "Hello! How can I assist you today?",
"response_json": {
"id": "chatcmpl-ANUWXkIeaElMNKblDP83pT9qk9t0m",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Hello! How can I assist you today?",
"role": "assistant"
}
}
],
"created": 1730162241,
"model": "gpt-4o-mini-2024-07-18",
"object": "chat.completion",
"system_fingerprint": "fp_f59a81427f",
"usage": {
"completion_tokens": 9,
"prompt_tokens": 8,
"total_tokens": 17,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0
}
}
},
"conversation_id": "01jbav9cg7qntkka2hvca72yhd",
"duration_ms": 603,
"datetime_utc": "2024-10-29T00:37:21.450264",
"conversation_name": "hi",
"conversation_model": "gpt-4o-mini",
"attachments": []
}
] For a completion model: llm -m gpt-3.5-turbo-instruct 'capital of france is ' [
{
"id": "01jbavbrwsrtwgt5snjz6t7fgd",
"model": "gpt-3.5-turbo-instruct",
"prompt": "capital of france is ",
"system": null,
"prompt_json": {
"messages": [
"capital of france is "
]
},
"options_json": {},
"response": " Paris\n\n",
"response_json": {
"content": " Paris\n\n",
"usage": {
"completion_tokens": 2,
"prompt_tokens": 5,
"total_tokens": 7
},
"id": "cmpl-ANUXorptC5yuMOMLF1Z4JL2pCz2DF",
"object": "text_completion",
"model": "gpt-3.5-turbo-instruct",
"created": 1730162320
},
"conversation_id": "01jbavbrwqfp0b0t22x9tk71at",
"duration_ms": 633,
"datetime_utc": "2024-10-29T00:38:39.644058",
"conversation_name": "capital of france is ",
"conversation_model": "gpt-3.5-turbo-instruct",
"attachments": []
}
] And that with [
{
"id": "01jbavcgc4f40zy4ynqnvbmv24",
"model": "gpt-3.5-turbo-instruct",
"prompt": "capital of france is ",
"system": null,
"prompt_json": {
"messages": [
"capital of france is "
]
},
"options_json": {},
"response": " paris\n\n\nThe capital of France is indeed Paris. It is located in the northern part of the country and is known for its historic landmarks, art, fashion, and cuisine. It is also a major global city, with a population of over 2 million people. The Eiffel Tower, Notre-Dame Cathedral, and the Louvre Museum are some of its most famous attractions. Paris is also known as the \"City of Love\" and is a popular tourist destination.",
"response_json": {
"id": "cmpl-ANUYBosUNuPgLZJZF20dxAHKUhN8b",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"text": " paris\n\n\nThe capital of France is indeed Paris. It is located in the northern part of the country and is known for its historic landmarks, art, fashion, and cuisine. It is also a major global city, with a population of over 2 million people. The Eiffel Tower, Notre-Dame Cathedral, and the Louvre Museum are some of its most famous attractions. Paris is also known as the \"City of Love\" and is a popular tourist destination."
}
],
"created": 1730162343,
"model": "gpt-3.5-turbo-instruct",
"object": "text_completion",
"usage": {
"completion_tokens": 96,
"prompt_tokens": 5,
"total_tokens": 101
}
},
"conversation_id": "01jbavcgc2y0vm77r63q0pz9x1",
"duration_ms": 1643,
"datetime_utc": "2024-10-29T00:39:02.677491",
"conversation_name": "capital of france is ",
"conversation_model": "gpt-3.5-turbo-instruct",
"attachments": []
}
] |
The
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OpenAI used to not return usage information in streams, but now they do:
https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream_options
The text was updated successfully, but these errors were encountered: