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

chatgpt-official

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatgpt-official - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

5

dist/classes/chatgpt.d.ts

@@ -8,3 +8,2 @@ import Options from "../models/options.js";

private openAi;
instructionTokens: number;
constructor(key: string, options?: Options);

@@ -20,8 +19,10 @@ private chunksToLines;

askStream(data: (arg0: string) => void, prompt: string, conversationId?: string, userName?: string): Promise<string>;
aksRevProxy(prompt: string, data?: (arg0: string) => void): Promise<string>;
private aksRevProxy;
private generatePrompt;
moderate(prompt: string): Promise<boolean>;
private convToString;
private getToday;
private getTime;
private wait;
}
export default ChatGPT;

36

dist/classes/chatgpt.js

@@ -10,3 +10,2 @@ import { encode } from "gpt-3-encoder";

openAi;
instructionTokens;
constructor(key, options) {

@@ -25,6 +24,6 @@ this.key = key;

aiName: options?.aiName || "ChatGPT",
moderation: options?.moderation || false,
revProxy: options?.revProxy,
};
this.openAi = new OpenAIApi(new Configuration({ apiKey: this.key }));
this.instructionTokens = encode(this.options.instructions).length;
}

@@ -94,2 +93,8 @@ async *chunksToLines(chunksAsync) {

let promptStr = this.generatePrompt(conversation, prompt);
if (this.options.moderation) {
let flagged = await this.moderate(promptStr);
if (flagged) {
return "Your message was flagged as inappropriate and was not sent.";
}
}
try {

@@ -113,5 +118,5 @@ let responseStr;

}
let regex = new RegExp(`\n${conversation.userName}:.*`, "gs");
responseStr = responseStr
.replace(regex, "")
.replace(new RegExp(`\n${conversation.userName}:.*`, "gs"), "")
.replace(new RegExp(`${conversation.userName}:.*`, "gs"), "")
.replace(/<\|im_end\|>/g, "")

@@ -134,2 +139,12 @@ .replace(this.options.stop, "")

let conversation = this.getConversation(conversationId, userName);
if (this.options.moderation) {
let flagged = await this.moderate(prompt);
if (flagged) {
for (let chunk in "Your message was flagged as inappropriate and was not sent.".split("")) {
data(chunk);
await this.wait(100);
}
return "Your message was flagged as inappropriate and was not sent.";
}
}
let promptStr = this.generatePrompt(conversation, prompt);

@@ -165,5 +180,5 @@ try {

}
let regex = new RegExp(`\n${conversation.userName}:.*`, "gs");
responseStr = responseStr
.replace(regex, "")
.replace(new RegExp(`\n${conversation.userName}:.*`, "gs"), "")
.replace(new RegExp(`${conversation.userName}:.*`, "gs"), "")
.replace(/<\|im_end\|>/g, "")

@@ -249,2 +264,8 @@ .replace(this.options.stop, "")

}
async moderate(prompt) {
let response = await this.openAi.createModeration({
input: prompt,
});
return response.data.results[0].flagged;
}
convToString(conversation) {

@@ -280,4 +301,7 @@ let messages = [];

}
wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
}
export default ChatGPT;
//# sourceMappingURL=chatgpt.js.map

@@ -11,4 +11,5 @@ interface Options {

aiName?: string;
moderation?: boolean;
revProxy?: string;
}
export default Options;
{
"name": "chatgpt-official",
"version": "1.1.1",
"version": "1.1.2",
"description": "ChatGPT Client using official OpenAI API",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -14,3 +14,2 @@ import { encode } from "gpt-3-encoder";

private openAi: OpenAIApi;
public instructionTokens: number;
constructor(key: string, options?: Options) {

@@ -29,6 +28,6 @@ this.key = key;

aiName: options?.aiName || "ChatGPT",
moderation: options?.moderation || false,
revProxy: options?.revProxy,
};
this.openAi = new OpenAIApi(new Configuration({ apiKey: this.key }));
this.instructionTokens = encode(this.options.instructions).length;
}

@@ -110,2 +109,9 @@

if (this.options.moderation) {
let flagged = await this.moderate(promptStr);
if (flagged) {
return "Your message was flagged as inappropriate and was not sent.";
}
}
try {

@@ -129,6 +135,5 @@ let responseStr: string;

let regex = new RegExp(`\n${conversation.userName}:.*`, "gs");
responseStr = responseStr
.replace(regex, "")
.replace(new RegExp(`\n${conversation.userName}:.*`, "gs"), "")
.replace(new RegExp(`${conversation.userName}:.*`, "gs"), "")
.replace(/<\|im_end\|>/g, "")

@@ -153,2 +158,14 @@ .replace(this.options.stop, "")

let conversation = this.getConversation(conversationId, userName);
if (this.options.moderation) {
let flagged = await this.moderate(prompt);
if (flagged) {
for (let chunk in "Your message was flagged as inappropriate and was not sent.".split("")) {
data(chunk);
await this.wait(100);
}
return "Your message was flagged as inappropriate and was not sent.";
}
}
let promptStr = this.generatePrompt(conversation, prompt);

@@ -187,6 +204,5 @@

let regex = new RegExp(`\n${conversation.userName}:.*`, "gs");
responseStr = responseStr
.replace(regex, "")
.replace(new RegExp(`\n${conversation.userName}:.*`, "gs"), "")
.replace(new RegExp(`${conversation.userName}:.*`, "gs"), "")
.replace(/<\|im_end\|>/g, "")

@@ -222,3 +238,3 @@ .replace(this.options.stop, "")

public async aksRevProxy(prompt: string, data: (arg0: string) => void = (_) => {}) {
private async aksRevProxy(prompt: string, data: (arg0: string) => void = (_) => {}) {
try {

@@ -286,2 +302,9 @@ const response = await axios.post(

public async moderate(prompt: string) {
let response = await this.openAi.createModeration({
input: prompt,
});
return response.data.results[0].flagged;
}
private convToString(conversation: Conversation) {

@@ -319,4 +342,8 @@ let messages: string[] = [];

}
private wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
}
export default ChatGPT;

@@ -11,2 +11,3 @@ interface Options {

aiName?: string;
moderation?: boolean;
revProxy?: string;

@@ -13,0 +14,0 @@ }

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