Skip to content

Commit

Permalink
fix: database schema
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Apr 10, 2024
1 parent af15106 commit 391185f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE "ai_prompts_messages" (
"idx" INTEGER NOT NULL,
"role" "AiPromptRole" NOT NULL,
"content" TEXT NOT NULL,
"attachments" JSON,
"params" JSON,
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
Expand All @@ -47,6 +48,8 @@ CREATE TABLE "ai_sessions_messages" (
"session_id" VARCHAR(36) NOT NULL,
"role" "AiPromptRole" NOT NULL,
"content" TEXT NOT NULL,
"attachments" JSON,
"params" JSON,
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL,

Expand Down
27 changes: 15 additions & 12 deletions packages/backend/server/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,16 @@ enum AiPromptRole {
}

model AiPromptMessage {
promptId Int @map("prompt_id") @db.Integer
promptId Int @map("prompt_id") @db.Integer
// if a group of prompts contains multiple sentences, idx specifies the order of each sentence
idx Int @db.Integer
idx Int @db.Integer
// system/assistant/user
role AiPromptRole
role AiPromptRole
// prompt content
content String @db.Text
params Json? @db.Json
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
content String @db.Text
attachments Json? @db.Json
params Json? @db.Json
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
prompt AiPrompt @relation(fields: [promptId], references: [id], onDelete: Cascade)
Expand All @@ -462,12 +463,14 @@ model AiPrompt {
}

model AiSessionMessage {
id String @id @default(uuid()) @db.VarChar(36)
sessionId String @map("session_id") @db.VarChar(36)
role AiPromptRole
content String @db.Text
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
id String @id @default(uuid()) @db.VarChar(36)
sessionId String @map("session_id") @db.VarChar(36)
role AiPromptRole
content String @db.Text
attachments Json? @db.Json
params Json? @db.Json
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
session AiSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/server/src/plugins/copilot/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Public } from '../../core/auth';
import { CurrentUser } from '../../core/auth/current-user';
import { ProviderService } from './providers';
import { ChatSession, ChatSessionService } from './session';
import { CopilotCapability } from './types';
import { CopilotCapability, CopilotProviderType } from './types';

export interface ChatEvent {
type: 'attachment' | 'message';
Expand Down Expand Up @@ -180,7 +180,8 @@ export class CopilotController {
@Query() params: Record<string, string>
): Promise<Observable<ChatEvent>> {
const provider = this.provider.getProviderByCapability(
CopilotCapability.TextToImage
CopilotCapability.ImageToImage,
CopilotProviderType.FAL
);
if (!provider) {
throw new InternalServerErrorException('No provider available');
Expand Down
10 changes: 7 additions & 3 deletions packages/backend/server/src/plugins/copilot/providers/fal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export type FalConfig = {
apiKey: string;
};

export type FalResponse = {
images: Array<{ url: string }>;
};

export class FalProvider implements CopilotImageToImageProvider {
static readonly type = CopilotProviderType.FAL;
static readonly capabilities = [CopilotCapability.ImageToImage];
Expand Down Expand Up @@ -53,7 +57,7 @@ export class FalProvider implements CopilotImageToImageProvider {
throw new Error('Attachments is required');
}

const data = await fetch(`https://${model}.gateway.alpha.fal.ai/`, {
const data = (await fetch(`https://${model}.gateway.alpha.fal.ai/`, {
method: 'POST',
headers: {
Authorization: `key ${this.config.apiKey}`,
Expand All @@ -67,9 +71,9 @@ export class FalProvider implements CopilotImageToImageProvider {
enable_safety_checks: false,
}),
signal: options.signal,
}).then(res => res.json());
}).then(res => res.json())) as FalResponse;

return data.images[0].url;
return data.images.map(image => image.url);
}

async *generateImagesStream(
Expand Down

0 comments on commit 391185f

Please sign in to comment.