Skip to content

Commit 72cf4f7

Browse files
committed
feat: fix bing "Success: null" error
using a fork of node-chatgpt-api as [this PR](waylaidwanderer/node-chatgpt-api#481) hasnt been merged yet. will revert to the main package as soon as this gets merged. this fork also implements the feat in [this PR](waylaidwanderer/node-chatgpt-api#452) but it's not yet implemented
1 parent 8f05116 commit 72cf4f7

File tree

8 files changed

+98
-72
lines changed

8 files changed

+98
-72
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@prisma/client": "5.3.1",
2424
"@types/common-tags": "^1.8.2",
2525
"@types/node-schedule": "^2.1.1",
26-
"@waylaidwanderer/chatgpt-api": "^1.37.3",
26+
"@waylaidwanderer/chatgpt-api": "github:veigamann/node-chatgpt-api",
2727
"common-tags": "^1.8.2",
2828
"dayjs": "^1.11.10",
2929
"dotenv": "^16.3.1",

pnpm-lock.yaml

+62-52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `signature` on the `BingConversation` table. All the data in the column will be lost.
5+
- Added the required column `encryptedSignature` to the `BingConversation` table without a default value. This is not possible if the table is not empty.
6+
7+
*/
8+
-- RedefineTables
9+
PRAGMA foreign_keys=OFF;
10+
CREATE TABLE "new_BingConversation" (
11+
"waChatId" TEXT NOT NULL PRIMARY KEY,
12+
"waMessageId" TEXT NOT NULL,
13+
"id" TEXT NOT NULL,
14+
"clientId" TEXT NOT NULL,
15+
"jailbreakId" TEXT,
16+
"parentMessageId" TEXT,
17+
"invocationId" INTEGER NOT NULL,
18+
"encryptedSignature" TEXT NOT NULL,
19+
"expiryTime" TEXT NOT NULL,
20+
CONSTRAINT "BingConversation_waChatId_fkey" FOREIGN KEY ("waChatId") REFERENCES "WAChat" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
21+
);
22+
INSERT INTO "new_BingConversation" ("clientId", "expiryTime", "id", "invocationId", "jailbreakId", "parentMessageId", "waChatId", "waMessageId") SELECT "clientId", "expiryTime", "id", "invocationId", "jailbreakId", "parentMessageId", "waChatId", "waMessageId" FROM "BingConversation";
23+
DROP TABLE "BingConversation";
24+
ALTER TABLE "new_BingConversation" RENAME TO "BingConversation";
25+
PRAGMA foreign_key_check;
26+
PRAGMA foreign_keys=ON;

prisma/schema.prisma

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ model BingConversation {
2626
parentMessageId String?
2727
invocationId Int
2828
29-
signature String
30-
expiryTime String
29+
encryptedSignature String
30+
expiryTime String
3131
3232
waChat WAChat? @relation(fields: [waChatId], references: [id])
3333
}

src/crud/conversation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function createConversation(
1212
data: {
1313
id: completion.conversationId,
1414
clientId: completion.clientId,
15-
signature: completion.conversationSignature,
15+
encryptedSignature: completion.encryptedConversationSignature,
1616
invocationId: completion.invocationId,
1717
jailbreakId: completion.jailbreakConversationId,
1818
parentMessageId: completion.messageId,

src/handlers/completion.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ import type {
99
import { Message } from "whatsapp-web.js";
1010
import { prisma } from "../clients/prisma";
1111
import { bing } from "../clients/bing";
12-
import {
13-
ENABLE_SOURCES,
14-
ENABLE_SUGGESTIONS,
15-
STREAM_REMINDERS,
16-
STREAM_RESPONSES,
17-
SYSTEM_MESSAGE,
18-
} from "../constants";
12+
import { STREAM_REMINDERS, STREAM_RESPONSES, SYSTEM_MESSAGE } from "../constants";
1913
import { createConversation, getConversationFor } from "../crud/conversation";
2014
import { createChat, getChatFor } from "../crud/chat";
2115

@@ -95,7 +89,7 @@ async function generateCompletionFor(
9589
});
9690
else
9791
completion = await bing.sendMessage(message.body, {
98-
conversationSignature: conversation.signature,
92+
encryptedConversationSignature: conversation.encryptedSignature,
9993
conversationId: conversation.id,
10094
clientId: conversation.clientId,
10195
invocationId: conversation.invocationId,

src/handlers/context/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ export async function createContextFromMessage(message: Message) {
1515
const timezone = dayjs.tz.guess();
1616
const timestampUTC = dayjs().utc();
1717
const timestampLocal = timestampUTC.tz(timezone).format();
18-
console.log({
19-
publicUserName,
20-
timezone,
21-
timestampUTC,
22-
timestampLocal,
23-
});
2418

2519
const context = stripIndent`[system](#context)
2620
- The user's name is '${publicUserName}'

src/types/bing-ai-client.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ declare module "@waylaidwanderer/chatgpt-api" {
88
message: string,
99
options?: BingAIClientSendMessageOptions
1010
): Promise<BingAIClientResponse>;
11+
12+
uploadImage(imageBase64: string): Promise<string>;
1113
}
1214

1315
interface BingAIClientOptions {
@@ -22,7 +24,7 @@ declare module "@waylaidwanderer/chatgpt-api" {
2224
interface BingAIClientSendMessageOptions {
2325
jailbreakConversationId?: boolean | string;
2426
conversationId?: string;
25-
conversationSignature?: string;
27+
encryptedConversationSignature?: string;
2628
clientId?: string;
2729
toneStyle?: "balanced" | "creative" | "precise" | "fast";
2830
invocationId?: number;
@@ -36,7 +38,7 @@ declare module "@waylaidwanderer/chatgpt-api" {
3638
jailbreakConversationId?: string;
3739
messageId?: string;
3840
conversationId: string;
39-
conversationSignature: string;
41+
encryptedConversationSignature: string;
4042
clientId: string;
4143
invocationId: number;
4244
conversationExpiryTime: string;

0 commit comments

Comments
 (0)