inicio de funcion de generación de asignatura
This commit is contained in:
@@ -26,3 +26,14 @@ entrypoint = "./functions/create-chat-conversation/index.ts"
|
||||
# Specifies static files to be bundled with the function. Supports glob patterns.
|
||||
# For example, if you want to serve static HTML pages in your function:
|
||||
# static_files = [ "./functions/create-chat-conversation/*.html" ]
|
||||
|
||||
[functions.ai-generate-subject]
|
||||
enabled = true
|
||||
verify_jwt = true
|
||||
import_map = "./functions/ai-generate-subject/deno.json"
|
||||
# Uncomment to specify a custom file path to the entrypoint.
|
||||
# Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx
|
||||
entrypoint = "./functions/ai-generate-subject/index.ts"
|
||||
# Specifies static files to be bundled with the function. Supports glob patterns.
|
||||
# For example, if you want to serve static HTML pages in your function:
|
||||
# static_files = [ "./functions/ai-generate-subject/*.html" ]
|
||||
|
||||
@@ -91,6 +91,30 @@ export class OpenAIService {
|
||||
const uploadedToStorage = await this.uploadFilesToStorage(files ?? []);
|
||||
const openaiFileIds = await this.uploadFilesToOpenAI(files ?? []);
|
||||
|
||||
const newOptions = { ...options };
|
||||
|
||||
// Attach file references to the request as an extra user message
|
||||
if (openaiFileIds.length > 0) {
|
||||
const fileParts: OpenAITypes.OpenAI.Responses.ResponseInputFile[] =
|
||||
openaiFileIds.map((id) => ({
|
||||
type: "input_file",
|
||||
file_id: id,
|
||||
}));
|
||||
|
||||
const arr = Array.isArray(options.input) ? options.input : [];
|
||||
arr.push({
|
||||
role: "user",
|
||||
content: [
|
||||
...fileParts,
|
||||
{
|
||||
type: "input_text",
|
||||
text: "Usa estos archivos como referencia",
|
||||
},
|
||||
],
|
||||
});
|
||||
newOptions.input = arr;
|
||||
}
|
||||
|
||||
// Narrow to non-streaming response
|
||||
const openaiRaw = (await this.openai.responses.create(
|
||||
newOptions as OpenAITypes.OpenAI.Responses.ResponseCreateParamsNonStreaming,
|
||||
@@ -98,12 +122,11 @@ export class OpenAIService {
|
||||
|
||||
const { model, id: responseId } = openaiRaw;
|
||||
const usage = openaiRaw?.usage ?? null;
|
||||
const conversationId =
|
||||
(
|
||||
openaiRaw as OpenAITypes.OpenAI.Responses.Response & {
|
||||
conversation_id?: string | null;
|
||||
}
|
||||
).conversation_id ?? null;
|
||||
const conversationId = (
|
||||
openaiRaw as OpenAITypes.OpenAI.Responses.Response & {
|
||||
conversation_id?: string | null;
|
||||
}
|
||||
).conversation_id ?? null;
|
||||
|
||||
// Try to read structured JSON output
|
||||
let output: TOutput | undefined = undefined;
|
||||
@@ -148,8 +171,8 @@ export class OpenAIService {
|
||||
const code = message.includes("Supabase upload failed")
|
||||
? "StorageUploadFailed"
|
||||
: message.includes("OpenAI file upload failed")
|
||||
? "OpenAIFileUploadFailed"
|
||||
: "OpenAIRequestFailed";
|
||||
? "OpenAIFileUploadFailed"
|
||||
: "OpenAIRequestFailed";
|
||||
|
||||
return { ok: false, code, message, cause: err };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Configuration for private npm package dependencies
|
||||
# For more information on using private registries with Edge Functions, see:
|
||||
# https://supabase.com/docs/guides/functions/import-maps#importing-from-private-registries
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"imports": {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
|
||||
import { corsHeaders } from "../_shared/cors.ts";
|
||||
|
||||
console.log("Hello from Functions!");
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
const url = new URL(req.url);
|
||||
const functionName = url.pathname.split("/").pop();
|
||||
console.log(
|
||||
`[${new Date().toISOString()}][${functionName}]: Request received`,
|
||||
);
|
||||
|
||||
if (req.method === "OPTIONS") {
|
||||
return new Response(null, { status: 204, headers: corsHeaders });
|
||||
}
|
||||
const { name } = await req.json();
|
||||
const data = {
|
||||
message: `Hello ${name}!`,
|
||||
};
|
||||
|
||||
return new Response(
|
||||
JSON.stringify(data),
|
||||
{ headers: { "Content-Type": "application/json" } },
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user