Add deno.lock file and refactor AI function to streamline OpenAI integration
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"version": "5",
|
||||
"specifiers": {
|
||||
"jsr:@openai/openai@*": "6.9.0",
|
||||
"jsr:@supabase/functions-js@*": "2.90.1"
|
||||
},
|
||||
"jsr": {
|
||||
"@openai/openai@6.9.0": {
|
||||
"integrity": "d1828101f5a782a75c25805c4e06c1316d9c19f422d84755fb908046184c3ef6"
|
||||
},
|
||||
"@supabase/functions-js@2.90.1": {
|
||||
"integrity": "9a077ecf42aa84594ef3aac621d643e15ffaa9506a4c051e35c93f127ffdb035"
|
||||
}
|
||||
},
|
||||
"workspace": {
|
||||
"packageJson": {
|
||||
"dependencies": [
|
||||
"npm:@supabase/supabase-js@^2.90.1",
|
||||
"npm:@types/bun@latest",
|
||||
"npm:supabase-js@^1.0.4",
|
||||
"npm:supabase@^2.72.6"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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' },
|
||||
})
|
||||
})
|
||||
@@ -16,43 +16,7 @@ try {
|
||||
|
||||
const response = await supabase.functions.invoke("ai-structured", {
|
||||
body: {
|
||||
response: {
|
||||
model: "gpt-5",
|
||||
input: [
|
||||
{ role: "system", content: "Responde SIEMPRE en JSON válido." },
|
||||
{ role: "user", content: "Dame 3 ideas de proyecto de IA para educación." },
|
||||
],
|
||||
/* conversation: "conv_...", */ // opcional
|
||||
},
|
||||
structured: {
|
||||
type: "json_schema",
|
||||
name: "ideas",
|
||||
strict: true,
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
ideas: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
titulo: { type: "string" },
|
||||
descripcion: { type: "string" }
|
||||
},
|
||||
required: ["titulo", "descripcion"],
|
||||
additionalProperties: false
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ["ideas"],
|
||||
additionalProperties: false
|
||||
}
|
||||
},
|
||||
references: {
|
||||
/* vectorStoreIds: ["vs_..."], */ // opcional (file_search) ✅
|
||||
/* openaiFileIds: ["file_..."], */ // opcional (input_file) ✅
|
||||
},
|
||||
usarMCP: false, // opcional ✅
|
||||
query: "Escribe un poema sobre la primavera en español",
|
||||
},
|
||||
});
|
||||
console.log({ d: response.data, e: response.error });
|
||||
|
||||
Reference in New Issue
Block a user