Replies: 1 comment
-
🤖 Hello! Based on your question, it seems you want to automatically call a chain that translates the model's prediction to match the language of the input question, after an agent runs, without having to manually code it each time. In LangChainJS, you can achieve this by using the Here is an example of how you can use it: const chat = new ChatOpenAI({ temperature: 0 });
const chatPrompt = ChatPromptTemplate.fromPromptMessages([
[
"system",
"You are a helpful assistant that translates {input_language} to {output_language}.",
],
["human", "{text}"],
]);
const chainB = new LLMChain({
prompt: chatPrompt,
llm: chat,
});
const resB = await chainB.call({
input_language: "English",
output_language: "French",
text: "I love programming.",
});
console.log({ resB });
// { resB: { text: "J'adore la programmation." } } In this code, Regarding your question about the If you want to automatically call the translation chain after the agent runs, you might need to create a custom chain or function that wraps the agent execution and translation into a single operation. This custom chain or function would take the input question, run the agent to get the prediction, and then call the translation chain with the input question and the prediction. I hope this helps! If you have any other questions, feel free to ask. Sources
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. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hii! I'm trying to ensure that the language of the user input question matches the language of an agent's response. But just with prompt, a lot of errors are happening.
I created a chain that receives the input question and the model prediction, identifies the language of the input question, and if the model prediction is not in the same language, translates it.
However, I have to code it manually every time I call the agent, get its response and put it in the translation chain. Is there any way I can configure the agent so that it automatically performs this task when it reaches its final response?
My current code is more or less like this:
I tried doing something like this:
translatorChain
automatically receives the response from the executor, however, I cannot identify which input theexecutor
received to also pass totranslatorChain
. Would there be any way to do this?(I can create a function to do this orchestration, but I would like to know if there is something native)
Beta Was this translation helpful? Give feedback.
All reactions