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 bc53a9d
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"] == True:

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 (E712)

langchain_mistralai/chat_models.py:348:54: E712 Avoid equality comparisons to `True`; use `if message.additional_kwargs["prefix"]:` for truth checks

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 (97 > 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 (E712)

langchain_mistralai/chat_models.py:348:54: E712 Avoid equality comparisons to `True`; use `if message.additional_kwargs["prefix"]:` for truth checks

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 (97 > 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 bc53a9d

Please sign in to comment.