Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
nestjs-chatgpt
Advanced tools
This service allows you to generate text using the OpenAI API. It uses the axios library to make a post request to the OpenAI API with the provided prompt and API key.
The service exports a single method, generateText, which takes an object with a prompt and apiKey property as an argument. The prompt property should be a string containing the text you would like to generate a response for, and the apiKey property should be a string containing your OpenAI API key.
The generateText method returns a promise that resolves to the generated text.
To use the ChatGptService, you will first need to import it and the CreateChatgptDto:
import { ChatGptService } from 'nestjs-chatgpt';
You will also need to import the Injectable decorator from @nestjs/common:
import { Injectable } from '@nestjs/common';
in your module you have to include the apiKey in forRoot method:
@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:
@Injectable()
export class MyController {
constructor(private readonly chatGptService: ChatGptService) {}
async generateText(prompt: string): Promise<string> {
const createChatgptDto: CreateChatgptDto = { prompt };
return this.chatGptService.generateTextGPT3(createChatgptDto);
}
}
@Injectable()
export class MyController {
constructor(private readonly chatGptService: ChatGptService) {}
async generateText(prompt: string, model: string, apiKey: string): Promise<string> {
const createChatgptDto: CreateChatgptDto = { prompt, model };
return this.chatGptService.generateText(createChatgptDto);
}
}
You can then use the generateText method in your controller or service to generate text for the provided prompt:
@Injectable()
const generatedTextGPT3 = await this.generateTextGPT3('What is the meaning of life?', 'my-api-key');
console.log(generatedText);
@Injectable()
const generatedTextGPT3 = await this.generateText('What is the meaning of life?', 'text-davinci-003','my-api-key');
console.log(generatedText);
The generateText method throws a HttpException if there is an error with generating the text.
It is recommended to catch the exception and handle it appropriately in your controller or service.
try {
const generatedText = await this.generateText('What is the meaning of life?', 'my-api-key');
console.log(generatedText);
} catch (error) {
if (error instanceof HttpException) {
console.log(`Error generating text: ${error.message}`);
}
}
```
FAQs
NestJS module for interacting with the OpenAI's ChatGPT API
The npm package nestjs-chatgpt receives a total of 66 weekly downloads. As such, nestjs-chatgpt popularity was classified as not popular.
We found that nestjs-chatgpt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.