Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error When Using CLI #3

Open
yellowface7 opened this issue Feb 22, 2023 · 5 comments
Open

Error When Using CLI #3

yellowface7 opened this issue Feb 22, 2023 · 5 comments

Comments

@yellowface7
Copy link

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.

@bsdayo
Copy link
Owner

bsdayo commented Feb 23, 2023

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.

@yellowface7
Copy link
Author

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

@bsdayo
Copy link
Owner

bsdayo commented Mar 2, 2023

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.

@daiaji
Copy link

daiaji commented Mar 5, 2023

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

@Snupai
Copy link

Snupai commented Apr 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants