Warning OUT OF DATE & MAINTENANCE
Currently, the implementation is out of sync with the recent API changes which lead to frequent errors and trigger captcha. It is planned to investigate this and align the implementation with official API clients (iOS app and Browser) to reduce these issues or completely mitigate them if such possibility exists.Also, this repository is lack of maintainers for a long time. If anyone want to take over, please contact me.
Warning This library is unofficial and heavily depends on reverse-engineering. Use at your own risk.
Note Since BingChat's public release, a valid cookie is no longer required. You can use this package without any authentication.
Install this package via NuGet package manager or dotnet CLI:
dotnet add package --prerelease BingChat
Then,
using BingChat;
// Construct the chat client
var client = new BingChatClient(new BingChatClientOptions
{
// Tone used for conversation
Tone = BingChatTone.Balanced,
});
var message = "Do you like cats?";
var answer = await client.AskAsync(message);
Console.WriteLine($"Answer: {answer}");
The code above sends a message to the chat AI, and gets the answer from it.
This method creates a one-shot conversation and discards it when completed. If you want to continue chatting in the same context (just like the behavior in the web interface), you need to create a shared conversation:
// Create a conversation, so we can continue chatting in the same context.
var conversation = await client.CreateConversation();
var firstMessage = "Do you like cats?";
var answer = await conversation.AskAsync(firstMessage);
Console.WriteLine($"First answer: {answer}");
await Task.Delay(TimeSpan.FromSeconds(5));
var secondMessage = "What did I just say?";
answer = await conversation.AskAsync(secondMessage);
Console.WriteLine($"Second answer: {answer}");
We also developed an amazing command line tool for you! See the preview below:
You can install the CLI by executing the following command simply:
dotnet tool install -g --prerelease dotnet-bingchat
Then start the CLI:
dotnet bingchat
harmonyv3
enables the older model which has better
performance.SendAsync(..)
to allow detailed access and control over the conversation stateYou can set your own cookie to interact with BingChat server, instead of generating a random one.
To get it, you can go to www.bing.com, log in an account which has access, and then open the
Developer Tools (F12) > Application Tab > Storage > Cookies, find the cookie named _U
, and
copy its value. Then pass it to the BingChatClientOptions
' constructor.
Thanks to these contributors for developing or improving this library:
If you have any idea on this project, feel free to open a PR and share with us :D
This project is licensed under MIT License. We ❤ open source!