Skip to content

Commit

Permalink
refactor: Update message model and resolver to use MessageRole enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Sma1lboy committed Oct 29, 2024
1 parent bc6ee4b commit 3e429b4
Show file tree
Hide file tree
Showing 3 changed files with 8,376 additions and 6,676 deletions.
6 changes: 3 additions & 3 deletions backend/src/chat/chat.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChatCompletionChunk } from './chat.model';
import { ChatProxyService, ChatService } from './chat.service';
import { UserService } from 'src/user/user.service';
import { Chat } from './chat.model';
import { Message, Role } from 'src/chat/message.model';
import { Message, MessageRole } from 'src/chat/message.model';
import {
NewChatInput,
UpdateChatTitleInput,
Expand Down Expand Up @@ -33,7 +33,7 @@ export class ChatResolver {
})
async *chatStream(@Args('input') input: ChatInput) {
const iterator = this.chatProxyService.streamChat(input.message);
this.chatService.saveMessage(input.chatId, input.message, Role.User);
this.chatService.saveMessage(input.chatId, input.message, MessageRole.User);

let accumulatedContent = ''; // Accumulator for all chunks

Expand All @@ -49,7 +49,7 @@ export class ChatResolver {
await this.chatService.saveMessage(
input.chatId,
accumulatedContent,
Role.Model,
MessageRole.Model,
);
} catch (error) {
console.error('Error in chatStream:', error);
Expand Down
8 changes: 4 additions & 4 deletions backend/src/chat/message.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
import { Chat } from 'src/chat/chat.model';
import { SystemBaseModel } from 'src/system-base-model/system-base.model';

export enum Role {
export enum MessageRole {
User = 'User',
Model = 'Model',
}

registerEnumType(Role, {
registerEnumType(MessageRole, {
name: 'Role',
});

Expand All @@ -36,9 +36,9 @@ export class Message extends SystemBaseModel {
@Column()
content: string;

@Field(() => Role)
@Field(() => MessageRole)
@Column({ type: 'text' })
role: Role;
role: MessageRole;

@Field({ nullable: true })
@Column({ nullable: true })
Expand Down
Loading

0 comments on commit 3e429b4

Please sign in to comment.