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.0.7 to 1.0.8

9

dist/classes/chatgpt.d.ts

@@ -9,9 +9,12 @@ import options from "../models/options.js";

constructor(key: string, options?: options);
addConversation(conversationId: string): {
addConversation(conversationId: string, userName?: string, aiName?: string): {
id: string;
userName: string;
aiName: string;
messages: any[];
};
getConversation(conversationId: string): conversation;
private getInstructions;
getConversation(conversationId: string, userName?: string, aiName?: string): conversation;
resetConversation(conversationId: string): conversation;
ask(prompt: string, conversationId?: string): Promise<any>;
ask(prompt: string, conversationId?: string, userName?: string, aiName?: string): Promise<any>;
private generatePrompt;

@@ -18,0 +21,0 @@ private getToday;

@@ -13,10 +13,12 @@ import axios from "axios";

model: options?.model || "text-chat-davinci-002-20230126",
temperature: options?.temperature || 0.7,
max_tokens: options?.max_tokens || 256,
top_p: options?.top_p || 1,
temperature: options?.temperature || 0.1,
max_tokens: options?.max_tokens || 1024,
top_p: options?.top_p || 0.9,
frequency_penalty: options?.frequency_penalty || 0,
presence_penalty: options?.presence_penalty || 0,
instructions: options?.instructions ||
`You are ChatGPT, a large language model trained by OpenAI. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short.
Knowledge cutoff: 2021-09`,
`You are an AI language model developed by OpenAI, called ChatGPT. you have been trained on a large corpus of text data to generate human-like text and answer questions. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short.
Knowledge cutoff: 2021-09
you do not have the capability to retain information from previous interactions. Every time a user interacts with you, it is treated as a standalone session and you do not have the ability to store any information or recall past conversations
Respond conversationally.`,
stop: options?.stop || "<|im_end|>",

@@ -26,16 +28,23 @@ };

}
addConversation(conversationId) {
addConversation(conversationId, userName = "User", aiName = "ChatGPT") {
let conversation = {
id: conversationId,
userName: userName,
aiName: aiName,
messages: [],
};
conversation.messages.push(`${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`);
conversation.messages.push(this.getInstructions(aiName));
this.conversations.push(conversation);
return conversation;
}
getConversation(conversationId) {
getInstructions(aiName) {
return `${aiName !== null ? this.options.instructions.replace("You are ChatGPT", `You are ${aiName}`) : this.options.instructions}
you do not have the capability to retain information from previous interactions. Every time a user interacts with you, it is treated as a standalone session and you do not have the ability to store any information or recall past conversations
Respond conversationally.
Current date: ${this.getToday()}${this.options.stop}`;
}
getConversation(conversationId, userName = "User", aiName = "ChatGPT") {
let conversation = this.conversations.find((conversation) => conversation.id === conversationId);
if (!conversation) {
conversation = this.addConversation(conversationId);
conversation = this.addConversation(conversationId, userName, aiName);
}

@@ -51,4 +60,3 @@ else {

conversation.messages = [];
conversation.messages.push(`${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`);
conversation.messages.push(this.getInstructions(conversation.aiName));
conversation.lastActive = Date.now();

@@ -58,4 +66,4 @@ }

}
async ask(prompt, conversationId = "default") {
let conversation = this.getConversation(conversationId);
async ask(prompt, conversationId = "default", userName = "User", aiName = "ChatGPT") {
let conversation = this.getConversation(conversationId, userName, aiName);
let promptStr = this.generatePrompt(conversation, prompt);

@@ -80,4 +88,5 @@ const response = await axios.post("https://api.openai.com/v1/completions", {

.replace(this.options.stop, "")
.replace(`${conversation.aiName}: `, "")
.trim();
conversation.messages.push(`${responseStr}${this.options.stop}`);
conversation.messages.push(`${responseStr}${this.options.stop}\n`);
return responseStr;

@@ -87,7 +96,6 @@ }

prompt = [",", "!", "?", "."].includes(prompt[prompt.length - 1]) ? prompt : `${prompt}.`;
conversation.messages.push(`${prompt}\n\n`);
conversation.messages.push(`${conversation.userName}":${prompt}\n${conversation.aiName}:`);
if (!conversation.messages[0].includes("Current date:"))
conversation.messages[0] = `${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`;
let promptStr = conversation.messages.join("\n");
conversation.messages[0] = this.getInstructions(conversation.aiName);
let promptStr = conversation.messages.join();
let promptEncodedLength = encode(promptStr).length;

@@ -98,5 +106,4 @@ let totalLength = promptEncodedLength + this.options.max_tokens;

if (!conversation.messages[0].includes("Current date:"))
conversation.messages[0] = `${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`;
promptStr = conversation.messages.join("\n");
conversation.messages[0] = this.getInstructions(conversation.aiName);
promptStr = conversation.messages.join();
promptEncodedLength = encode(promptStr).length;

@@ -103,0 +110,0 @@ totalLength = promptEncodedLength + this.options.max_tokens;

interface conversation {
id: string;
messages: string[];
userName: string;
aiName: string;
lastActive?: number;
}
export default conversation;
{
"name": "chatgpt-official",
"version": "1.0.7",
"version": "1.0.8",
"description": "ChatGPT Client using official OpenAI API",

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

@@ -40,3 +40,2 @@ # chatgpt-official - Unofficial API client for ChatGPT that uses OpenAI official API [[Discord](https://discord.pawan.krd)]

presence_penalty: 0, // OpenAI parameter
historySize: 50, // Max messages to remember per conversation
instructions: `You are ChatGPT, a large language model trained by OpenAI.`, // initial instructions for the bot

@@ -43,0 +42,0 @@ model: "text-chat-davinci-002-20230126", // OpenAI parameter

@@ -17,5 +17,5 @@ import axios from "axios";

model: options?.model || "text-chat-davinci-002-20230126",
temperature: options?.temperature || 0.7,
max_tokens: options?.max_tokens || 256,
top_p: options?.top_p || 1,
temperature: options?.temperature || 0.1,
max_tokens: options?.max_tokens || 1024,
top_p: options?.top_p || 0.9,
frequency_penalty: options?.frequency_penalty || 0,

@@ -25,4 +25,6 @@ presence_penalty: options?.presence_penalty || 0,

options?.instructions ||
`You are ChatGPT, a large language model trained by OpenAI. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short.
Knowledge cutoff: 2021-09`,
`You are an AI language model developed by OpenAI, called ChatGPT. you have been trained on a large corpus of text data to generate human-like text and answer questions. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short.
Knowledge cutoff: 2021-09
you do not have the capability to retain information from previous interactions. Every time a user interacts with you, it is treated as a standalone session and you do not have the ability to store any information or recall past conversations
Respond conversationally.`,
stop: options?.stop || "<|im_end|>",

@@ -33,9 +35,10 @@ };

public addConversation(conversationId: string) {
public addConversation(conversationId: string, userName: string = "User", aiName = "ChatGPT") {
let conversation = {
id: conversationId,
userName: userName,
aiName: aiName,
messages: [],
};
conversation.messages.push(`${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`);
conversation.messages.push(this.getInstructions(aiName));
this.conversations.push(conversation);

@@ -46,6 +49,13 @@

public getConversation(conversationId: string) {
private getInstructions(aiName?: string): string {
return `${aiName !== null ? this.options.instructions.replace("You are ChatGPT", `You are ${aiName}`) : this.options.instructions}
you do not have the capability to retain information from previous interactions. Every time a user interacts with you, it is treated as a standalone session and you do not have the ability to store any information or recall past conversations
Respond conversationally.
Current date: ${this.getToday()}${this.options.stop}`;
}
public getConversation(conversationId: string, userName: string = "User", aiName = "ChatGPT") {
let conversation = this.conversations.find((conversation) => conversation.id === conversationId);
if (!conversation) {
conversation = this.addConversation(conversationId);
conversation = this.addConversation(conversationId, userName, aiName);
} else {

@@ -62,4 +72,3 @@ conversation.lastActive = Date.now();

conversation.messages = [];
conversation.messages.push(`${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`);
conversation.messages.push(this.getInstructions(conversation.aiName));
conversation.lastActive = Date.now();

@@ -71,4 +80,4 @@ }

public async ask(prompt: string, conversationId: string = "default") {
let conversation = this.getConversation(conversationId);
public async ask(prompt: string, conversationId: string = "default", userName: string = "User", aiName = "ChatGPT") {
let conversation = this.getConversation(conversationId, userName, aiName);
let promptStr = this.generatePrompt(conversation, prompt);

@@ -99,4 +108,5 @@

.replace(this.options.stop, "")
.replace(`${conversation.aiName}: `, "")
.trim();
conversation.messages.push(`${responseStr}${this.options.stop}`);
conversation.messages.push(`${responseStr}${this.options.stop}\n`);
return responseStr;

@@ -107,9 +117,7 @@ }

prompt = [",", "!", "?", "."].includes(prompt[prompt.length - 1]) ? prompt : `${prompt}.`; // Thanks to https://github.com/optionsx
conversation.messages.push(`${prompt}\n\n`);
conversation.messages.push(`${conversation.userName}":${prompt}\n${conversation.aiName}:`);
if (!conversation.messages[0].includes("Current date:"))
conversation.messages[0] = `${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`;
if (!conversation.messages[0].includes("Current date:")) conversation.messages[0] = this.getInstructions(conversation.aiName);
let promptStr = conversation.messages.join("\n");
let promptStr = conversation.messages.join();
let promptEncodedLength = encode(promptStr).length;

@@ -120,6 +128,4 @@ let totalLength = promptEncodedLength + this.options.max_tokens;

conversation.messages.shift();
if (!conversation.messages[0].includes("Current date:"))
conversation.messages[0] = `${this.options.instructions}
Current date: ${this.getToday()}${this.options.stop}`;
promptStr = conversation.messages.join("\n");
if (!conversation.messages[0].includes("Current date:")) conversation.messages[0] = this.getInstructions(conversation.aiName);
promptStr = conversation.messages.join();
promptEncodedLength = encode(promptStr).length;

@@ -126,0 +132,0 @@ totalLength = promptEncodedLength + this.options.max_tokens;

interface conversation {
id: string;
messages: string[];
userName: string;
aiName: string;
lastActive?: number;

@@ -5,0 +7,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