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[patch]: support final AIMessage responses in tool_example_to_messages #28267

Merged
merged 5 commits into from
Nov 22, 2024

Conversation

ccurme
Copy link
Collaborator

@ccurme ccurme commented Nov 21, 2024

We have a test test_structured_few_shot_examples in standard integration tests that implements a version of tool-calling few shot examples that works with ~all tested providers. The formulation supported by ~all providers is: human message, tool call, tool message, AI reponse.

Here we update langchain_core.utils.function_calling.tool_example_to_messages to support this formulation.

The tool_example_to_messages util is undocumented outside of our API reference. IMO, if we are testing that this function works across all providers, it can be helpful to feature it in our guides. The structured few-shot examples we document at the moment require users to implement this function and can be simplified.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 21, 2024
Copy link

vercel bot commented Nov 21, 2024

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

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Nov 22, 2024 3:30pm

@dosubot dosubot bot added the langchain Related to the langchain package label Nov 21, 2024
@ccurme ccurme removed the langchain Related to the langchain package label Nov 21, 2024
@@ -495,20 +495,25 @@ def convert_to_openai_tool(


def tool_example_to_messages(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This utility was added 8 months ago but is not documented. Thoughts on retroactively marking it @beta?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure I don't mind!

hmm tool calls are also limited to BaseModel / should probably supported typed dicts

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Marked beta


Looked into supporting TypedDict but we need a way of getting the tool name from an instance of TypedDict

from typing_extensions import TypedDict


class Apple(TypedDict):
    color: str


tool_call = Apple(color="red")
tool_call.__class__.__name__
'dict'

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Nov 21, 2024
@ccurme ccurme enabled auto-merge (squash) November 22, 2024 15:35
@ccurme ccurme merged commit a433039 into master Nov 22, 2024
144 checks passed
@ccurme ccurme deleted the cc/structured_few_shot branch November 22, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm PR looks good. Use to confirm that a PR is ready for merging. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants