Skip to content

Commit

Permalink
feat: allow to set Prefix in AIMessage (for MistralAI)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain DEPARTE committed Dec 20, 2024
1 parent 5a351a1 commit e42a764
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
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 and message.additional_kwargs["prefix"]:

Check failure on line 348 in libs/partners/mistralai/langchain_mistralai/chat_models.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/mistralai / make lint #3.13

Ruff (E501)

langchain_mistralai/chat_models.py:348:89: E501 Line too long (89 > 88)

Check failure on line 348 in libs/partners/mistralai/langchain_mistralai/chat_models.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/mistralai / make lint #3.9

Ruff (E501)

langchain_mistralai/chat_models.py:348:89: E501 Line too long (89 > 88)
message_dict["prefix"] = True
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

0 comments on commit e42a764

Please sign in to comment.