Skip to content
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

Stop propagating 'id' field from Message object to request payload #10

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions libs/databricks/langchain_databricks/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,6 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
if (name := message.name or message.additional_kwargs.get("name")) is not None:
message_dict["name"] = name

if id := message.id:
message_dict["id"] = id

if isinstance(message, ChatMessage):
return {"role": message.role, **message_dict}
elif isinstance(message, HumanMessage):
Expand Down
11 changes: 11 additions & 0 deletions libs/databricks/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ def test_convert_message(role: str, expected_output: BaseMessage) -> None:
assert dict_result == message


def test_convert_message_not_propagate_id() -> None:
# The AIMessage returned by the model endpoint can contain "id" field,
# but it is not always supported for requests. Therefore, we should not
# propagate it to the request payload.
message = AIMessage(content="foo", id="some-id")
result = _convert_message_to_dict(message)
assert result == {"role": "assistant", "content": "foo"}
B-Step62 marked this conversation as resolved.
Show resolved Hide resolved


def test_convert_message_with_tool_calls() -> None:
ID = "call_fb5f5e1a-bac0-4422-95e9-d06e6022ad12"
tool_calls = [
Expand Down Expand Up @@ -267,6 +276,7 @@ def test_convert_message_with_tool_calls() -> None:

# convert back
dict_result = _convert_message_to_dict(result)
message_with_tools.pop("id") # id is not propagated
assert dict_result == message_with_tools


Expand Down Expand Up @@ -320,6 +330,7 @@ def test_convert_tool_message_chunk() -> None:

# convert back
dict_result = _convert_message_to_dict(result)
delta.pop("id") # id is not propagated
assert dict_result == delta


Expand Down
Loading