Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: add prompts file
Marc Seitza8041dd1ded8
diff --git a/ee/features/templates/lib/prompts.ts b/ee/features/templates/lib/prompts.tsnew file mode 100644index 00000000..ffe9e66e--- /dev/null+++ b/ee/features/templates/lib/prompts.ts@@ -0,0 +1,47 @@+import { get } from "@vercel/edge-config";++interface Prompts {+ "generate-dataroom-system": string;+ "generate-dataroom-user": string;+}++async function getPrompts(): Promise<Prompts> {+ if (!process.env.EDGE_CONFIG) {+ throw new Error("Edge Config not configured");+ }++ const prompts = await get<Prompts>("prompts");++ if (!prompts) {+ throw new Error("Prompts not found in Edge Config");+ }++ return prompts;+}++export async function getDataroomSystemPrompt(): Promise<string> {+ const prompts = await getPrompts();++ const prompt = prompts["generate-dataroom-system"];++ if (!prompt || typeof prompt !== "string") {+ throw new Error("Dataroom system prompt not found in Edge Config");+ }++ return prompt;+}++export async function getDataroomUserPrompt(+ description: string,+): Promise<string> {+ const prompts = await getPrompts();++ const template = prompts["generate-dataroom-user"];++ if (!template || typeof template !== "string") {+ throw new Error("Dataroom user prompt not found in Edge Config");+ }++ return template.replace("{{DESCRIPTION}}", description.trim());+}+diff --git a/pages/api/teams/[teamId]/datarooms/generate-ai-structure.ts b/pages/api/teams/[teamId]/datarooms/generate-ai-structure.tsindex 60aaf884..81ead8ee 100644--- a/pages/api/teams/[teamId]/datarooms/generate-ai-structure.ts+++ b/pages/api/teams/[teamId]/datarooms/generate-ai-structure.ts@@ -2,6 +2,10 @@ import type { NextApiRequest, NextApiResponse } from "next";import { getServerSession } from "next-auth/next";+import {+ getDataroomSystemPrompt,+ getDataroomUserPrompt,+} from "@/ee/features/templates/lib/prompts";import { openai } from "@/lib/openai";import prisma from "@/lib/prisma";import { CustomUser } from "@/lib/types";@@ -55,26 +59,16 @@ export default async function handle(}// Use GPT to generate folder structure- const systemPrompt = `Prompt`;+ const [systemPrompt, userPrompt] = await Promise.all([+ getDataroomSystemPrompt(),+ getDataroomUserPrompt(description),+ ]);const completion = await openai.chat.completions.create({model: "gpt-4o-mini",messages: [{ role: "system", content: systemPrompt },- {- role: "user",- content: `Analyze this description carefully and create a highly tailored, specific data room folder structure that perfectly matches this exact use case:--"${description.trim()}"--Generate a folder structure that is:-- Specifically designed for this exact scenario-- Includes all relevant document types for this specific transaction/use case-- Uses industry-appropriate naming conventions-- Organized logically for this particular purpose--Also suggest an appropriate, professional name for this data room.`,- },+ { role: "user", content: userPrompt },],temperature: 0.7,max_tokens: 3000,