chatgpt-web
chatgpt-web copied to clipboard
怎么知道每次对话消耗的token数量?
我看到网上别人贴出来的响应,有使用量记录,不知这个怎么没有?谢谢 类似下面这样的(usage):
"id": "chatcmpl-6q0Kqgk2qlcpCGDYcLQnUmUVVrMd6",
"object": "chat.completion",
"created": 1677852364,
"model": "gpt-3.5-turbo-0301",
"usage": {
"prompt_tokens": 69,
"completion_tokens": 20,
"total_tokens": 89
},
"choices": [
{
"message": {
"role": "assistant",
"content": "起草一封电子邮件或其他写作材料。"
},
"finish_reason": "stop",
"index": 0
}
]
}```
现阶段是没有的,如果你是自己的key和账号,可以在这里查看https://platform.openai.com/account/usage
OpenAI的cookbook里面说: For cl100k_base and p50k_base encodings, tiktoken is the only tokenizer available as of March 2023. Python: tiktoken(https://github.com/openai/tiktoken/blob/main/README.md)
你可以直接问chatgpt:"how many tokens were used in the last reply?"
谢谢,看能不能程序调用,我也找到了这个库
OpenAI的cookbook里面说: For cl100k_base and p50k_base encodings, tiktoken is the only tokenizer available as of March 2023. Python: tiktoken(https://github.com/openai/tiktoken/blob/main/README.md)
这个是查看整体的token数,分不清是哪次会话调用的
你可以直接问chatgpt:"how many tokens were used in the last reply?"
好的,我试试
how many tokens were used in the last reply?
我测试了一下,回答不准,不是按openai的方法计算的
这里不是已经告诉你了吗
"usage": {
"prompt_tokens": 69,
"completion_tokens": 20,
"total_tokens": 89
},
这里不是已经告诉你了吗 "usage": { "prompt_tokens": 69, "completion_tokens": 20, "total_tokens": 89 },
目前这个项目的接口没有返回上面的信息
"usage": {
"prompt_tokens": 69,
"completion_tokens": 20,
"total_tokens": 89
},
这段返回是官方的接口里的,
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "What is the OpenAI mission?"}]
}'
{
"id": "chatcmpl-6p5FEv1JHictSSnDZsGU4KvbuBsbu",
"object": "messages",
"created": 1677693600,
"model": "gpt-3.5-turbo",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "OpenAI's mission is to ensure that artificial general intelligence benefits all of humanity."
}
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 18,
"total_tokens": 38
}
}
来源:https://openai.com/blog/introducing-chatgpt-and-whisper-apis