AgentOps-AI / AgentOps-AI/tokencost

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

Aperta
#228 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
2k
Fork
105
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.