AI da dat ten cho dong song

This commit is contained in:
2024-10-26 11:10:14 +07:00
parent 2b6d3869f9
commit 48305a3948
11 changed files with 2999 additions and 63 deletions

View File

@@ -0,0 +1,23 @@
import { ClientOptions, OpenAI } from 'openai';
import { Module } from '@nestjs/common';
import { OpenaiService } from './openai.service';
const openaiOptions: ClientOptions = {
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_BASE_URL,
maxRetries: parseInt(process.env.OPENAI_MAX_RETRIES as string) ?? 3,
};
@Module({
imports: [OpenAI],
providers: [
{
provide: OpenAI,
useFactory: () => new OpenAI(openaiOptions),
},
OpenaiService,
],
exports: [OpenaiService],
})
export class OpenaiModule {}

View File

@@ -0,0 +1,24 @@
import { Injectable } from '@nestjs/common';
import { OpenAI } from 'openai';
@Injectable()
export class OpenaiService {
constructor(private openai: OpenAI) {}
async generateInvitationMailContent(
mail: string,
username: string,
url: string,
) {
const prompt = `
give me mail content for invitation to a workshop to EPESS and replace {{ mail }} with ${mail}, {{ username }} with ${username} and {{ url }} with ${url}
`;
const response = await this.openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: prompt }],
});
return response.choices[0].message.content;
}
}