mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 22:59:11 +03:00
30 lines
771 B
TypeScript
30 lines
771 B
TypeScript
const generateFunctionCode = async (prompt: string) => {
|
|
const code = `
|
|
import OpenAI from 'https://deno.land/x/openai@v4.24.0/mod.ts'
|
|
|
|
Deno.serve(async (req) => {
|
|
const { query } = await req.json()
|
|
const apiKey = Deno.env.get('OPENAI_API_KEY')
|
|
const openai = new OpenAI({
|
|
apiKey: apiKey,
|
|
})
|
|
|
|
// Documentation here: https://github.com/openai/openai-node
|
|
const chatCompletion = await openai.chat.completions.create({
|
|
messages: [{ role: 'user', content: query }],
|
|
// Choose model from here: https://platform.openai.com/docs/models
|
|
model: 'gpt-3.5-turbo',
|
|
stream: true,
|
|
})
|
|
|
|
const reply = chatCompletion.choices[0].message.content
|
|
|
|
return new Response(reply, {
|
|
headers: { 'Content-Type': 'text/plain' },
|
|
})
|
|
})
|
|
`
|
|
|
|
return code
|
|
}
|