From 4d6920d56becd165ab25748b5adab0bd97156eb0 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Sat, 4 Nov 2023 01:46:41 -0400 Subject: [PATCH] started dedpuing logic --- app/page.tsx | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/app/page.tsx b/app/page.tsx index ccf60a4..cfa869b 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -33,6 +33,7 @@ import { } from "@/components/ui/table"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { set } from "date-fns"; const MIN_FEATURES_PER_PROJECT = 6; const MAX_FEATURES_PER_PROJECT = 12; @@ -63,6 +64,14 @@ const openai = new OpenAIChatApi( } ); +type Project = { + name: string; + description: string; + stack: string[]; + features?: Feature[]; + tasks?: Task[]; +}; + type Feature = { name: string; description: string; @@ -95,6 +104,8 @@ export default function Home() { }); const [stackInput, setStackInput] = useState(""); + const [deps, setDeps] = useState([]); + const [project, setProject] = useState(); const [features, setFeatures] = useState([]); const [tasks, setTasks] = useState([]); @@ -103,6 +114,7 @@ export default function Home() { async function onSubmit(values: z.infer) { setFeatures([]); setTasks([]); + setProject(values); try { const feature_gen_prompt = `You are an AI software project manager. You use agile methodology and the best software project management techniques to plan software projects for indie developers. @@ -276,6 +288,18 @@ Instructions: For each feature, we need to figure out what other features need t }); const tasks: Task[][] = await Promise.all(featurePromises); setTasks(tasks.flat()); + + let featuresWithTasks = [...features]; + featuresWithTasks.forEach((feature) => { + feature.tasks = tasks + .flat() + .filter((task) => task.feature === feature.uid); + }); + + setFeatures(featuresWithTasks); + setDeps(_dependencies); + + console.log("featuresWithTasks ", featuresWithTasks); } async function generateTask( @@ -360,6 +384,64 @@ Dependency-Based Order (numeric) } } + async function dedupeTasks() { + try { + features.forEach((feature) => { + console.log("deduping feature ", feature.name); + let _deps = deps + .filter((dep) => dep.uid === feature.uid) + .map((dep) => dep.depUid); + if (_deps.length > 0) { + feature.tasks!.forEach((task) => { + console.log("deduping task ", task.name); + let otherTasks: Task[] = []; + _deps.forEach((dep) => { + otherTasks = [ + ...otherTasks, + ...tasks.filter((t) => t.feature === dep), + ]; + }); + dedupeTask(task, otherTasks); + }); + } + }); + } catch (err) { + console.error(err); + } + } + + async function dedupeTask(targetTask: Task, otherTasks: Task[]) { + try { + const prompt = `You are an AI software project manager. You use agile methodology and the best software project management techniques to plan software projects for indie developers. + +I am an indie developer creating a new software project. Here are the details: +""" +Project Name: ${project?.name} +Project Description: ${project?.description} +Tech Stack: ${project?.stack.join(", ")} +""" +We have generated a list of features which contain a list of tasks to build out those features. We need to dedupe the tasks so that we don't have any duplicate tasks. Check if this task is a duplicate of any other task in the project. If it is, then return the UID of the task that it is a duplicate of. If it is not a duplicate, then return null. + +Task: +""" +Name: ${targetTask.name} +Description: ${targetTask.description} +""" + +Other Tasks: +""" +${otherTasks.map((task) => { + return `Name: ${task.name}, Description: ${task.description}, ID: ${task.uid}.\n`; +})} +""" + `; + + // logic to to actually complete and return a boolean + } catch (err) { + console.error(err); + } + } + const keyHandler = (e: React.KeyboardEvent) => { if ((e.key === "Enter" || e.key === "Tab") && stackInput !== "") { e.preventDefault(); @@ -455,6 +537,7 @@ Dependency-Based Order (numeric) Features Tasks + Duplicates @@ -505,6 +588,9 @@ Dependency-Based Order (numeric) ); })} + + This is where deduping logic will be displayed. + );