• Stars
    star
    119
  • Rank 296,744 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 1 year ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

.NET API wrapper, and an amazing interactive CLI for Microsoft's new AI-powered Bing Chat.

BingChat

.NET API wrapper for Microsoft's new AI-powered Bing Chat.

.NET Version NuGet Version License

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.

Quick Start

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}");

Interactive Command Line Tool

We also developed an amazing command line tool for you! See the preview below:

CLI Preview

You can install the CLI by executing the following command simply:

dotnet tool install -g --prerelease dotnet-bingchat

Then start the CLI:

dotnet bingchat

Roadmap

  • Implement a command line tool to interact with Bing Chat
  • Provide a way to get the full result, like adaptive cards
  • Add ability to set timeout
  • Publish CLI as dotnet tool
  • Validate that connectivity issues are gone after switching to SignalR
  • Investigate BingChat iOS app and Browser changes to mitigate overzelous captcha requests
  • Investigate API spec changes to bring implementation in line with changed API contracts
  • Research OptionSet specifics, analyze whether switching to harmonyv3 enables the older model which has better performance
  • Expose rich response object via .SendAsync(..) to allow detailed access and control over the conversation state

Q&A

Set your own cookie

You 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.

UnauthorizedRequest Exception

Solution

There are multiple reasons. You may follow these steps to handle the problem.

  1. Refresh the webpage, confirm that the '_U' value is up to date and copied correctly, and retry.

  2. If you are using a proxy (VPN), try setting the global proxy, and retry. The code is as follows:

    HttpClient.DefaultProxy = new WebProxy("127.0.0.1:8807"); //Your proxy address and port
  3. Find another cookie named 'KievRPSSecAuth', set its value, and retry. The code is as follows:

    var client = new BingChatClient(new BingChatClientOptions {
        // The "_U" cookie's value
        CookieU = strU,
        // The "KievRPSSecAuth" cookie's value
        CookieKievRPSSecAuth = strKievRPSSecAuth,
    });
  4. Open the browser menu > Extensions. Search for 'Cookie Editor' and install it. Go to Bing Chat webpage and export all cookies to to a local file in JSON format. Set file path value as follows (The "_U" and "KievRPSSecAuth" value are not needed at this time):

    var client = new BingChatClient(new BingChatClientOptions {
        // The exported cookie file path
        CookieFilePath = strFilePath,
    });

Contributors

Thanks to these contributors for developing or improving this library:

Contributors

If you have any idea on this project, feel free to open a PR and share with us :D

License

This project is licensed under MIT License. We ❤ open source!

More Repositories

1

jint-configuration

Add JavaScript modules as your configuration source!
C#
10
star
2

Satori.NET

Satori 协议 .NET SDK
C#
9
star
3

YukiChan

跨平台的功能性聊天机器人「暮雪酱」,主要为 Arcaea 玩家提供查分服务
C#
7
star
4

BiliSharp

哔哩哔哩 API 的包装,为开发人员提供简单易用的接口 / bilibili API wrapper, provides easy-to-use interfaces to developers
C#
5
star
5

lancelot-docker-kernel

Built Android kernel for Redmi 9 (lancelot), supports running Docker.
4
star
6

blog

My personal blog
Vue
3
star
7

Flandre.Plugins

Self-made plugins for Flandre.
C#
2
star
8

lancelot

A cross-platform chat bot made with love and hope
TypeScript
2
star
9

webtools

BlackSoil's Webtools
Vue
2
star
10

bsdocs

A document collection for b1acksoil's projects.
2
star
11

bsblog-v2

bsBlog - Resurrection!
Vue
2
star
12

simple-weather-esp8266

ESP8266 + MicroPython 实现的简单联网天气显示
Python
2
star
13

5000choyen-api

通过 HTTP API 形式提供的五千兆图片生成服务
TypeScript
2
star
14

Dress

记录自己的女装历程
2
star
15

magisk-module-jbmonofont

A magisk module that replaces Android default monospace font with JetBrains Mono.
Shell
2
star
16

satori-server

基于 Koishi 和 @koishijs/plugin-server 的 Satori 协议服务器
TypeScript
2
star
17

bsblog-v3

BsBlog v3
HTML
1
star
18

iflyime-gboard-converter

Python
1
star
19

YukiChanR

暮雪酱 Revive
C#
1
star
20

Flandre.Plugins.SkyBlock

Hypixel SkyBlock 查询插件 (WIP)
C#
1
star
21

YukiChan.Docs

YukiChan Documentations
1
star
22

YukiChan.Server

Server for YukiChan v3
C#
1
star
23

bsblog-v2-assets

Assets for bsblog.
1
star
24

configs

自用的各类配置文件模板
1
star
25

leetcode

My LeetCode solutions
C#
1
star
26

bsdayo

1
star
27

chres

Super tiny display resolution changer for Windows
C#
1
star