chatgpt-web icon indicating copy to clipboard operation
chatgpt-web copied to clipboard

怎么知道每次对话消耗的token数量?

Open chenying99 opened this issue 1 year ago • 10 comments

我看到网上别人贴出来的响应,有使用量记录,不知这个怎么没有?谢谢 类似下面这样的(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
        }
    ]
}```

chenying99 avatar Mar 10 '23 05:03 chenying99

现阶段是没有的,如果你是自己的key和账号,可以在这里查看https://platform.openai.com/account/usage

nagaame avatar Mar 10 '23 06:03 nagaame

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)

WenJing95 avatar Mar 10 '23 09:03 WenJing95

你可以直接问chatgpt:"how many tokens were used in the last reply?"

fyu0h avatar Mar 11 '23 04:03 fyu0h

谢谢,看能不能程序调用,我也找到了这个库

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)

chenying99 avatar Mar 11 '23 05:03 chenying99

这个是查看整体的token数,分不清是哪次会话调用的

chenying99 avatar Mar 11 '23 05:03 chenying99

你可以直接问chatgpt:"how many tokens were used in the last reply?"

好的,我试试

chenying99 avatar Mar 11 '23 05:03 chenying99

how many tokens were used in the last reply?

我测试了一下,回答不准,不是按openai的方法计算的

chenying99 avatar Mar 11 '23 22:03 chenying99

这里不是已经告诉你了吗
"usage": {
        "prompt_tokens": 69,
        "completion_tokens": 20,
        "total_tokens": 89
    },

diudiudiuu avatar Mar 12 '23 01:03 diudiudiuu

这里不是已经告诉你了吗
"usage": {
        "prompt_tokens": 69,
        "completion_tokens": 20,
        "total_tokens": 89
    },

目前这个项目的接口没有返回上面的信息

chenying99 avatar Mar 12 '23 03:03 chenying99

"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

fyu0h avatar Mar 13 '23 06:03 fyu0h