init commit,
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# openai
|
||||
|
||||
## Setup env vars
|
||||
|
||||
```bash
|
||||
cp supabase/.env.local.example supabase/.env.local
|
||||
```
|
||||
|
||||
## Run locally
|
||||
|
||||
```bash
|
||||
supabase functions serve --env-file ./supabase/.env.local --no-verify-jwt
|
||||
```
|
||||
|
||||
Use cURL or Postman to make a POST request to http://localhost:54321/functions/v1/openai.
|
||||
|
||||
```bash
|
||||
curl -i --location --request POST http://localhost:54321/functions/v1/openai \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '{"query":"What is Supabase?"}'
|
||||
```
|
||||
|
||||
## Deploy
|
||||
|
||||
```bash
|
||||
supabase functions deploy --no-verify-jwt openai
|
||||
supabase secrets set --env-file ./supabase/.env.local
|
||||
```
|
@@ -0,0 +1,23 @@
|
||||
import 'https://deno.land/x/xhr@0.3.0/mod.ts'
|
||||
import { CreateCompletionRequest } from 'https://esm.sh/openai@3.1.0'
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
const { query } = await req.json()
|
||||
|
||||
const completionConfig: CreateCompletionRequest = {
|
||||
model: 'text-davinci-003',
|
||||
prompt: query,
|
||||
max_tokens: 256,
|
||||
temperature: 0,
|
||||
stream: true,
|
||||
}
|
||||
|
||||
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),
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user