1.4.1 • Published 6 months ago

chat-gpt-nestjs v1.4.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

Description

Add openai in your nestjs module

Installation

$ yarn add chat-gpt-nestjs

Usage

First create two env variables:

API_KEY=sk-XxxxXXXxxx
ORGANIZATION_ID=xxxxx

note that ORGANIZATION_ID is optional

Using register async configuration in your module

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ChatModule } from 'chat-gpt-nestjs';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    ConfigModule.forRoot({
      cache: true,
    }),
    ChatModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        organizationId: configService.get('ORGANIZATION_ID'),
        apiKey: configService.get('API_KEY'),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

You can now use openai in your services as follow as an example:

import { Injectable } from '@nestjs/common';
import { ChatService } from 'chat-gpt-nestjs';

@Injectable()
export class AppService {
  constructor(private readonly appService: ChatService) {}

  async createCompletion(prompt:string) {
    try {
      const completion = await this.openai.createCompletion({
        model: 'text-davinci-003',
        prompt,
      });

      return completion.data.choices[0].text
    } catch (e) {
      console.error(e);
    }
  }
}

Roadmap

x Get listModels and cache results to avoid to many calls [] More to come!

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

chat-gpt-nestjs is MIT licensed.

1.4.1

6 months ago

1.2.0

11 months ago

1.1.0

11 months ago

1.0.0

11 months ago

1.4.0

11 months ago

1.3.0

11 months ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.7

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago