BingChat icon indicating copy to clipboard operation
BingChat copied to clipboard

Error When Using CLI

Open yellowface7 opened this issue 1 year ago • 5 comments

Current behavior

After sending a message, the following error is thrown: Error: Object reference not set to an instance of an object. Then the program crashes.

Expected Behavior:

Bing AI responds to user message.

Reproduction steps:

  1. Open command prompt at root
  2. Run dotnet run --project src/BingChat.Cli/BingChat.Cli.csproj
  3. Type in anything and hit enter
  4. Notice the error message after

Log

Welcome to Bing Chat!
Enter message to chat with Bing, or enter /help to get command help.
[REDACTED]
Creating new conversation...
Error: Object reference not set to an instance of an object.

Closing Notes:

  • At the time the error was thrown, my daily limit was already met
  • This was done on a fresh install with the environment variable set
  • OS: Windows 11 Home

Very interesting API though. Curious to see if it can get through the censoring.

yellowface7 avatar Feb 22 '23 22:02 yellowface7

Seems not related to the daily limit. My limit is already met too but I didn't crash.

Could you please provide more detailed information such as the stack trace? Since the CLI library Spectre.Console.Cli only outputs the error message, you can manually wrap the code with try...catch... and log the stack trace:

// src/BingChat.Cli/Commands/ConversationCommand.cs

public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
    try
    {
        // The execution code...
    }
    catch (Exception e)
    {
        Console.WriteLine(e.StackTrace);
        return 1;
    }
}

Then dotnet run --project .\src\BingChat.Cli\BingChat.Cli.csproj again, and paste the output here.

bsdayo avatar Feb 23 '23 15:02 bsdayo

Here is the stack trace:

                        at BingChat.BingChatConversation.<AskAsync>g__GetAnswer|3_1(BingChatConversationResponse response) in C:\[REDACTED]\BingChat-0.3.0\src\BingChat\BingChatConversation.cs:line 40
                     atConversation.<>c__DisplayClass3_0.<AskAsync>g__OnMessageReceived|2(String text) in C:\[REDACTED]
\ Bing is thinking...-0.3.0\src\BingChat\BingChatConversation.cs:line 65

yellowface7 avatar Feb 24 '23 03:02 yellowface7

I eventually found the problem. I'm in China and Bing Chat doesn't serve China. If I had used the original IP address directly, I would have had the same problem.

Unauthorized -> The server did not send the required credential -> Still unauthorized when trying to receive the response -> JSON deserialization error -> NullReferenceException

But when I used a US proxy, the problem resolved.

If you make sure the correct cookie is set and you still keep seeing this, maybe Bing Chat doesn't serve your region. You can use a proxy and try again.

bsdayo avatar Mar 02 '23 13:03 bsdayo

headers.Add("x-forwarded-for", "66.249.73.97"); bing只验证x-forwarded-for头的话。 也能用。 这个客户端也能不绕过单个会话的提问数量限制吧? 猫娘GHS能搞只能搞一点点,蚌埠了。 出文本了就被删除了。

daiaji avatar Mar 05 '23 13:03 daiaji

So basically I get a similar error but only with short inputs.

If I input "Bing AI" it would throw

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at BingChat.BingChatConversation.<AskAsync>g__GetAnswer|3_1(BingChatConversationResponse response)
   at BingChat.BingChatConversation.<>c__DisplayClass3_0.<AskAsync>g__OnMessageReceived|2(String text)
--- End of stack trace from previous location ---
   at BingChat.BingChatClient.AskAsync(String message)
   at ConsoleApp1.program.MainAsync() in D:\vs-projects\ConsoleApp1\ConsoleApp1\Program.cs:line 29
   at ConsoleApp1.program.<Main>(String[] args)

but if I have a longer input it works just fine. as an example "Bing AI a" would work.

Snupai avatar Apr 07 '23 15:04 Snupai