microsoft / promptflow

Build high-quality LLM apps - from prototyping, testing to production deployment and monitoring.
https://microsoft.github.io/promptflow/
MIT License
9.55k stars 872 forks source link

[BUG] Bad token estimation in Prompty #3809

Closed ianchi closed 6 days ago

ianchi commented 1 month ago

Describe the bug Token estimation is wrong, as it doesn't take into account the functions/tools definition as part of the prompt. In cases with heavy use of tools this can make a big diference and make you take a wrong decision regarding the token limit of a request.

How To Reproduce the bug Steps to reproduce the behavior, how frequent can you experience the bug:

  1. Create a prompty file with a large tools definition
  2. Make an estimation with a small question
  3. compare with the actual token consumption reported by oai response

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Running Information(please complete the following information):

Additional context Add any other context about the problem here.

ianchi commented 1 month ago

Additionally token from messages is also incorrect. It doesn't take into account when an assistant's message has tool_calls

And when using Azure OpenAI the wrong model type may be selected. num_tokens_from_messages expects the model as string using one of OpenAI model's labels, but in this case the azure_deployment is used. This is a user generated label and not necessarily a valid model name, so the token count raises error and can´t be used.

github-actions[bot] commented 1 week ago

Hi, we're sending this friendly reminder because we haven't heard back from you in 30 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 7 days of this comment, the issue will be automatically closed. Thank you!