Tracy
Tracy

Reputation: 33

how can i pass the input gotten from user to the tool in langchain

i have this function in langchain

app.post('/new', async (req, res) => {
  const { question } = req.body;
  const formattedPromptValue = await promptTemplate.format({
    userPrompt: question,
  });
  try {
    // loaded agent
    const executor = await initializeAgentExecutorWithOptions(tools, model, {
      agentType: 'chat-conversational-react-description',
      maxIterations: 3,
    });
  
    const result = await executor.call({
      input: formattedPromptValue.toString(),
    });
   console.log('tool result', result);
}

now in my tools i have

export const getProductInfo = new DynamicTool({
  name: 'Get the product info',
  description: `call this to get information about products that are in myapp, 
      The input to this tool is called question which contains products infomation and the the output will be response gotten from pinecone that match the query.
      `,
  func: getProductsDetails,
});

and in the function getProductsDetails i have

export const getProductsDetails = async () => {
    await createPineconeIndex(client, indexName, vectorDimension);
    await updatePinecone(client, indexName, docs);
    const queryResponse = await queryPineconeVectorStoreAndQueryLLM(client, indexName, question);
  
          return queryResponse ;    
      };

now the issue is that the 'question' i am passing here queryPineconeVectorStoreAndQueryLLM(client, indexName, question) is not been passed, as i am getting question is undefined.

please how can i pass the user input('question') to the tool so it can get to the function

Upvotes: 1

Views: 2308

Answers (1)

ZKS
ZKS

Reputation: 2836

Few changes you need to make.

Add question as parameter in you method

       export const getProductsDetails = async (question) => {
            await createPineconeIndex(client, indexName, vectorDimension);
            await updatePinecone(client, indexName, docs);
            const queryResponse = await queryPineconeVectorStoreAndQueryLLM(client, indexName, question);
            return queryResponse;    
        };

Your dynamic tool should have question as input

export const getProductInfo = new DynamicTool({
        name: 'Get the product info',
          description: 'your description',
          func: (inputs) => getProductsDetails(inputs.question),
        });

Make sure your request is having question as an input

Upvotes: 1

Related Questions