The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
openai.mdx updated deno function to use latest openai package (#19956)
Karim Attiaa63d4d3c915d
diff --git a/apps/docs/pages/guides/ai/examples/openai.mdx b/apps/docs/pages/guides/ai/examples/openai.mdxindex 820295bad4a..7bf0c3b07ae 100644--- a/apps/docs/pages/guides/ai/examples/openai.mdx+++ b/apps/docs/pages/guides/ai/examples/openai.mdx@@ -34,27 +34,27 @@ A new edge function will now exist under `./supabase/functions/openai/index.ts`.We'll design the function to take your user's query (via POST request) and forward it to OpenAI's API.```ts index.ts-import { CreateCompletionRequest } from 'https://esm.sh/[email protected]'-import 'https://deno.land/x/[email protected]/mod.ts'+import OpenAI from 'https://deno.land/x/[email protected]/mod.ts'Deno.serve(async (req) => {- const { query } = await req.json()+ const query = await req.json()+ const apiKey = Deno.env.get('OPENAI_API_KEY')+ const openai = new OpenAI({+ apiKey: apiKey,+ })- const completionConfig: CreateCompletionRequest = {- model: 'gpt-3.5-turbo-instruct',- prompt: query,- max_tokens: 256,- temperature: 0,+ // 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: false,- }-- return fetch('https://api.openai.com/v1/completions', {- method: 'POST',- headers: {- Authorization: `Bearer ${Deno.env.get('OPENAI_API_KEY')}`,- 'Content-Type': 'application/json',- },- body: JSON.stringify(completionConfig),+ })++ const reply = chatCompletion.choices[0].message.content++ return new Response(reply, {+ headers: { 'Content-Type': 'text/plain' },})})```