Skip to content

How to get the usage and other information responded by OpenAI? #6

@nasirus

Description

@nasirus

This is the response message from the OpenAI api:

{
"id":"chatcmpl-abc123",
"object":"chat.completion",
"created":1677858242,
"model":"gpt-3.5-turbo-0301",
"usage":{
"prompt_tokens":13,
"completion_tokens":7,
"total_tokens":20
},
"choices":[
{
"message":{
"role":"assistant",
"content":"\n\nThis is a test!"
},
"finish_reason":"stop",
"index":0
}
]
}
Here's the response I get using index.query:

{
"extra_info": null,
"response": "text",
"source_nodes": [
{
"node": {
"doc_hash": "42b5f8b6acb0c03e229b6093479990dccf70e77525d9ce869cabea7bc8389460",
"doc_id": "047322ad-3bc6-49be-a2fb-6a0a710c39fb",
"embedding": null,
"extra_info": null,
"node_info": {
"end": 12360,
"start": 11744
},
"relationships": {
"1": "a07a2f85-7735-4648-b78f-a43b66bc38fb",
"2": "85320698-eeef-4682-ad22-a1fc4d968807",
"3": "729bf224-b65c-4285-94df-7492abf989d1"
},
"text":"\ntext\n"
},
"score": 0.8182768021866872
}
]
}
How can I get the usage and other information returned by OpenAI? Compared with the prediction, this really reflects my spending.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions