Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-chatgpt

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-chatgpt - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

2

dist/chatgpt/chatgpt.module.d.ts

@@ -0,3 +1,5 @@

import { DynamicModule } from '@nestjs/common';
export declare class ChatGptModule {
static forRoot(apiKey: string): DynamicModule;
}
//# sourceMappingURL=chatgpt.module.d.ts.map

@@ -8,2 +8,3 @@ "use strict";

};
var ChatGptModule_1;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -13,5 +14,18 @@ exports.ChatGptModule = void 0;

const chatgpt_service_1 = require("./chatgpt.service");
let ChatGptModule = class ChatGptModule {
let ChatGptModule = ChatGptModule_1 = class ChatGptModule {
static forRoot(apiKey) {
return {
module: ChatGptModule_1,
providers: [
{
provide: chatgpt_service_1.ChatGptService,
useFactory: () => {
return new chatgpt_service_1.ChatGptService(apiKey);
},
},
],
};
}
};
ChatGptModule = __decorate([
ChatGptModule = ChatGptModule_1 = __decorate([
(0, common_1.Module)({

@@ -18,0 +32,0 @@ exports: [chatgpt_service_1.ChatGptService],

6

dist/chatgpt/chatgpt.service.d.ts
import { CreateChatgptDto } from './dto/create-chatgpt.dto';
import { ChatGptResponse } from './dto/response-chatgpt.dto';
export declare class ChatGptService {
generateTextGPT3({ prompt, apiKey }: CreateChatgptDto): Promise<ChatGptResponse>;
generateText({ prompt, model, apiKey }: CreateChatgptDto): Promise<ChatGptResponse>;
private readonly apiKey;
constructor(apiKey: string);
generateTextGPT3({ prompt }: CreateChatgptDto): Promise<ChatGptResponse>;
generateText({ prompt, model }: CreateChatgptDto): Promise<ChatGptResponse>;
}
//# sourceMappingURL=chatgpt.service.d.ts.map

@@ -8,2 +8,5 @@ "use strict";

};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -17,7 +20,10 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

let ChatGptService = class ChatGptService {
async generateTextGPT3({ prompt, apiKey }) {
return this.generateText({ prompt, model: 'text-davinci-003', apiKey });
constructor(apiKey) {
this.apiKey = apiKey;
}
async generateTextGPT3({ prompt }) {
return this.generateText({ prompt, model: 'text-davinci-003' });
}
;
async generateText({ prompt, model, apiKey }) {
async generateText({ prompt, model }) {
try {

@@ -32,3 +38,3 @@ const response = await axios_1.default.post('https://api.openai.com/v1/completions', {

'Content-Type': 'application/json',
authorization: `Bearer ${apiKey}`,
authorization: `Bearer ${this.apiKey}`,
},

@@ -44,5 +50,6 @@ });

ChatGptService = __decorate([
(0, common_1.Injectable)()
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [String])
], ChatGptService);
exports.ChatGptService = ChatGptService;
//# sourceMappingURL=chatgpt.service.js.map
export declare class CreateChatgptDto {
prompt: string;
model?: string;
apiKey: string;
}
//# sourceMappingURL=create-chatgpt.dto.d.ts.map
{
"name": "nestjs-chatgpt",
"version": "1.0.3",
"version": "1.0.4",
"homepage": "https://github.com/engcfraposo/nestjs-chatgpt",

@@ -19,3 +19,3 @@ "email": "engcfraposo@gmail.com",

],
"author": "engcfrapooso",
"author": "engcfraposo",
"license": "MIT",

@@ -22,0 +22,0 @@ "dependencies": {

@@ -27,2 +27,13 @@ ## ChatGptService

in your module you have to include the apiKey in forRoot method:
```ts
@Module({
imports: [ChatGptModule.forRoot('Your apiKey')],
})
export class AppModule {}
```
You can then use the ChatGptService in a controller or another service by injecting it with the @Injectable() decorator:

@@ -36,4 +47,4 @@

async generateText(prompt: string, apiKey: string): Promise<string> {
const createChatgptDto: CreateChatgptDto = { prompt, apiKey };
async generateText(prompt: string): Promise<string> {
const createChatgptDto: CreateChatgptDto = { prompt };
return this.chatGptService.generateTextGPT3(createChatgptDto);

@@ -52,3 +63,3 @@ }

async generateText(prompt: string, model: string, apiKey: string): Promise<string> {
const createChatgptDto: CreateChatgptDto = { prompt, model, apiKey };
const createChatgptDto: CreateChatgptDto = { prompt, model };
return this.chatGptService.generateText(createChatgptDto);

@@ -55,0 +66,0 @@ }

@@ -1,2 +0,2 @@

import { Module } from '@nestjs/common';
import { DynamicModule, Module } from '@nestjs/common';
import { ChatGptService } from './chatgpt.service';

@@ -9,2 +9,16 @@

})
export class ChatGptModule {}
export class ChatGptModule {
static forRoot(apiKey: string): DynamicModule {
return {
module: ChatGptModule,
providers: [
{
provide: ChatGptService,
useFactory: () => {
return new ChatGptService(apiKey);
},
},
],
};
}
}

@@ -8,6 +8,10 @@ import { HttpException, Injectable } from '@nestjs/common';

export class ChatGptService {
async generateTextGPT3({ prompt, apiKey }: CreateChatgptDto) {
return this.generateText({ prompt, model:'text-davinci-003', apiKey })
private readonly apiKey: string;
constructor(apiKey: string){
this.apiKey = apiKey;
}
async generateTextGPT3({ prompt }: CreateChatgptDto) {
return this.generateText({ prompt, model:'text-davinci-003' })
};
async generateText({ prompt, model, apiKey }: CreateChatgptDto) {
async generateText({ prompt, model }: CreateChatgptDto) {
try {

@@ -25,3 +29,3 @@ const response = await axios.post<ChatGptResponse>(

'Content-Type': 'application/json',
authorization: `Bearer ${apiKey}`,
authorization: `Bearer ${this.apiKey}`,
},

@@ -28,0 +32,0 @@ },

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc