Skip to content

Commit

Permalink
feat: add flavor for session
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Apr 2, 2024
1 parent 499df4c commit c11d872
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
-- CreateTable
CREATE TABLE "ai_sessions" (
"id" VARCHAR NOT NULL,
"id" VARCHAR(36) NOT NULL,
"user_id" VARCHAR NOT NULL,
"workspace_id" VARCHAR NOT NULL,
"doc_id" VARCHAR NOT NULL,
"prompt_name" VARCHAR NOT NULL,
"action" BOOLEAN NOT NULL,
"flavor" VARCHAR NOT NULL,
"model" VARCHAR NOT NULL,
"messages" JSON NOT NULL,
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/server/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ model AiSession {
docId String @map("doc_id") @db.VarChar
promptName String @map("prompt_name") @db.VarChar
action Boolean @db.Boolean
// an mark identifying which view to use to display the session
// it is only used in the frontend and does not affect the backend
flavor String @db.VarChar
model String @db.VarChar
messages Json @db.Json
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
Expand Down
33 changes: 25 additions & 8 deletions packages/backend/server/src/plugins/copilot/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ import {

registerEnumType(AvailableModels, { name: 'CopilotModel' });

@ObjectType('Copilot')
export class CopilotType {
@Field(() => ID)
workspaceId!: string;
}
// ================== Input Types ==================

@InputType()
class CreateChatSessionInput {
Expand All @@ -47,13 +43,24 @@ class CreateChatSessionInput {
@Field(() => String)
docId!: string;

@Field(() => Boolean)
@Field(() => Boolean, {
description: 'Whether the session is for action',
})
action!: boolean;

@Field(() => String)
@Field(() => String, {
description: 'An mark identifying which view to use to display the session',
})
flavor!: string;

@Field(() => String, {
description: 'The model to use for the session',
})
model!: AvailableModel;

@Field(() => String)
@Field(() => String, {
description: 'The prompt name to use for the session',
})
promptName!: string;
}

Expand All @@ -72,6 +79,8 @@ class QueryChatHistoriesInput implements Partial<ListHistoriesOptions> {
sessionId: string | undefined;
}

// ================== Return Types ==================

@ObjectType('ChatMessage')
class ChatMessageType implements Partial<ChatMessage> {
@Field(() => String)
Expand Down Expand Up @@ -108,6 +117,14 @@ class CopilotQuotaType {
used!: number;
}

// ================== Resolver ==================

@ObjectType('Copilot')
export class CopilotType {
@Field(() => ID)
workspaceId!: string;
}

@Resolver(() => CopilotType)
export class CopilotResolver {
constructor(
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/server/src/plugins/copilot/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ChatSessionOptions {
promptName: string;
// options
action: boolean;
flavor: string;
model: AvailableModel;
}

Expand Down Expand Up @@ -148,6 +149,7 @@ export class ChatSessionService {
create: {
id: state.sessionId,
action: state.action,
flavor: state.flavor,
model: state.model,
messages: state.messages,
// connect
Expand Down Expand Up @@ -189,6 +191,7 @@ export class ChatSessionService {
docId: session.docId,
promptName: session.promptName,
action: session.action,
flavor: session.flavor,
model: session.model as AvailableModel,
prompt: await this.prompt.get(session.promptName),
messages: messages.success ? messages.data : [],
Expand Down
11 changes: 11 additions & 0 deletions packages/backend/server/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ type CopilotQuota {
}

input CreateChatSessionInput {
"""Whether the session is for action"""
action: Boolean!
docId: String!

"""An mark identifying which view to use to display the session"""
flavor: String!

"""The model to use for the session"""
model: String!

"""The prompt name to use for the session"""
promptName: String!
workspaceId: String!
}
Expand Down Expand Up @@ -300,6 +308,9 @@ type ServerConfigType {
"""credentials requirement"""
credentialsRequirement: CredentialsRequirementType!

"""enable telemetry"""
enableTelemetry: Boolean!

"""enabled server features"""
features: [ServerFeature!]!

Expand Down

0 comments on commit c11d872

Please sign in to comment.