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

Langsmith Hub Javascript Inline doesn't work #4915

Closed
5 tasks done
Mosquid opened this issue Mar 28, 2024 · 2 comments · Fixed by #4920
Closed
5 tasks done

Langsmith Hub Javascript Inline doesn't work #4915

Mosquid opened this issue Mar 28, 2024 · 2 comments · Fixed by #4920
Assignees
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@Mosquid
Copy link

Mosquid commented Mar 28, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

const prompt = ChatPromptTemplate.fromMessages([
    ['system', 'You are a helpful assistant'],
    ['placeholder', '{chat_history}'],
    ['human', '{input}'],
    ['placeholder', '{agent_scratchpad}'],
  ]);

Error Message and Stack Trace (if applicable)

No response

Description

https://smith.langchain.com/hub/hwchase17/openai-functions-agent
The code in "Javascript Inline" here is broken.

This is the code provided on the template page:

import { ChatPromptTemplate } from "@langchain/core/prompts";

const prompt = ChatPromptTemplate.fromMessages(
  ["system", "You are a helpful assistant"],
  ["placeholder", "{chat_history}"],
  ["human", "{input}"],
  ["placeholder", "{agent_scratchpad}"],
)

It gives an error: "Expected 1-2 arguments, but got 4".

Based on the langchain docs, it should look like this:

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a helpful assistant"],
  ["placeholder", "{chat_history}"],
  ["human", "{input}"],
  ["placeholder", "{agent_scratchpad}"],
])

But with this modification, it gives a different error: "Missing value for input variable {chat_history}"

System Info

info.txt

Copy link

dosubot bot commented Mar 28, 2024

It looks like there's a misunderstanding in how the ChatPromptTemplate.fromMessages function is used in LangChain JS. The correct usage involves passing an array of BaseMessagePromptTemplate instances, each representing a message in the chat. Here's how you should structure your code:

import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate } from "@langchain/core/prompts";

const prompt = ChatPromptTemplate.fromMessages([
  SystemMessagePromptTemplate.fromTemplate("You are a helpful assistant"),
  PlaceholderPromptTemplate.fromTemplate("{chat_history}"),
  HumanMessagePromptTemplate.fromTemplate("{input}"),
  PlaceholderPromptTemplate.fromTemplate("{agent_scratchpad}"),
]);

This approach uses SystemMessagePromptTemplate.fromTemplate and HumanMessagePromptTemplate.fromTemplate for system and human messages, respectively, and PlaceholderPromptTemplate.fromTemplate for placeholders.

Regarding the "Missing value for input variable {chat_history}" error, it indicates that the placeholder {chat_history} is being used without providing its actual value. Ensure you supply values for all placeholders when using the prompt.format function, like so:

const formattedPrompt = prompt.format({
  chat_history: "Previous chat history",
  input: "User's input",
  agent_scratchpad: "Agent's scratchpad",
});

This method replaces placeholders with their corresponding values, ensuring the prompt is correctly formatted.

For further examples and detailed guidance, consider checking the examples/src/prompts/prompts.ts file in the LangChain JS repository.

If there are any more questions or if something isn't clear, feel free to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Mar 28, 2024
@jacoblee93
Copy link
Collaborator

["placeholder", "{agent_scratchpad}"], isn't supported yet - @rahilvora this would be a good one to add!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants