langchain-ai / langchain

šŸ¦œšŸ”— Build context-aware reasoning applications
https://python.langchain.com
MIT License
91.37k stars 14.53k forks source link

RunnablePassthrough().pick() not working as expected #21942

Closed LeoAnt02 closed 3 months ago

LeoAnt02 commented 3 months ago

Checked other resources

Example Code

const chain = RunnableSequence.from([
        {
          context: retriever.pipe(formatDocumentsAsString),
          input: new RunnablePassthrough().pick("input"),
        },
        generalPrompt,
        ollama,
        new StringOutputParser(),
      ]);

const stream = await chain.stream({ input: lastUserMessage, chat_history: history });

Error Message and Stack Trace (if applicable)

Failed to process the request text.replace is not a function { "stack": "TypeError: text.replace is not a function\n at OpenAIEmbeddings.embedQuery

Description

I want to select a specific input from my .invoke or .stream in the RunnableSequence

as if I did

const chain = RunnableSequence.from([
        {
          context: retriever.pipe(formatDocumentsAsString),
          input: new RunnablePassthrough(),
        },
        generalPrompt,
        ollama,
        new StringOutputParser(),
      ]);

const stream = await chain.stream({ input: lastUserMessage, chat_history: history });

System Info

typescript, "langchain": "^0.1.37",

LeoAnt02 commented 3 months ago

Seems like the solution is this

new RunnablePassthrough().pick(["input"])

takes an array of string instead of a direct string