Your application supports integration with OpenAI's GPT models, enabling advanced conversational AI features. Follow the steps below to set up and integrate OpenAI into your application using Angular and NestJS.
// other imports// import { OpenAIModule } from './openai/openai.module'; // Uncomment this line to enable the OpenAI module@Module({ imports: [ // other imports // OpenAIModule, // Uncomment this line to enable the OpenAI module ],})export class AppModule {}
Locate the line:
// import { OpenAIModule } from './openai/openai.module';
The OpenAIService handles communication with the OpenAI API and is already set up for generating responses. You can customize the logic in openai.service.ts if needed.
Example usage of OpenAIService:
import { Injectable } from '@nestjs/common';import { OpenAIService } from './openai.service';@Injectable()export class MyCustomService { constructor(private readonly openAIService: OpenAIService) {} async askChatGPT(prompt: string): Promise<string> { return this.openAIService.generateResponse(prompt); }}
You’re all set! OpenAI is now integrated into your application. Make sure the appropriate modules are enabled, and the API key is correctly configured.