Skip to content

Commit

Permalink
feat: fix bing "Success: null" error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
veigamann committed Oct 5, 2023
1 parent 8f05116 commit 72cf4f7
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@prisma/client": "5.3.1",
"@types/common-tags": "^1.8.2",
"@types/node-schedule": "^2.1.1",
"@waylaidwanderer/chatgpt-api": "^1.37.3",
"@waylaidwanderer/chatgpt-api": "github:veigamann/node-chatgpt-api",
"common-tags": "^1.8.2",
"dayjs": "^1.11.10",
"dotenv": "^16.3.1",
Expand Down
114 changes: 62 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Warnings:
- You are about to drop the column `signature` on the `BingConversation` table. All the data in the column will be lost.
- Added the required column `encryptedSignature` to the `BingConversation` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_BingConversation" (
"waChatId" TEXT NOT NULL PRIMARY KEY,
"waMessageId" TEXT NOT NULL,
"id" TEXT NOT NULL,
"clientId" TEXT NOT NULL,
"jailbreakId" TEXT,
"parentMessageId" TEXT,
"invocationId" INTEGER NOT NULL,
"encryptedSignature" TEXT NOT NULL,
"expiryTime" TEXT NOT NULL,
CONSTRAINT "BingConversation_waChatId_fkey" FOREIGN KEY ("waChatId") REFERENCES "WAChat" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_BingConversation" ("clientId", "expiryTime", "id", "invocationId", "jailbreakId", "parentMessageId", "waChatId", "waMessageId") SELECT "clientId", "expiryTime", "id", "invocationId", "jailbreakId", "parentMessageId", "waChatId", "waMessageId" FROM "BingConversation";
DROP TABLE "BingConversation";
ALTER TABLE "new_BingConversation" RENAME TO "BingConversation";
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ model BingConversation {
parentMessageId String?
invocationId Int
signature String
expiryTime String
encryptedSignature String
expiryTime String
waChat WAChat? @relation(fields: [waChatId], references: [id])
}
Expand Down
2 changes: 1 addition & 1 deletion src/crud/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function createConversation(
data: {
id: completion.conversationId,
clientId: completion.clientId,
signature: completion.conversationSignature,
encryptedSignature: completion.encryptedConversationSignature,
invocationId: completion.invocationId,
jailbreakId: completion.jailbreakConversationId,
parentMessageId: completion.messageId,
Expand Down
10 changes: 2 additions & 8 deletions src/handlers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import type {
import { Message } from "whatsapp-web.js";
import { prisma } from "../clients/prisma";
import { bing } from "../clients/bing";
import {
ENABLE_SOURCES,
ENABLE_SUGGESTIONS,
STREAM_REMINDERS,
STREAM_RESPONSES,
SYSTEM_MESSAGE,
} from "../constants";
import { STREAM_REMINDERS, STREAM_RESPONSES, SYSTEM_MESSAGE } from "../constants";
import { createConversation, getConversationFor } from "../crud/conversation";
import { createChat, getChatFor } from "../crud/chat";

Expand Down Expand Up @@ -95,7 +89,7 @@ async function generateCompletionFor(
});
else
completion = await bing.sendMessage(message.body, {
conversationSignature: conversation.signature,
encryptedConversationSignature: conversation.encryptedSignature,
conversationId: conversation.id,
clientId: conversation.clientId,
invocationId: conversation.invocationId,
Expand Down
6 changes: 0 additions & 6 deletions src/handlers/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ export async function createContextFromMessage(message: Message) {
const timezone = dayjs.tz.guess();
const timestampUTC = dayjs().utc();
const timestampLocal = timestampUTC.tz(timezone).format();
console.log({
publicUserName,
timezone,
timestampUTC,
timestampLocal,
});

const context = stripIndent`[system](#context)
- The user's name is '${publicUserName}'
Expand Down
6 changes: 4 additions & 2 deletions src/types/bing-ai-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ declare module "@waylaidwanderer/chatgpt-api" {
message: string,
options?: BingAIClientSendMessageOptions
): Promise<BingAIClientResponse>;

uploadImage(imageBase64: string): Promise<string>;
}

interface BingAIClientOptions {
Expand All @@ -22,7 +24,7 @@ declare module "@waylaidwanderer/chatgpt-api" {
interface BingAIClientSendMessageOptions {
jailbreakConversationId?: boolean | string;
conversationId?: string;
conversationSignature?: string;
encryptedConversationSignature?: string;
clientId?: string;
toneStyle?: "balanced" | "creative" | "precise" | "fast";
invocationId?: number;
Expand All @@ -36,7 +38,7 @@ declare module "@waylaidwanderer/chatgpt-api" {
jailbreakConversationId?: string;
messageId?: string;
conversationId: string;
conversationSignature: string;
encryptedConversationSignature: string;
clientId: string;
invocationId: number;
conversationExpiryTime: string;
Expand Down

0 comments on commit 72cf4f7

Please sign in to comment.