mirror of
https://github.com/SkalaraAI/skbeta.git
synced 2025-04-09 15:00:18 -04:00
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs";
|
|
import { cookies } from "next/headers";
|
|
import { NextResponse, NextRequest } from "next/server";
|
|
import { Database } from "@/types/supabase";
|
|
import prisma from "@/lib/prisma";
|
|
import { generateFeatures } from "@/lib/prompts";
|
|
import openai from "@/lib/openai";
|
|
import { randomUUID } from "crypto";
|
|
|
|
import { completion } from "zod-gpt";
|
|
import * as z from "zod";
|
|
|
|
const MIN_FEATURES_PER_PROJECT = 6;
|
|
const MAX_FEATURES_PER_PROJECT = 12;
|
|
|
|
async function getSession(supabase: any) {
|
|
const {
|
|
data: { session },
|
|
} = await supabase.auth.getSession();
|
|
return session;
|
|
}
|
|
|
|
// generate features for project
|
|
export async function POST(req: NextRequest) {
|
|
const supabase = createRouteHandlerClient<Database>({ cookies });
|
|
const session = await getSession(supabase);
|
|
|
|
if (!session) return NextResponse.redirect("/auth");
|
|
|
|
try {
|
|
// TODO: generate features for project
|
|
const req_data = await req.json();
|
|
const project_name = String(req_data.project_name);
|
|
const project_description = String(req_data.project_description);
|
|
const project_stack = req_data.project_stack;
|
|
const qa = req_data.qa;
|
|
|
|
console.log(project_name, project_description, project_stack, qa);
|
|
|
|
const feature_gen_prompt = generateFeatures(
|
|
project_name,
|
|
project_description,
|
|
project_stack,
|
|
qa
|
|
);
|
|
|
|
const res = await completion(openai, feature_gen_prompt, {
|
|
schema: z.object({
|
|
features: z
|
|
.array(
|
|
z.object({
|
|
name: z.string().describe("The name of the feature"),
|
|
description: z
|
|
.string()
|
|
.describe("The description of the feature"),
|
|
})
|
|
)
|
|
.min(MIN_FEATURES_PER_PROJECT)
|
|
.max(MAX_FEATURES_PER_PROJECT),
|
|
}),
|
|
});
|
|
|
|
const features = res.data.features.map((feature) => ({
|
|
...feature,
|
|
uid: String(randomUUID()),
|
|
project_id: String(req_data.project_id),
|
|
}));
|
|
|
|
console.log(features);
|
|
|
|
return NextResponse.json({ features }, { status: 200 });
|
|
} catch (err) {
|
|
console.error(err);
|
|
return NextResponse.json({ error: err }, { status: 500 });
|
|
}
|
|
}
|