langchain icon indicating copy to clipboard operation
langchain copied to clipboard

ChatOpenAI.get_num_tokens_from_messages: use self.model_name and support GPT-4

Open asadovsky opened this issue 2 years ago • 3 comments

A couple problems:

  • ChatOpenAI.get_num_tokens_from_messages() takes a model parameter that is not included in the base class method signature. Instead, it should use self.model_name, similar to how the BaseOpenAI.get_num_tokens() does.
  • ChatOpenAI.get_num_tokens_from_messages() does not support GPT-4. See here for the updated formula: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb

asadovsky avatar Mar 24 '23 16:03 asadovsky

There is already a PR to fix this issue at #1858. Is this fix acceptable?

Aratako avatar Mar 25 '23 00:03 Aratako

Yes, looks like it would fix this issue, thanks!

One minor suggestion is to link to the official documentation from the code: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb

That way anyone reading the code would know where it came from and can verify that it's up to date.

asadovsky avatar Mar 25 '23 00:03 asadovsky

Thanks! I added the link to code.

Aratako avatar Mar 25 '23 02:03 Aratako

Hi, @asadovsky. I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, the issue was about updating the ChatOpenAI.get_num_tokens_from_messages() method in the repository to use self.model_name instead of the model parameter. Aratako has already submitted a pull request (#1858) to fix this issue, and you have confirmed that the changes are acceptable. Aratako has also added a link to the official documentation in the code as suggested by you.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.

Thank you for your contribution and support in improving LangChain! Let us know if you have any further questions or concerns.

dosubot[bot] avatar Sep 04 '23 16:09 dosubot[bot]