Next.js Discord

Discord Forum

LangChainStream OpenAPI Agent troubleshooting

Unanswered
Varied Thrush posted this in #help-forum
Open in Discord
Varied ThrushOP
so my question is probably not vercel / nextjs specific but I figured somebody on here might know 🙂

I am trying to run langchain with openAI + an openapi spec with the vercel AI sdk langchain stream.

The error is basically that input is missing however I am passing in the input so I don't get it.

here is my route /api/chat

import { StreamingTextResponse, LangChainStream, Message } from "ai"; import { ChatOpenAI } from "langchain/chat_models/openai"; import { AIMessage, HumanMessage } from "langchain/schema"; import { createOpenApiAgent, OpenApiToolkit } from "langchain/agents"; import { JsonSpec } from "langchain/tools"; import { currentUser } from "@clerk/nextjs"; export const runtime = "edge"; export async function POST(req: Request) { const { messages } = await req.json(); const user = await currentUser(); const { stream, handlers } = LangChainStream(); const llm = new ChatOpenAI({ streaming: true, modelName: "gpt-3.5-turbo", temperature: 0.4, }); // Load the OpenAPI spec for the Fortnox API const rawFortnoxApiSpec = require("./fortnox.json"); const fortnoxApiSpec = new JsonSpec(rawFortnoxApiSpec); custom RequestsWrapper const fortnoxAgent = new OpenApiToolkit(fortnoxApiSpec, llm, { Authorization:Bearer ${user?.privateMetadata?.fortnoxAccessToken}, }); const executor = createOpenApiAgent(llm, fortnoxAgent); if (Array.isArray(messages) && messages.length > 0) { executor .call( messages.map((m) => m.role == "user" ? new HumanMessage(m.content) : new AIMessage(m.content), ), ) .catch(console.error); } else { console.error("No messages provided"); } return new StreamingTextResponse(stream); }

and the error: [Error: Missing value for input input]

client: https://sdk.vercel.ai/docs/api-reference/use-chat

Thnx

7 Replies

im not sure exactly what ur doing, but this might help
https://github.com/tfutada/zenn-vercel-ai-sdk/blob/main/app/chat/page.tsx
Varied ThrushOP
thnx mate, will check! I am basically creating a chat application that uses both Vercel AI SDK and LangChain's OpenAIChat(opens in a new tab) together with Next.js. I am adding an OpenAPI spec file and I want to from the chat send the input to langchain / open ai so it can do api calls to my openapi endpoint and return the data etc
unluckily i did not implement LangChain version. you will find huggingface
version in my repo. it works without OpenAI API so it would be better for practice.
client side, useChat, works regardless of back end impl
Varied ThrushOP
got it! thnx

yes the Client side works.

I'm encountering an issue when calling the executor.call() function. The error message I'm getting is [Error: Missing value for input input].

Here's the relevant part of my code:


executor .call( messages.map((m) => m.role == "user" ? new HumanMessage(m.content) : new AIMessage(m.content), ), ) .catch(console.error);

will check the repo thnx
could be a bug. u might wanna check Vercel SDK git repo, check the sdk version.
Varied ThrushOP
alright might be, I'll ask on their git! thnx