Skip to content

Commit

Permalink
fix: prompt test
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Mar 29, 2024
1 parent a6df0d2 commit ca78fe5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ CREATE TABLE "ai_prompts" (
"role" "AiPromptRole" NOT NULL,
"content" TEXT NOT NULL,
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "ai_prompts_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "ai_prompts_name_key" ON "ai_prompts"("name");
CREATE UNIQUE INDEX "ai_prompts_name_idx_key" ON "ai_prompts"("name", "idx");
3 changes: 2 additions & 1 deletion packages/backend/server/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ enum AiPromptRole {
model AiPrompt {
id String @id @default(uuid()) @db.VarChar
// prompt name
name String @unique @db.VarChar(20)
name String @db.VarChar(20)
// if a group of prompts contains multiple sentences, idx specifies the order of each sentence
idx Int @db.Integer
// system/assistant/user
Expand All @@ -440,6 +440,7 @@ model AiPrompt {
content String @db.Text
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
@@unique([name, idx])
@@map("ai_prompts")
}

Expand Down
5 changes: 3 additions & 2 deletions packages/backend/server/src/plugins/copilot/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CopilotPromptService {
async list() {
return this.db.aiPrompt
.findMany({ select: { name: true } })
.then(prompts => prompts.map(p => p.name));
.then(prompts => Array.from(new Set(prompts.map(p => p.name))));
}

async get(name: string): Promise<ChatMessage[]> {
Expand All @@ -31,7 +31,8 @@ export class CopilotPromptService {

async set(name: string, messages: ChatMessage[]) {
return this.db.$transaction(async tx => {
if (await tx.aiPrompt.findUnique({ where: { name } })) {
const prompts = await tx.aiPrompt.count({ where: { name } });
if (prompts > 0) {
return 0;
}
return tx.aiPrompt
Expand Down

0 comments on commit ca78fe5

Please sign in to comment.