Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Nov 12, 2024
1 parent def6106 commit 1c0add6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion libs/community/langchain_community/chat_models/anyscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def get_num_tokens_from_messages(
Official documentation: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb
"""
if tools is not None:
warnings.warn("Counting tokens in tool schemas is not yet supported.")
warnings.warn(
"Counting tokens in tool schemas is not yet supported. Ignoring tools."
)
if sys.version_info[1] <= 7:
return super().get_num_tokens_from_messages(messages)
model, encoding = self._get_encoding_model()
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/chat_models/everlyai.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def get_num_tokens_from_messages(
Official documentation: https://github.com/openai/openai-cookbook/blob/
main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb"""
if tools is not None:
warnings.warn("Counting tokens in tool schemas is not yet supported.")
warnings.warn(
"Counting tokens in tool schemas is not yet supported. Ignoring tools."
)
if sys.version_info[1] <= 7:
return super().get_num_tokens_from_messages(messages)
model, encoding = self._get_encoding_model()
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/chat_models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,9 @@ def get_num_tokens_from_messages(
Official documentation: https://github.com/openai/openai-cookbook/blob/
main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb"""
if tools is not None:
warnings.warn("Counting tokens in tool schemas is not yet supported.")
warnings.warn(
"Counting tokens in tool schemas is not yet supported. Ignoring tools."
)
if sys.version_info[1] <= 7:
return super().get_num_tokens_from_messages(messages)
model, encoding = self._get_encoding_model()
Expand Down
5 changes: 5 additions & 0 deletions libs/core/langchain_core/language_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TypeVar,
Union,
)
import warnings

from pydantic import BaseModel, ConfigDict, Field, field_validator
from typing_extensions import TypeAlias, TypedDict, override
Expand Down Expand Up @@ -384,6 +385,10 @@ def get_num_tokens_from_messages(
Returns:
The sum of the number of tokens across the messages.
"""
if tools is not None:
warnings.warn(

Check failure on line 389 in libs/core/langchain_core/language_models/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (B028)

langchain_core/language_models/base.py:389:13: B028 No explicit `stacklevel` keyword argument found

Check failure on line 389 in libs/core/langchain_core/language_models/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (B028)

langchain_core/language_models/base.py:389:13: B028 No explicit `stacklevel` keyword argument found

Check failure on line 389 in libs/core/langchain_core/language_models/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (B028)

langchain_core/language_models/base.py:389:13: B028 No explicit `stacklevel` keyword argument found

Check failure on line 389 in libs/core/langchain_core/language_models/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (B028)

langchain_core/language_models/base.py:389:13: B028 No explicit `stacklevel` keyword argument found

Check failure on line 389 in libs/core/langchain_core/language_models/base.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (B028)

langchain_core/language_models/base.py:389:13: B028 No explicit `stacklevel` keyword argument found
"Counting tokens in tool schemas is not yet supported. Ignoring tools."
)
return sum([self.get_num_tokens(get_buffer_string([m])) for m in messages])

@classmethod
Expand Down
4 changes: 3 additions & 1 deletion libs/partners/openai/langchain_openai/chat_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,9 @@ def get_num_tokens_from_messages(
"""
# TODO: Count bound tools as part of input.
if tools is not None:
warnings.warn("Counting tokens in tool schemas is not yet supported. Ignoring tools.")
warnings.warn(
"Counting tokens in tool schemas is not yet supported. Ignoring tools."
)
if sys.version_info[1] <= 7:
return super().get_num_tokens_from_messages(messages)
model, encoding = self._get_encoding_model()
Expand Down

0 comments on commit 1c0add6

Please sign in to comment.