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

chat-gpt-nestjs

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chat-gpt-nestjs

Empower nestjs with native OpenAi integration

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27
decreased by-44.9%
Maintainers
0
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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