-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vertexai: refactor: simplify content processing in anthropic formatter #601
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,14 +205,18 @@ def _format_params( | |
|
||
def _format_output(self, data: Any, **kwargs: Any) -> ChatResult: | ||
data_dict = data.model_dump() | ||
content = [c for c in data_dict["content"] if c["type"] != "tool_use"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main difference, here, we would only have elements in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome -- thanks for calling this out @Reprazent! updated the description as well. |
||
content = content[0]["text"] if len(content) == 1 else content | ||
content = data_dict["content"] | ||
llm_output = { | ||
k: v for k, v in data_dict.items() if k not in ("content", "role", "type") | ||
} | ||
tool_calls = _extract_tool_calls(data_dict["content"]) | ||
if tool_calls: | ||
msg = AIMessage(content=content, tool_calls=tool_calls) | ||
if len(content) == 1 and content[0]["type"] == "text": | ||
msg = AIMessage(content=content[0]["text"]) | ||
elif any(block["type"] == "tool_use" for block in content): | ||
tool_calls = _extract_tool_calls(content) | ||
msg = AIMessage( | ||
content=content, | ||
tool_calls=tool_calls, | ||
) | ||
else: | ||
msg = AIMessage(content=content) | ||
# Collect token usage | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we add a test for
_format_output
similar to the test that we have in the main lanchain library: https://github.com/langchain-ai/langchain/blob/f1222739f88bfdf37513af146da6b9dbf2a091c4/libs/partners/anthropic/tests/unit_tests/test_chat_models.py#L87-L109We should base the input for the test here on what we noticed was causing the errors. So instead of passing only a
TextBlock
, we should only pass aToolUseBlock
like we do in our test. I suspect this will fail in the previous implementation.What do you think?