AgentOps-AI / AgentOps-AI/tokencost

'num_tokens_from_messages() is not implemented for model gpt-5-nano

Đang mở
#228 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
2k
Fork
105
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.