-
Notifications
You must be signed in to change notification settings - Fork 382
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
'StreamingTextResponse' is deprecated. What is another approach to return streaming response? #56
Comments
I am facing the same issue as well. I have been trying to integrate streaming response with ai-sdk in the client side , would appreciate some resolution. |
U can refer to this article for alternative https://sdk.vercel.ai/docs/reference/stream-helpers/streaming-text-response |
This is not helping at all |
Remove the import { PromptTemplate } from '@langchain/core/prompts'
import { ChatOpenAI } from '@langchain/openai'
import { LangChainAdapter, type Message } from 'ai'
import { NextResponse, type NextRequest } from 'next/server'
export const runtime = 'edge'
const formatMessage = (message: Message) => {
return `${message.role}: ${message.content}`
}
const TEMPLATE = `You are a pirate named Patchy. All responses must be extremely verbose and in pirate dialect.
Current conversation:
{chat_history}
User: {input}
AI:`
export async function POST(req: NextRequest) {
try {
const body = await req.json()
const messages = body.messages ?? []
const formattedPreviousMessages = messages.slice(0, -1).map(formatMessage)
const currentMessageContent = messages[messages.length - 1].content
const prompt = PromptTemplate.fromTemplate(TEMPLATE)
const model = new ChatOpenAI({
temperature: 0.8,
model: 'gpt-4o-mini',
})
const chain = prompt.pipe(model)
const stream = await chain.stream({
chat_history: formattedPreviousMessages.join('\n'),
input: currentMessageContent,
})
return LangChainAdapter.toDataStreamResponse(stream)
} catch (e) {
console.log(e)
return NextResponse.json({ error: 'An error occurred' }, { status: 500 })
}
} |
'StreamingTextResponse' is deprecated. What is another approach to return streaming response?
The text was updated successfully, but these errors were encountered: