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

core[minor]: add name to basemessage #17539

Merged
merged 6 commits into from
Feb 14, 2024

Conversation

efriis
Copy link
Contributor

@efriis efriis commented Feb 14, 2024

Adds an optional name param to our base message to support passing names into LLMs.

OpenAI supports having a name on anything except tool message now (system, ai, user/human).

Copy link

vercel bot commented Feb 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Feb 14, 2024 7:16pm

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Ɑ: models Related to LLMs or chat model modules 🤖:improvement Medium size change to existing code to handle new use-cases 🔌: openai Primarily related to OpenAI integrations labels Feb 14, 2024
Comment on lines 32 to 60
assert AIMessageChunk(content="I am") + HumanMessageChunk(
content=" indeed."
) == AIMessageChunk(
content="I am indeed."
), "MessageChunk + MessageChunk should be a MessageChunk of same class as the left side" # noqa: E501

assert (
AIMessageChunk(content="", additional_kwargs={"foo": "bar"})
+ AIMessageChunk(content="", additional_kwargs={"baz": "foo"})
== AIMessageChunk(content="", additional_kwargs={"foo": "bar", "baz": "foo"})
assert AIMessageChunk(
content="", additional_kwargs={"foo": "bar"}
) + AIMessageChunk(content="", additional_kwargs={"baz": "foo"}) == AIMessageChunk(
content="", additional_kwargs={"foo": "bar", "baz": "foo"}
), "MessageChunk + MessageChunk should be a MessageChunk with merged additional_kwargs" # noqa: E501

assert (
AIMessageChunk(
content="", additional_kwargs={"function_call": {"name": "web_search"}}
)
+ AIMessageChunk(
content="", additional_kwargs={"function_call": {"arguments": None}}
)
+ AIMessageChunk(
content="", additional_kwargs={"function_call": {"arguments": "{\n"}}
)
+ AIMessageChunk(
content="",
additional_kwargs={
"function_call": {"arguments": ' "query": "turtles"\n}'}
},
)
== AIMessageChunk(
content="",
additional_kwargs={
"function_call": {
"name": "web_search",
"arguments": '{\n "query": "turtles"\n}',
}
},
)
assert AIMessageChunk(
content="", additional_kwargs={"function_call": {"name": "web_search"}}
) + AIMessageChunk(
content="", additional_kwargs={"function_call": {"arguments": None}}
) + AIMessageChunk(
content="", additional_kwargs={"function_call": {"arguments": "{\n"}}
) + AIMessageChunk(
content="",
additional_kwargs={"function_call": {"arguments": ' "query": "turtles"\n}'}},
) == AIMessageChunk(
content="",
additional_kwargs={
"function_call": {
"name": "web_search",
"arguments": '{\n "query": "turtles"\n}',
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no changes here - just formatting

@@ -192,6 +185,21 @@ def test_multiple_msg() -> None:
assert messages_from_dict(messages_to_dict(msgs)) == msgs


def test_multiple_msg_with_name() -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test to confirm name loads/dumps with dict

@@ -480,3 +488,49 @@ def test_convert_to_messages() -> None:
HumanMessage(content="Hello!"),
AIMessage(content="Hi!"),
]


@pytest.mark.parametrize(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test all message types with name except tool (different case)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "name" to snapshots

@efriis efriis requested a review from nfcampos February 14, 2024 19:09
@efriis efriis changed the title core[minor]: add name to ai message core[minor]: add name to basemessage Feb 14, 2024
@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Feb 14, 2024
@efriis efriis merged commit 86d3e42 into master Feb 14, 2024
76 checks passed
@efriis efriis deleted the erick/core-minor-add-name-to-ai-message branch February 14, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. Ɑ: models Related to LLMs or chat model modules 🔌: openai Primarily related to OpenAI integrations size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants