@@ -140,26 +140,32 @@ app.listen(8000);`,
140
140
name : 'OpenAI Text Completion' ,
141
141
description : 'Generate text completions using OpenAI GPT-3' ,
142
142
content : `// Setup type definitions for built-in Supabase Runtime APIs
143
- import "jsr:@supabase/functions-js/edge-runtime.d.ts";
144
- import { Configuration, OpenAIApi } from ' npm:openai@3.3.0'
143
+ import "jsr:@supabase/functions-js/edge-runtime.d.ts"
144
+ import { OpenAI } from " npm:openai@4.8.0"
145
145
146
- const openAi = new OpenAIApi(
147
- new Configuration({
148
- apiKey: Deno.env.get('OPENAI_API_KEY')
149
- })
150
- )
146
+ const openai = new OpenAI({
147
+ apiKey: Deno.env.get('OPENAI_API_KEY')
148
+ })
151
149
152
- Deno.serve(async (req) => {
150
+ Deno.serve(async (req)=> {
153
151
const { prompt } = await req.json()
154
- const completion = await openAi.createCompletion({
155
- model: 'text-davinci-003',
156
- prompt,
157
- max_tokens: 200
152
+ const response = await openai.chat.completions.create({
153
+ model: "gpt-3.5-turbo",
154
+ messages: [
155
+ {
156
+ role: "user",
157
+ content: prompt
158
+ }
159
+ ]
160
+ })
161
+ return new Response(JSON.stringify({
162
+ text: response.choices[0].message.content
163
+ }), {
164
+ headers: {
165
+ 'Content-Type': 'application/json',
166
+ 'Connection': 'keep-alive'
167
+ }
158
168
})
159
- return new Response(
160
- JSON.stringify({ text: completion.data.choices[0].text }),
161
- { headers: { 'Content-Type': 'application/json' }}
162
- )
163
169
})` ,
164
170
} ,
165
171
{
0 commit comments