Add deno.lock file and refactor AI function to streamline OpenAI integration

This commit is contained in:
2026-01-13 11:10:41 -06:00
parent f037e31896
commit 411e0f2154
3 changed files with 44 additions and 54 deletions
+18 -17
View File
@@ -1,22 +1,23 @@
// Setup type definitions for built-in Supabase Runtime APIs
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { load } from "jsr:@std/dotenv";
import OpenAI from 'jsr:@openai/openai';
interface reqPayload {
name: string;
}
console.info('server started');
Deno.serve(async (req) => {
const apiKey = Deno.env.get('OPENAI_API_KEY')
const openai = new OpenAI({
apiKey: apiKey,
})
Deno.serve(async (req: Request) => {
// Documentation here: https://github.com/openai/openai-node
const response = await openai.responses.create({
model: 'gpt-5-nano',
instructions: 'You are a coding assistant that talks like a pirate',
input: 'Are semicolons optional in JavaScript?',
});
const reply = response.output_text
const { name }: reqPayload = await req.json();
const data = {
message: Deno.env.toObject(),
};
return new Response(
JSON.stringify(data),
{ headers: { 'Content-Type': 'application/json', 'Connection': 'keep-alive' }}
);
});
return new Response(reply, {
headers: { 'Content-Type': 'text/plain' },
})
})