英文:
Does chatgpt-3.5-turbo API recounts the tokens in billing when sending the conversation history in api
问题
当使用chatgpt-3.5-turbo模型创建聊天应用时,API是否会考虑整个令牌(包括助手消息和旧消息集)来计费,还是只有用户的最后一条消息在每次重新发送API请求时计费?
例如:
messages = [
{"role": "system", "content": "You are a kind helpful assistant."},
]
while True:
message = input("User: ")
if message:
messages.append(
{"role": "user", "content": message},
)
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat.choices[0].message.content
print(f"ChatGPT: {reply}")
messages.append({"role": "assistant", "content": reply})
英文:
When creating a chat app using chatgpt-3.5-turbo model. Does the API consider the whole tokens (including the assistant messages and old set of messages) in billing or just the last message from the user is counted in billing whenever I resend the API request with a new message appended to the conversation?
For eg:
messages = [
{"role": "system", "content": "You are a kind helpful assistant."},
]
while True:
message = input("User : ")
if message:
messages.append(
{"role": "user", "content": message},
)
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat.choices[0].message.content
print(f"ChatGPT: {reply}")
messages.append({"role": "assistant", "content": reply})
</details>
# 答案1
**得分**: 2
如[OpenAI文档][1]中提到的:
> API调用中的总标记数会影响API调用的成本,因为您按标记付费 <br>
输入和输出标记都计入这些数量。例如,如果您的API调用在消息输入中使用了10个标记,并在消息输出中收到了20个标记,您将被收费30个标记。
要查看API调用使用了多少标记,请检查API响应中的usage字段
response['usage']['total_tokens']
每次您将以前的聊天附加到消息中的`append`时,`total_token`的数量都会增加。因此,以前消息的所有标记都将计入账单。
[1]: https://platform.openai.com/docs/guides/chat/introduction
<details>
<summary>英文:</summary>
As mentioned in [OpenAI document][1]:
> The total number of tokens in an API call affects how much your API call costs, as you pay per token <br>
Both input and output tokens count toward these quantities. For example, if your API call used 10 tokens in the message input and you received 20 tokens in the message output, you would be billed for 30 tokens.
To see how many tokens are used by an API call, check the usage field in the API response
response['usage']['total_tokens']
Each time you `append` previous chats to `messages`, the number of `total_token` will increases. So all tokens of previous messages will be considered in the bill.
[1]: https://platform.openai.com/docs/guides/chat/introduction
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论