Skip to content

Commit a8041dd

Browse files
committed
refactor: add prompts file
1 parent ceec93f commit a8041dd

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { get } from "@vercel/edge-config";
2+
3+
interface Prompts {
4+
"generate-dataroom-system": string;
5+
"generate-dataroom-user": string;
6+
}
7+
8+
async function getPrompts(): Promise<Prompts> {
9+
if (!process.env.EDGE_CONFIG) {
10+
throw new Error("Edge Config not configured");
11+
}
12+
13+
const prompts = await get<Prompts>("prompts");
14+
15+
if (!prompts) {
16+
throw new Error("Prompts not found in Edge Config");
17+
}
18+
19+
return prompts;
20+
}
21+
22+
export async function getDataroomSystemPrompt(): Promise<string> {
23+
const prompts = await getPrompts();
24+
25+
const prompt = prompts["generate-dataroom-system"];
26+
27+
if (!prompt || typeof prompt !== "string") {
28+
throw new Error("Dataroom system prompt not found in Edge Config");
29+
}
30+
31+
return prompt;
32+
}
33+
34+
export async function getDataroomUserPrompt(
35+
description: string,
36+
): Promise<string> {
37+
const prompts = await getPrompts();
38+
39+
const template = prompts["generate-dataroom-user"];
40+
41+
if (!template || typeof template !== "string") {
42+
throw new Error("Dataroom user prompt not found in Edge Config");
43+
}
44+
45+
return template.replace("{{DESCRIPTION}}", description.trim());
46+
}
47+

pages/api/teams/[teamId]/datarooms/generate-ai-structure.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { NextApiRequest, NextApiResponse } from "next";
22

33
import { getServerSession } from "next-auth/next";
44

5+
import {
6+
getDataroomSystemPrompt,
7+
getDataroomUserPrompt,
8+
} from "@/ee/features/templates/lib/prompts";
59
import { openai } from "@/lib/openai";
610
import prisma from "@/lib/prisma";
711
import { CustomUser } from "@/lib/types";
@@ -55,26 +59,16 @@ export default async function handle(
5559
}
5660

5761
// Use GPT to generate folder structure
58-
const systemPrompt = `Prompt`;
62+
const [systemPrompt, userPrompt] = await Promise.all([
63+
getDataroomSystemPrompt(),
64+
getDataroomUserPrompt(description),
65+
]);
5966

6067
const completion = await openai.chat.completions.create({
6168
model: "gpt-4o-mini",
6269
messages: [
6370
{ role: "system", content: systemPrompt },
64-
{
65-
role: "user",
66-
content: `Analyze this description carefully and create a highly tailored, specific data room folder structure that perfectly matches this exact use case:
67-
68-
"${description.trim()}"
69-
70-
Generate a folder structure that is:
71-
- Specifically designed for this exact scenario
72-
- Includes all relevant document types for this specific transaction/use case
73-
- Uses industry-appropriate naming conventions
74-
- Organized logically for this particular purpose
75-
76-
Also suggest an appropriate, professional name for this data room.`,
77-
},
71+
{ role: "user", content: userPrompt },
7872
],
7973
temperature: 0.7,
8074
max_tokens: 3000,

0 commit comments

Comments
 (0)