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

partners: allow to set Prefix in AIMessage (for MistralAI) #28846

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions libs/partners/mistralai/langchain_mistralai/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ def _convert_message_to_mistral_chat_message(
message_dict["content"] = ""
else:
message_dict["content"] = message.content
if "prefix" in message.additional_kwargs:
message_dict["prefix"] = message.additional_kwargs["prefix"]
return message_dict
elif isinstance(message, SystemMessage):
return dict(role="system", content=message.content)
Expand Down
4 changes: 4 additions & 0 deletions libs/partners/mistralai/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def test_mistralai_initialization_baseurl_env(env_var_name: str) -> None:
AIMessage(content="Hello"),
dict(role="assistant", content="Hello"),
),
(
AIMessage(content="{", additional_kwargs={"prefix": True}),
dict(role="assistant", content="{", prefix=True),
),
(
ChatMessage(role="assistant", content="Hello"),
dict(role="assistant", content="Hello"),
Expand Down
Loading