AgentOps-AI / AgentOps-AI/tokencost
'num_tokens_from_messages() is not implemented for model gpt-5-nano
- 主要语言
- Python
- 星标
- 2k
- 派生
- 105
- PR 合并指标
- 30 天内没有已合并 PR
描述
I get:
```
Exception has occurred: KeyError
'num_tokens_from_messages() is not implemented for model gpt-5-nano.
See https://github.com/openai/openai-python/blob/main/chatml.md for how messages are converted to tokens.'
File "/mnt/c/Github/NLP/sketch_cost_5.py", line 55, in
prompt_cost = calculate_prompt_cost(prompt, model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'num_tokens_from_messages() is not implemented for model gpt-5-nano.
See https://github.com/openai/openai-python/blob/main/chatml.md for how messages are converted to tokens.'
```
With:
```python
from openai import OpenAI
client = OpenAI()
model = "gpt-5-nano"
prompt = [{ "role": "user", "content": "Say this is a test"}]
chat_completion = client.chat.completions.create(messages=prompt, model=model)
completion = chat_completion.choices[0].message.content
# "This is a test."
prompt_cost = calculate_prompt_cost(prompt, model)
completion_cost = calculate_completion_cost(completion, model)
print(f"{prompt_cost} + {completion_cost} = {prompt_cost + completion_cost}")
# 0.0000180 + 0.000010 = 0.0000280
```
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。