ChatOpenAI.get_num_tokens_from_messages: use self.model_name and support GPT-4
A couple problems:
ChatOpenAI.get_num_tokens_from_messages()takes amodelparameter that is not included in the base class method signature. Instead, it should useself.model_name, similar to how theBaseOpenAI.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
There is already a PR to fix this issue at #1858. Is this fix acceptable?
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.
Thanks! I added the link to code.
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.