Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
sonuku092 committed Mar 15, 2024
1 parent 0dfe45a commit a887a55
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
9 changes: 0 additions & 9 deletions backend/src/chats/chats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@

import { Controller, Post, Body } from '@nestjs/common';
import { ChatsService } from './chats.service';
import { UserMessageDto } from '../shared/dto/user-message.dto';
import { OpenaiService } from '../shared/services/openai.service';

@Controller('chats')
export class ChatsController {
constructor(
private readonly chatsService: ChatsService,
private readonly openaiService: OpenaiService,
) {}

@Post()
async handleUserMessage(@Body() userMessageDto: UserMessageDto): Promise<string> {
const response = await this.openaiService.getResponse(userMessageDto.message);
return response;
}
}
5 changes: 2 additions & 3 deletions backend/src/chats/chats.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import { Module } from '@nestjs/common';
import { ChatsController } from './chats.controller';
import { ChatsService } from './chats.service';
import { OpenaiService } from '../shared/services/openai.service'; // Import OpenaiService
import { ChatGateway } from './chats.gateway';
import { UsersModule } from 'src/users/users.module';

@Module({
imports: [UsersModule],
controllers: [ChatsController],
providers: [ChatsService, OpenaiService, ChatGateway], // Add OpenaiService to providers
exports: [ChatsService, OpenaiService], // Add OpenaiService to exports
providers: [ChatsService, ChatGateway], // Add OpenaiService to providers
exports: [ChatsService], // Add OpenaiService to exports
})
export class ChatsModule {}
12 changes: 3 additions & 9 deletions backend/src/chats/chats.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Injectable } from '@nestjs/common';
import { OpenaiService } from '../shared/services/openai.service';

@Injectable()
export class ChatsService {
constructor(private readonly openAIService: OpenaiService) {}

async handleUserMessage(userMessage: string): Promise<void | string> {
// Here you can implement your logic to fetch responses for fixed questions

const response = await this.openAIService.getResponse(userMessage);
return response;
}
getHello(): string {
return 'Hello World!';
}
}

0 comments on commit a887a55

Please sign in to comment.