chatgpt-io
Advanced tools
Comparing version 1.1.2-alpha.0 to 1.1.3
@@ -23,3 +23,3 @@ import ErrorType from "../enums/error-type.js"; | ||
resetConversation(id?: string): void; | ||
send(callback: (arg0: string) => void, prompt: string, id?: string, parentId?: string): Promise<import("../models/ask-response.js").default>; | ||
send(callback: (arg0: string) => void, prompt: string, id?: string, parentId?: string): Promise<import("../models/result.js").default<import("../models/ask-response.js").default>>; | ||
ask(prompt: string, id?: string, parentId?: string): Promise<string>; | ||
@@ -26,0 +26,0 @@ askStream(callback: (arg0: string) => void, prompt: string, id?: string, parentId?: string): Promise<string>; |
@@ -5,3 +5,2 @@ import { randomUUID, createHash } from "node:crypto"; | ||
import fs from "fs"; | ||
import AccountType from "../enums/account-type.js"; | ||
import wait from "../utils/wait.js"; | ||
@@ -23,5 +22,5 @@ import { sendMessage, getTokens, validateToken } from "../utils/chatgpt.js"; | ||
logLevel: options?.logLevel ?? LogLevel.Info, | ||
accountType: options?.accountType ?? AccountType.Free, | ||
model: options?.model ?? "text-davinci-002-render-sha", | ||
saveInterval: options?.saveInterval ?? 1000 * 60, | ||
bypassNode: options?.bypassNode ?? "https://gpt.pawan.krd", | ||
bypassNode: options?.bypassNode ?? "https://api.pawan.krd", | ||
configsDir: options?.configsDir ?? "configs", | ||
@@ -149,17 +148,3 @@ }; | ||
let conversation = this.getConversationById(id, parentId); | ||
let model; | ||
switch (this.options.accountType) { | ||
case AccountType.Free: | ||
model = "text-davinci-002-render"; | ||
break; | ||
case AccountType.Plus: | ||
model = "text-davinci-002-render-paid"; | ||
break; | ||
case AccountType.Turbo: | ||
model = "text-davinci-002-render-sha"; | ||
break; | ||
default: | ||
model = "text-davinci-002-render"; | ||
} | ||
let result = await sendMessage(callback, this.options.bypassNode, this.accessToken, model, prompt, parentId ?? conversation.parentId, conversation.conversationId); | ||
let result = await sendMessage(callback, this.options.bypassNode, this.accessToken, this.options.model, prompt, parentId ?? conversation.parentId, conversation.conversationId); | ||
if (!result.status) { | ||
@@ -175,11 +160,11 @@ this.log.error(result.error); | ||
} | ||
return result.data; | ||
return result; | ||
} | ||
async ask(prompt, id = "default", parentId) { | ||
let data = await this.send((_) => { }, prompt, id, parentId); | ||
return data.answer; | ||
let result = await this.send((_) => { }, prompt, id, parentId); | ||
return result.data.answer; | ||
} | ||
async askStream(callback, prompt, id = "default", parentId) { | ||
let data = await this.send(callback, prompt, id, parentId); | ||
return data.answer; | ||
let result = await this.send(callback, prompt, id, parentId); | ||
return result.data.answer; | ||
} | ||
@@ -189,3 +174,3 @@ async getTokens() { | ||
let result = await getTokens(this.options.bypassNode, this.sessionToken); | ||
if (result.status) { | ||
if (!result.status) { | ||
this.log.error(result.error); | ||
@@ -192,0 +177,0 @@ if (this.onError) |
@@ -1,2 +0,1 @@ | ||
import AccountType from "../enums/account-type.js"; | ||
import LogLevel from "../enums/log-level.js"; | ||
@@ -7,3 +6,3 @@ interface Options { | ||
bypassNode?: string; | ||
accountType?: AccountType; | ||
model?: string; | ||
configsDir?: string; | ||
@@ -10,0 +9,0 @@ saveInterval?: number; |
@@ -37,2 +37,5 @@ import axios from "axios"; | ||
id: randomUUID(), | ||
author: { | ||
role: "user", | ||
}, | ||
role: "user", | ||
@@ -70,29 +73,15 @@ content: { | ||
let dataToReturn; | ||
if (response.headers["content-type"] === "application/json") { | ||
let dataCollected = await new Promise((resolve) => { | ||
let dataChunks = ""; | ||
response.data.on("data", (chunk) => { | ||
dataChunks += chunk; | ||
}); | ||
response.data.on("end", () => { | ||
dataToReturn = JSON.parse(dataChunks); | ||
resolve(dataToReturn); | ||
}); | ||
}); | ||
dataToReturn = dataCollected; | ||
} | ||
else { | ||
let dataToReturnString = ""; | ||
for await (const message of streamCompletion(response.data)) { | ||
try { | ||
const parsed = JSON.parse(message); | ||
let text = parsed.message.content.parts[0]; | ||
dataToReturn = parsed; | ||
let dataToReturnString = ""; | ||
for await (const message of streamCompletion(response.data)) { | ||
try { | ||
const parsed = JSON.parse(message); | ||
let text = parsed.message.content.parts[0]; | ||
dataToReturn = parsed; | ||
if (text && text !== "") | ||
callback(text.replace(dataToReturnString, "")); | ||
dataToReturnString = text; | ||
} | ||
catch (error) { | ||
console.error("Could not JSON parse stream message", message, error); | ||
} | ||
dataToReturnString = text; | ||
} | ||
catch (error) { | ||
console.error("Could not JSON parse stream message", message, error); | ||
} | ||
} | ||
@@ -103,79 +92,51 @@ dataToReturn = dataToReturn || response.data; | ||
result.data.conversationId = dataToReturn.conversation_id; | ||
if (dataToReturn.detail) { | ||
if (isObject(dataToReturn.detail)) { | ||
if (dataToReturn.detail.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.detail.message); | ||
result.error = dataToReturn.detail.message; | ||
} | ||
catch (error) { | ||
try { | ||
result.status = false; | ||
if (error.response && error.response.data) { | ||
let errorResponseStr = ""; | ||
for await (const message of error.response.data) { | ||
errorResponseStr += message; | ||
} | ||
} | ||
else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.detail); | ||
result.error = dataToReturn.detail; | ||
} | ||
} | ||
else if (dataToReturn.details) { | ||
if (isObject(dataToReturn.details)) { | ||
if (dataToReturn.details.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.details.message); | ||
result.error = dataToReturn.details.message; | ||
const errorResponseJson = JSON.parse(errorResponseStr); | ||
if (errorResponseJson.error) { | ||
result.error = errorResponseJson.error; | ||
result.errorType = processError(errorResponseJson.error); | ||
} | ||
} | ||
else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.details); | ||
result.error = dataToReturn.details; | ||
} | ||
} | ||
else { | ||
if (result.data.answer === "") { | ||
result.status = false; | ||
result.errorType = ErrorType.UnknownError; | ||
result.error = "Failed to get response. ensure your session token is valid and isn't expired."; | ||
} | ||
} | ||
} | ||
catch (err) { | ||
let dataToReturn = err.response?.data; | ||
if (dataToReturn?.detail) { | ||
if (isObject(dataToReturn?.detail)) { | ||
if (dataToReturn?.detail?.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.detail?.message); | ||
result.error = dataToReturn?.detail?.message; | ||
else if (errorResponseJson.detail) { | ||
if (isObject(errorResponseJson.detail)) { | ||
result.error = errorResponseJson.detail.message; | ||
result.errorType = processError(errorResponseJson.detail.message); | ||
} | ||
else { | ||
result.error = errorResponseJson.detail; | ||
result.errorType = processError(errorResponseJson.detail); | ||
} | ||
} | ||
} | ||
else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.detail); | ||
result.error = dataToReturn?.detail; | ||
} | ||
} | ||
else if (dataToReturn?.details) { | ||
if (isObject(dataToReturn?.details)) { | ||
if (dataToReturn?.details?.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.details?.message); | ||
result.error = dataToReturn?.details?.message; | ||
else if (errorResponseJson.details) { | ||
if (isObject(errorResponseJson.details)) { | ||
result.error = errorResponseJson.details.message; | ||
result.errorType = processError(errorResponseJson.details.message); | ||
} | ||
else { | ||
result.error = errorResponseJson.details; | ||
result.errorType = processError(errorResponseJson.details); | ||
} | ||
} | ||
else { | ||
result.error = error.message; | ||
result.errorType = processError(error.message); | ||
} | ||
} | ||
else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.details); | ||
result.error = dataToReturn?.details; | ||
result.error = error.message; | ||
result.errorType = processError(error.message); | ||
} | ||
} | ||
else { | ||
if (result.data.answer === "") { | ||
result.status = false; | ||
result.errorType = ErrorType.UnknownError; | ||
result.error = "Failed to get response. ensure your session token is valid and isn't expired."; | ||
} | ||
else { | ||
result.status = false; | ||
result.errorType = ErrorType.UnknownError; | ||
result.error = err.toString(); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
result.status = false; | ||
result.error = error.message; | ||
result.errorType = processError(error.message); | ||
} | ||
@@ -202,4 +163,4 @@ } | ||
error: null, | ||
errorType: ErrorType.AccountRateLimitExceeded, | ||
status: false, | ||
errorType: ErrorType.UnknownError, | ||
status: true, | ||
}; | ||
@@ -222,3 +183,37 @@ try { | ||
catch (err) { | ||
throw new Error(`Could not find or parse actual response text due to: ${err}`); | ||
result.status = false; | ||
if (err.response && err.response.data) { | ||
if (err.response.data.error) { | ||
result.error = err.response.data.error; | ||
result.errorType = processError(err.response.data.error); | ||
} | ||
else if (err.response.data.detail) { | ||
if (isObject(err.response.data.detail)) { | ||
result.error = err.response.data.detail.message; | ||
result.errorType = processError(err.response.data.detail.message); | ||
} | ||
else { | ||
result.error = err.response.data.detail; | ||
result.errorType = processError(err.response.data.detail); | ||
} | ||
} | ||
else if (err.response.data.details) { | ||
if (isObject(err.response.data.details)) { | ||
result.error = err.response.data.details.message; | ||
result.errorType = processError(err.response.data.details.message); | ||
} | ||
else { | ||
result.error = err.response.data.details; | ||
result.errorType = processError(err.response.data.details); | ||
} | ||
} | ||
else { | ||
result.error = err.message; | ||
result.errorType = processError(err.message); | ||
} | ||
} | ||
else { | ||
result.error = err.message; | ||
result.errorType = processError(err.message); | ||
} | ||
} | ||
@@ -225,0 +220,0 @@ return result; |
@@ -9,3 +9,3 @@ import ChatGPT from "../dist/index.js"; | ||
let bot = new ChatGPT("eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..xcvFBxjRAO1S8qpr._P7X6XLDHH-fPyeotnwxGQao0Btz8YFL-wiyfYvxtdWHYDAVwQeLRWyAv_c_RvpXNRBhRmuvFe93KwTPJ4BI7zI0rYM70jBE73QjaEPNxM1zr4inLlGc3uyzTGzNOhwpEQrrZoK1q7X3YEMxbm2tjHuw0iM0-ArTxQ7yOztl1GBp0ag8evmhzXN4k0lBIJ5dNCsPxHvJxU8piq_H6NfgTm_uObcKaxww38sxP_ffPayrfRPRNhxfTbSVVtWstxBtPaLd6kGl66qbEojzRX-mGv_mTZnDD1jcPZqUVuRirSQacwG90zvhCuS2O348eF07SbDVGllGF8O68TWtrnX9JgSOwo1EJ1sosLf-1K0OBUmQke8u6H2JM8lJVCiEQ6wfM4b7nzX3w3UVFfFAPjzMXqUjh-rejMX87tGmyoT3bJDxrJh5ctFEUjx6Wo8ViSkJXzUOEZQx6Ea4eK3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pq0w.P4LCxigr5u-e3xnao0C2Cg"); | ||
let bot = new ChatGPT("<SESSION_TOKEN>"); | ||
@@ -12,0 +12,0 @@ while (true) { |
{ | ||
"name": "chatgpt-io", | ||
"version": "1.1.2-alpha.0", | ||
"version": "1.1.3", | ||
"description": "ChatGPT Client API, Blazing Fast, without using browser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,2 +13,4 @@ ## For support join [[Discord](https://discord.pawan.krd)] | ||
## [Check the new Google Bard Chatbot!](https://github.com/PawanOsman/GoogleBard) | ||
A simple Node.js module for interacting with the ChatGPT without using any **~~Browser~~**. | ||
@@ -15,0 +17,0 @@ |
@@ -7,3 +7,2 @@ import { randomUUID, createHash } from "node:crypto"; | ||
import Options from "../models/options.js"; | ||
import AccountType from "../enums/account-type.js"; | ||
import Conversation from "../models/conversation.js"; | ||
@@ -28,5 +27,5 @@ import wait from "../utils/wait.js"; | ||
logLevel: options?.logLevel ?? LogLevel.Info, | ||
accountType: options?.accountType ?? AccountType.Free, | ||
model: options?.model ?? "text-davinci-002-render-sha", | ||
saveInterval: options?.saveInterval ?? 1000 * 60, | ||
bypassNode: options?.bypassNode ?? "https://gpt.pawan.krd", | ||
bypassNode: options?.bypassNode ?? "https://api.pawan.krd", | ||
configsDir: options?.configsDir ?? "configs", | ||
@@ -153,20 +152,4 @@ }; | ||
let model: string; | ||
let result = await sendMessage(callback, this.options.bypassNode, this.accessToken, this.options.model, prompt, parentId ?? conversation.parentId, conversation.conversationId); | ||
switch (this.options.accountType) { | ||
case AccountType.Free: | ||
model = "text-davinci-002-render"; | ||
break; | ||
case AccountType.Plus: | ||
model = "text-davinci-002-render-paid"; | ||
break; | ||
case AccountType.Turbo: | ||
model = "text-davinci-002-render-sha"; | ||
break; | ||
default: | ||
model = "text-davinci-002-render"; | ||
} | ||
let result = await sendMessage(callback, this.options.bypassNode, this.accessToken, model, prompt, parentId ?? conversation.parentId, conversation.conversationId); | ||
if (!result.status) { | ||
@@ -181,13 +164,13 @@ this.log.error(result.error); | ||
return result.data; | ||
return result; | ||
} | ||
public async ask(prompt: string, id: string = "default", parentId?: string) { | ||
let data = await this.send((_) => {}, prompt, id, parentId); | ||
return data.answer; | ||
let result = await this.send((_) => {}, prompt, id, parentId); | ||
return result.data.answer; | ||
} | ||
public async askStream(callback: (arg0: string) => void, prompt: string, id: string = "default", parentId?: string) { | ||
let data = await this.send(callback, prompt, id, parentId); | ||
return data.answer; | ||
let result = await this.send(callback, prompt, id, parentId); | ||
return result.data.answer; | ||
} | ||
@@ -198,3 +181,3 @@ | ||
let result = await getTokens(this.options.bypassNode, this.sessionToken); | ||
if (result.status) { | ||
if (!result.status) { | ||
this.log.error(result.error); | ||
@@ -201,0 +184,0 @@ if (this.onError) this.onError(result.errorType); |
@@ -1,2 +0,1 @@ | ||
import AccountType from "../enums/account-type.js"; | ||
import LogLevel from "../enums/log-level.js"; | ||
@@ -8,3 +7,3 @@ | ||
bypassNode?: string; | ||
accountType?: AccountType; | ||
model?: string; | ||
configsDir?: string; | ||
@@ -11,0 +10,0 @@ saveInterval?: number; |
@@ -43,2 +43,5 @@ import axios from "axios"; | ||
id: randomUUID(), | ||
author: { | ||
role: "user", | ||
}, | ||
role: "user", | ||
@@ -80,26 +83,12 @@ content: { | ||
if (response.headers["content-type"] === "application/json") { | ||
let dataCollected = await new Promise<string>((resolve) => { | ||
let dataChunks = ""; | ||
response.data.on("data", (chunk: any) => { | ||
dataChunks += chunk; | ||
}); | ||
response.data.on("end", () => { | ||
dataToReturn = JSON.parse(dataChunks); | ||
resolve(dataToReturn); | ||
}); | ||
}); | ||
dataToReturn = dataCollected; | ||
} else { | ||
let dataToReturnString = ""; | ||
for await (const message of streamCompletion(response.data)) { | ||
try { | ||
const parsed = JSON.parse(message); | ||
let text = parsed.message.content.parts[0]; | ||
dataToReturn = parsed; | ||
callback(text.replace(dataToReturnString, "")); | ||
dataToReturnString = text; | ||
} catch (error) { | ||
console.error("Could not JSON parse stream message", message, error); | ||
} | ||
let dataToReturnString = ""; | ||
for await (const message of streamCompletion(response.data)) { | ||
try { | ||
const parsed = JSON.parse(message); | ||
let text = parsed.message.content.parts[0]; | ||
dataToReturn = parsed; | ||
if (text && text !== "") callback(text.replace(dataToReturnString, "")); | ||
dataToReturnString = text; | ||
} catch (error) { | ||
console.error("Could not JSON parse stream message", message, error); | ||
} | ||
@@ -113,71 +102,47 @@ } | ||
result.data.conversationId = dataToReturn.conversation_id; | ||
} catch (error: any) { | ||
try { | ||
result.status = false; | ||
if (error.response && error.response.data) { | ||
let errorResponseStr = ""; | ||
if (dataToReturn.detail) { | ||
if (isObject(dataToReturn.detail)) { | ||
if (dataToReturn.detail.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.detail.message); | ||
result.error = dataToReturn.detail.message; | ||
for await (const message of error.response.data) { | ||
errorResponseStr += message; | ||
} | ||
} else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.detail); | ||
result.error = dataToReturn.detail; | ||
} | ||
} else if (dataToReturn.details) { | ||
if (isObject(dataToReturn.details)) { | ||
if (dataToReturn.details.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.details.message); | ||
result.error = dataToReturn.details.message; | ||
const errorResponseJson = JSON.parse(errorResponseStr); | ||
if (errorResponseJson.error) { | ||
result.error = errorResponseJson.error; | ||
result.errorType = processError(errorResponseJson.error); | ||
} else if (errorResponseJson.detail) { | ||
if (isObject(errorResponseJson.detail)) { | ||
result.error = errorResponseJson.detail.message; | ||
result.errorType = processError(errorResponseJson.detail.message); | ||
} else { | ||
result.error = errorResponseJson.detail; | ||
result.errorType = processError(errorResponseJson.detail); | ||
} | ||
} else if (errorResponseJson.details) { | ||
if (isObject(errorResponseJson.details)) { | ||
result.error = errorResponseJson.details.message; | ||
result.errorType = processError(errorResponseJson.details.message); | ||
} else { | ||
result.error = errorResponseJson.details; | ||
result.errorType = processError(errorResponseJson.details); | ||
} | ||
} else { | ||
result.error = error.message; | ||
result.errorType = processError(error.message); | ||
} | ||
} else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn.details); | ||
result.error = dataToReturn.details; | ||
result.error = error.message; | ||
result.errorType = processError(error.message); | ||
} | ||
} else { | ||
if (result.data.answer === "") { | ||
result.status = false; | ||
result.errorType = ErrorType.UnknownError; | ||
result.error = "Failed to get response. ensure your session token is valid and isn't expired."; | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
result.status = false; | ||
result.error = error.message; | ||
result.errorType = processError(error.message); | ||
} | ||
} catch (err: any) { | ||
let dataToReturn = err.response?.data; | ||
if (dataToReturn?.detail) { | ||
if (isObject(dataToReturn?.detail)) { | ||
if (dataToReturn?.detail?.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.detail?.message); | ||
result.error = dataToReturn?.detail?.message; | ||
} | ||
} else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.detail); | ||
result.error = dataToReturn?.detail; | ||
} | ||
} else if (dataToReturn?.details) { | ||
if (isObject(dataToReturn?.details)) { | ||
if (dataToReturn?.details?.message) { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.details?.message); | ||
result.error = dataToReturn?.details?.message; | ||
} | ||
} else { | ||
result.status = false; | ||
result.errorType = processError(dataToReturn?.details); | ||
result.error = dataToReturn?.details; | ||
} | ||
} else { | ||
if (result.data.answer === "") { | ||
result.status = false; | ||
result.errorType = ErrorType.UnknownError; | ||
result.error = "Failed to get response. ensure your session token is valid and isn't expired."; | ||
} else { | ||
result.status = false; | ||
result.errorType = ErrorType.UnknownError; | ||
result.error = err.toString(); | ||
} | ||
} | ||
} | ||
@@ -206,4 +171,4 @@ | ||
error: null, | ||
errorType: ErrorType.AccountRateLimitExceeded, | ||
status: false, | ||
errorType: ErrorType.UnknownError, | ||
status: true, | ||
}; | ||
@@ -226,3 +191,31 @@ | ||
} catch (err: any) { | ||
throw new Error(`Could not find or parse actual response text due to: ${err}`); | ||
result.status = false; | ||
if (err.response && err.response.data) { | ||
if (err.response.data.error) { | ||
result.error = err.response.data.error; | ||
result.errorType = processError(err.response.data.error); | ||
} else if (err.response.data.detail) { | ||
if (isObject(err.response.data.detail)) { | ||
result.error = err.response.data.detail.message; | ||
result.errorType = processError(err.response.data.detail.message); | ||
} else { | ||
result.error = err.response.data.detail; | ||
result.errorType = processError(err.response.data.detail); | ||
} | ||
} else if (err.response.data.details) { | ||
if (isObject(err.response.data.details)) { | ||
result.error = err.response.data.details.message; | ||
result.errorType = processError(err.response.data.details.message); | ||
} else { | ||
result.error = err.response.data.details; | ||
result.errorType = processError(err.response.data.details); | ||
} | ||
} else { | ||
result.error = err.message; | ||
result.errorType = processError(err.message); | ||
} | ||
} else { | ||
result.error = err.message; | ||
result.errorType = processError(err.message); | ||
} | ||
} | ||
@@ -233,2 +226,2 @@ | ||
export { sendMessage, validateToken, getTokens }; | ||
export { sendMessage, validateToken, getTokens }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
82
0
200
1
0
83451
1320