import { streamText } from 'ai'
import { createOpenAI } from '@ai-sdk/openai'
const openai = createOpenAI({
apiKey: process.env.OPENAI_API_KEY!,
baseURL: 'https://gateway.ai.vercel.com/v1',
headers: {
'X-Vercel-AI-Provider': 'morph',
},
})
export async function POST(req: Request) {
const { editInstructions, originalCode, update } = await req.json()
// Get the morph model through AI Gateway
const model = openai('morph-v3-fast')
// Call the language model with the prompt
const result = streamText({
model,
messages: [
{
role: 'user',
content: `<instruction>${editInstructions}</instruction>\n<code>${originalCode}</code>\n<update>${update}</update>`
}
],
topP: 1,
})
// Respond with a streaming response
return result.toAIStreamResponse()
}