mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-03 10:12:33 +00:00
x
This commit is contained in:
parent
5d7fbedb21
commit
c26f2447eb
@ -39,7 +39,6 @@ from langchain_core.language_models.base import (
|
|||||||
)
|
)
|
||||||
from langchain_core.messages import (
|
from langchain_core.messages import (
|
||||||
AIMessage,
|
AIMessage,
|
||||||
BaseMessage,
|
|
||||||
convert_to_openai_image_block,
|
convert_to_openai_image_block,
|
||||||
get_buffer_string,
|
get_buffer_string,
|
||||||
is_data_content_block,
|
is_data_content_block,
|
||||||
@ -924,13 +923,13 @@ class BaseChatModelV1(BaseLanguageModel[AIMessageV1], ABC):
|
|||||||
Returns:
|
Returns:
|
||||||
The sum of the number of tokens across the messages.
|
The sum of the number of tokens across the messages.
|
||||||
"""
|
"""
|
||||||
messages = [_convert_from_v1_message(message) for message in messages]
|
messages_v0 = [_convert_from_v1_message(message) for message in messages]
|
||||||
if tools is not None:
|
if tools is not None:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Counting tokens in tool schemas is not yet supported. Ignoring tools.",
|
"Counting tokens in tool schemas is not yet supported. Ignoring tools.",
|
||||||
stacklevel=2,
|
stacklevel=2,
|
||||||
)
|
)
|
||||||
return sum(self.get_num_tokens(get_buffer_string([m])) for m in messages)
|
return sum(self.get_num_tokens(get_buffer_string([m])) for m in messages_v0)
|
||||||
|
|
||||||
|
|
||||||
def _gen_info_and_msg_metadata(
|
def _gen_info_and_msg_metadata(
|
||||||
|
@ -329,9 +329,9 @@ class AIMessageChunk:
|
|||||||
def add_chunk_to_invalid_tool_calls(chunk: ToolCallChunk) -> None:
|
def add_chunk_to_invalid_tool_calls(chunk: ToolCallChunk) -> None:
|
||||||
invalid_tool_calls.append(
|
invalid_tool_calls.append(
|
||||||
create_invalid_tool_call(
|
create_invalid_tool_call(
|
||||||
name=chunk["name"],
|
name=chunk.get("name", ""),
|
||||||
args=chunk["args"],
|
args=chunk.get("args", ""),
|
||||||
id=chunk["id"],
|
id=chunk.get("id", ""),
|
||||||
error=None,
|
error=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -342,9 +342,9 @@ class AIMessageChunk:
|
|||||||
if isinstance(args_, dict):
|
if isinstance(args_, dict):
|
||||||
tool_calls.append(
|
tool_calls.append(
|
||||||
create_tool_call(
|
create_tool_call(
|
||||||
name=chunk["name"] or "",
|
name=chunk.get("name", ""),
|
||||||
args=args_,
|
args=args_,
|
||||||
id=chunk["id"],
|
id=chunk.get("id", ""),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user