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

@platohq/nestjs-openai

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platohq/nestjs-openai

The NestJS module for Segment based on the official analytics-node package

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
decreased by-19.35%
Maintainers
3
Weekly downloads
 
Created
Source

@platohq/nestjs-openai

The NestJS module for OpenAI based on the official openai package

How to install

npm install @platohq/nestjs-openai

or

yarn add @platohq/nestjs-openai

How to use

Register the module

import { OpenAIModule } from '@platohq/nestjs-openai';

@Module({
  imports: [
    OpenAIModule.register({
      apiKey: process.env.OPENAI_API_KEY,
    }),
  ],
})
export class AppModule {
}

Inject the service

import { OpenAIClient } from '@platohq/nestjs-openai';

@Injectable()
export class AppService {
  constructor(private readonly openAIClient: OpenAIClient) {
  }

  async createCompletion(prompt: string) {
    const { data } = await this.openAIClient.createCompletion({
      model: 'text-davinci-002',
      max_tokens: 1000,
      temperature: 0.8,
      prompt,
    });
  
    return data;
  }
}

Async options

Quite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case, use registerAsync() method, that provides a couple of various ways to deal with async data.

Use factory

OpenAIModule.registerAsync({
  useFactory: () => ({
    apiKey: process.env.OPENAI_API_KEY,
  }),
});

FAQs

Package last updated on 17 Nov 2022

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