nestjs-chatgpt
Advanced tools
Comparing version 1.0.2 to 1.0.3
import { CreateChatgptDto } from './dto/create-chatgpt.dto'; | ||
import { ChatGptResponse } from './dto/response-chatgpt.dto'; | ||
export declare class ChatGptService { | ||
generateText({ prompt, apiKey }: CreateChatgptDto): Promise<string>; | ||
generateTextGPT3({ prompt, apiKey }: CreateChatgptDto): Promise<ChatGptResponse>; | ||
generateText({ prompt, model, apiKey }: CreateChatgptDto): Promise<ChatGptResponse>; | ||
} | ||
//# sourceMappingURL=chatgpt.service.d.ts.map |
@@ -16,8 +16,11 @@ "use strict"; | ||
let ChatGptService = class ChatGptService { | ||
async generateText({ prompt, apiKey }) { | ||
console.log(prompt); | ||
async generateTextGPT3({ prompt, apiKey }) { | ||
return this.generateText({ prompt, model: 'text-davinci-003', apiKey }); | ||
} | ||
; | ||
async generateText({ prompt, model, apiKey }) { | ||
try { | ||
const response = await axios_1.default.post('https://api.openai.com/v1/completions', { | ||
model: 'text-davinci-003', | ||
prompt: prompt, | ||
model, | ||
prompt, | ||
temperature: 1, | ||
@@ -31,3 +34,3 @@ max_tokens: 100, | ||
}); | ||
return response.data.choices[0].text; | ||
return response.data; | ||
} | ||
@@ -34,0 +37,0 @@ catch (error) { |
export declare class CreateChatgptDto { | ||
prompt: string; | ||
model?: string; | ||
apiKey: string; | ||
} | ||
//# sourceMappingURL=create-chatgpt.dto.d.ts.map |
{ | ||
"name": "nestjs-chatgpt", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"homepage": "https://github.com/engcfraposo/nestjs-chatgpt", | ||
@@ -30,7 +30,3 @@ "email": "engcfraposo@gmail.com", | ||
"typescript": "^4.9.4" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/engcfraposo/-nestjs-chatgpt.git" | ||
} | ||
} |
@@ -37,2 +37,16 @@ ## ChatGptService | ||
const createChatgptDto: CreateChatgptDto = { prompt, apiKey }; | ||
return this.chatGptService.generateTextGPT3(createChatgptDto); | ||
} | ||
} | ||
``` | ||
```ts | ||
@Injectable() | ||
export class MyController { | ||
constructor(private readonly chatGptService: ChatGptService) {} | ||
async generateText(prompt: string, model: string, apiKey: string): Promise<string> { | ||
const createChatgptDto: CreateChatgptDto = { prompt, model, apiKey }; | ||
return this.chatGptService.generateText(createChatgptDto); | ||
@@ -48,6 +62,12 @@ } | ||
```ts | ||
@Injectable() | ||
const generatedTextGPT3 = await this.generateTextGPT3('What is the meaning of life?', 'my-api-key'); | ||
console.log(generatedText); | ||
``` | ||
```ts | ||
@Injectable() | ||
const generatedText = await this.generateText('What is the meaning of life?', 'my-api-key'); | ||
const generatedTextGPT3 = await this.generateText('What is the meaning of life?', 'text-davinci-003','my-api-key'); | ||
console.log(generatedText); | ||
@@ -54,0 +74,0 @@ |
@@ -8,4 +8,6 @@ import { HttpException, Injectable } from '@nestjs/common'; | ||
export class ChatGptService { | ||
async generateText({ prompt, apiKey }: CreateChatgptDto): Promise<string> { | ||
console.log(prompt) | ||
async generateTextGPT3({ prompt, apiKey }: CreateChatgptDto) { | ||
return this.generateText({ prompt, model:'text-davinci-003', apiKey }) | ||
}; | ||
async generateText({ prompt, model, apiKey }: CreateChatgptDto) { | ||
try { | ||
@@ -15,4 +17,4 @@ const response = await axios.post<ChatGptResponse>( | ||
{ | ||
model: 'text-davinci-003', | ||
prompt: prompt, | ||
model, | ||
prompt, | ||
temperature: 1, | ||
@@ -28,3 +30,3 @@ max_tokens: 100, | ||
); | ||
return response.data.choices[0].text; | ||
return response.data; | ||
} catch (error) { | ||
@@ -31,0 +33,0 @@ throw new HttpException('Falha ao gerar texto', error.response.status); |
export class CreateChatgptDto { | ||
prompt: string; | ||
model?: string; | ||
apiKey: string; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13909
186
91
1