Skip to content

Commit

Permalink
fix UpdateChatTitleInput typo, and add getModelTag
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHallen122 committed Oct 28, 2024
1 parent 1f5066d commit 9c8bc0e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
24 changes: 16 additions & 8 deletions backend/src/chat/chat.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Chat } from './chat.model';
import { Message, Role } from 'src/chat/message.model';
import {
NewChatInput,
UpateChatTitleInput,
UpdateChatTitleInput,
ChatInput,
} from 'src/chat/dto/chat.input';
import { UseGuards } from '@nestjs/common';
Expand Down Expand Up @@ -46,6 +46,19 @@ export class ChatResolver {
}
}

@Query(() => [String], { nullable: true })
async getAvailableModelTags(
@GetUserIdFromToken() userId: string,
): Promise<string[]> {
try {
const response = await this.chatProxyService.fetchModelTags();
return response.models.data.map((model) => model.id); // Adjust based on model structure
} catch (error) {
throw new Error('Failed to fetch model tags');
}
}

// this is not the final api.
@Query(() => [Chat], { nullable: true })
async getUserChats(@GetUserIdFromToken() userId: string): Promise<Chat[]> {
const user = await this.userService.getUserChats(userId);
Expand Down Expand Up @@ -75,11 +88,6 @@ export class ChatResolver {
return this.chatService.getChatDetails(chatId);
}

// @Query(() => [Message])
// getAvailableModelTags(@Args('chatId') chatId: string): Message[] {
// return this.chatService.getChatHistory(chatId);
// }

@Mutation(() => Chat)
async createChat(
@GetUserIdFromToken() userId: string,
Expand All @@ -103,8 +111,8 @@ export class ChatResolver {
@UseGuards(ChatGuard)
@Mutation(() => Chat, { nullable: true })
async updateChatTitle(
@Args('upateChatTitleInput') upateChatTitleInput: UpateChatTitleInput,
@Args('updateChatTitleInput') updateChatTitleInput: UpdateChatTitleInput,
): Promise<Chat> {
return this.chatService.updateChatTitle(upateChatTitleInput);
return this.chatService.updateChatTitle(updateChatTitleInput);
}
}
21 changes: 19 additions & 2 deletions backend/src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Message, Role } from 'src/chat/message.model';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from 'src/user/user.model';
import { NewChatInput, UpateChatTitleInput } from 'src/chat/dto/chat.input';
import { NewChatInput, UpdateChatTitleInput } from 'src/chat/dto/chat.input';

type CustomAsyncIterableIterator<T> = AsyncIterator<T> & {
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
Expand Down Expand Up @@ -122,6 +122,23 @@ export class ChatProxyService {
return iterator;
}

async fetchModelTags(): Promise<any> {
try {
this.logger.debug('Requesting model tags from /tags endpoint.');

// Make a GET request to /tags
const response = await this.httpService
.get('http://localhost:3001/tags', { responseType: 'json' })
.toPromise();

this.logger.debug('Model tags received:', response.data);
return response.data;
} catch (error) {
this.logger.error('Error fetching model tags:', error);
throw new Error('Failed to fetch model tags');
}
}

private isValidChunk(chunk: any): chunk is ChatCompletionChunk {
return (
chunk &&
Expand Down Expand Up @@ -210,7 +227,7 @@ export class ChatService {
}

async updateChatTitle(
upateChatTitleInput: UpateChatTitleInput,
upateChatTitleInput: UpdateChatTitleInput,
): Promise<Chat> {
const chat = await this.chatRepository.findOne({
where: { id: upateChatTitleInput.chatId },
Expand Down
9 changes: 6 additions & 3 deletions backend/src/chat/dto/chat.input.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// DTOs for Project APIs
import { InputType, Field, ID } from '@nestjs/graphql';
import { Message } from 'src/chat/message.model';
import { InputType, Field } from '@nestjs/graphql';

@InputType()
export class NewChatInput {
Expand All @@ -9,7 +8,7 @@ export class NewChatInput {
}

@InputType()
export class UpateChatTitleInput {
export class UpdateChatTitleInput {
@Field()
chatId: string;

Expand All @@ -22,6 +21,10 @@ export class ChatInput {
@Field()
chatId: string;

// more input check in the feature
// @IsString()
// @MinLength(1)
// @MaxLength(2000)
@Field()
message: string;
}

0 comments on commit 9c8bc0e

Please sign in to comment.