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

[Feat] Accept non-dict if only 1 prompt input variable #19156

Merged
merged 6 commits into from Mar 20, 2024

Conversation

hinthornw
Copy link
Collaborator

For prompt templates with only 1 variable (common in e.g., MessageGraph), it's convenient to wrap the incoming object in the variable before formatting.

The downside of this, of course, would be that some number of invocations will successfully format when the user may have intended to format it properly before

Copy link

vercel bot commented Mar 15, 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 Mar 20, 2024 4:45pm

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Mar 16, 2024
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 18, 2024
@hinthornw hinthornw changed the title [RFC] Accept non-dict [Feat] Accept non-dict if only 1 prompt input variable Mar 18, 2024

def test_messages_prompt_accepts_list() -> None:
prompt = ChatPromptTemplate.from_messages([MessagesPlaceholder("history")])
value = prompt.invoke([("user", "Hi there")]) # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

his is confusing -- are we sure we want to support?, why is it a list of 2-tuples rather than only a 2-tuple?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We already support prompt.invoke({"history": [("user", "hi there"]})

Copy link
Collaborator

@eyurtsev eyurtsev left a comment

Choose a reason for hiding this comment

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

would you be able to document this feature via an example in a relevant place?

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 20, 2024
and you invoke the template with a non-dict object, the prompt template will
inject the provided argument into that variable location.

Single-variable template:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@baskaryan do you think this formatting would work?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be indented at same level as Examples: (L564)

@hinthornw hinthornw merged commit 68298cd into master Mar 20, 2024
95 checks passed
@hinthornw hinthornw deleted the wfh/accept_messages_list branch March 20, 2024 16:59
rahul-trip pushed a commit to daxa-ai/langchain that referenced this pull request Mar 27, 2024
…19156)

For prompt templates with only 1 variable (common in e.g.,
MessageGraph), it's convenient to wrap the incoming object in the
variable before formatting.


The downside of this, of course, would be that some number of
invocations will successfully format when the user may have intended to
format it properly before
bechbd pushed a commit to bechbd/langchain that referenced this pull request Mar 29, 2024
…19156)

For prompt templates with only 1 variable (common in e.g.,
MessageGraph), it's convenient to wrap the incoming object in the
variable before formatting.


The downside of this, of course, would be that some number of
invocations will successfully format when the user may have intended to
format it properly before
gkorland pushed a commit to FalkorDB/langchain that referenced this pull request Mar 30, 2024
…19156)

For prompt templates with only 1 variable (common in e.g.,
MessageGraph), it's convenient to wrap the incoming object in the
variable before formatting.


The downside of this, of course, would be that some number of
invocations will successfully format when the user may have intended to
format it properly before
chrispy-snps pushed a commit to chrispy-snps/langchain that referenced this pull request Mar 30, 2024
…19156)

For prompt templates with only 1 variable (common in e.g.,
MessageGraph), it's convenient to wrap the incoming object in the
variable before formatting.


The downside of this, of course, would be that some number of
invocations will successfully format when the user may have intended to
format it properly before
chrispy-snps pushed a commit to chrispy-snps/langchain that referenced this pull request Mar 30, 2024
…19156)

For prompt templates with only 1 variable (common in e.g.,
MessageGraph), it's convenient to wrap the incoming object in the
variable before formatting.


The downside of this, of course, would be that some number of
invocations will successfully format when the user may have intended to
format it properly before
hinthornw added a commit that referenced this pull request Apr 26, 2024
For prompt templates with only 1 variable (common in e.g.,
MessageGraph), it's convenient to wrap the incoming object in the
variable before formatting.


The downside of this, of course, would be that some number of
invocations will successfully format when the user may have intended to
format it properly before
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
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants