Package: async-bing-client
中文文档FeaturesUse API similar to the Newbing websiteSupport image recognition by providing images as inputEnable human language-based drawingFacilitate persistent storage of session dataOrganize WebSocket communication (WSS) information into custom classes, supporting output categorization for easy developer encapsulationHigh concurrency processing capabilityRapid retrieval of chat dataBulk conversation deletion functionalityNo need for Tun mode proxySupport HTTP and SOCKS proxiesUsage GuideTable of ContentsStep 1: Create bing clientStep 2: Use client[1].Create new conversation[2].Get all cached chat lists[3].Reload cached chat lists[4].Delete specified number of chats (up to 200)[5].Delete specified chat[5].Chat with bing[6].AI drawing (provided by openai's dall-e)You can click the table of contents to jump to the corresponding content.Step 1: Create bing clientBing_Client:
Parameters:(1).cookie: bing.com cookie, need to use browser extensioncookie-editorExport cookie to json in bing chat interface, then pass file path of str or Path, can also directly pass
list[dict] formatted cookie(2).proxy: LAN proxy, need to fill in when there is no global proxy or split tunneling on local machine, support
http, httpx, socks5importasynciofromasync_bing_clientimportBing_Clientclient=Bing_Client(cookie="cookie.json",proxy="socks5://127.0.0.1:7890")if__name__=='__main__':asyncdefmain():awaitclient.init()asyncio.run(main())Step 2: Use client[1]. Create new conversation# The new conversation created here can be directly used for ask_streamchat=awaitclient.create_chat()[2]. Get all cached chat listsContains chat history of all latest 200 conversationschat_list=client.chat_list[3]. Reload cached chat lists# Just reinitializeawaitclient.init()[4]. Delete specified number of chats (up to 200)Parameters:(1).count: int = 20: Number to delete(2).del_all: bool = False: Whether to delete all (up to 200, because bing can only load latest 200 conversations)awaitclient.delete_conversation_by_count()[5]. Delete specified chatParameters:(1).conversation_id:str: conversation_id of chat to delete (chat key is conversation_id)awaitclient.delete_conversation('conversation_id')[5]. Chat with bingCan pass pictures for image recognition, can also return Image type or md image format including new ai drawings
generated by bingReturn different generator functions: ask_stream_rawParameters:(1).question: str: Your question(2).image: str | Path | bytes = None: Image you want to recognize (str here can be link of web image, can also be
str of path)(3).chat: dict = None: Chat window to send to, will create new one if not passed, and yield a NewChat class
containing the new chat(4).conversation_style: ConversationStyle = ConversationStyle.Creative: Conversation style to use(5).personality=None: Preset personality to load (just needs to be normal text, will auto obfuscate), content must
be within bing's moral and legal limits, otherwise will keep returning Apology(6).locale:str =guess_locale(): Locale to use (usually don't need to specify yourself)Return types:AsyncGenerator[NewChat | Apology | Notice | SearchResult | Text | SourceAttribution | SuggestRely | Limit | Response]Text: bing's text reply. Can access content attribute or use str method to get content. Addition of Text will still
return TextImage: bing's image reply. url attribute is image link, base64 (Optional) attribute is image base64 content, name is
image nameNewChat: Newly generated chat, can access chat attribute of NewChat to obtain.Apology: bing's refusal or error message. Can access content attribute or use str method to obtain contentNotice: bing's notification message. Can access content attribute or use str method to obtain contentSearchResult: bing's search results. content attribute stores list[dict] or str. Can use str method to convert to
suitable str formatSourceAttribution: bing's resource link reply, display_name attribute is displayed link name, see_more_url attribute
is link, image (optional) attribute is resource preview imageSuggestRely: bing's suggested reply. Can access content attribute or use str method to obtain contentLimit: bing's conversation limit content, will return Apology after exceeding limit. num_user_messages attribute is
number of messages user has sent, max_num_user_messages is max number of consecutive messages user can sendResponse: Summary of bing's messages in this conversation, content stores dict of all data generated in this
conversation.
ask_stream function wraps ask_stream_raw examplechat=client.create_chat()sources=[]suggest_reply=[]images=[]limit=Noneasyncfordatainclient.ask_stream_raw('question','image',chat=chat):ifisinstance(data,Text):yielddata.contentelifisinstance(data,SuggestRely):suggest_reply.append(data)elifisinstance(data,SourceAttribution):sources.append(data)elifisinstance(data,Apology):yield'\n'+data.contentelifisinstance(data,Image):images.append(data)elifisinstance(data,Limit):limit=dataelifisinstance(data,SearchResult)andyield_search:yieldstr(data)forindex,sourceinenumerate(sources):ifindex==0:yield"\nSee more:\n"yieldf"({index+1}):{source}\n"forindex,imageinenumerate(images):ifindex==0:yield"\nDrew images:\n"yieldf"{index+1}:{image}\n"forindex,replyinenumerate(suggest_reply):ifindex==0:yield"\nSuggest Replys:\n"yieldf"{index+1}:{reply.content}\n"iflimit:yieldf"\n\nLimit:{limit.num_user_messages}of{limit.max_num_user_messages}"Generator function outputting pure str ask_stream:asyncfortextinclient.ask_stream("hello",chat=chat,yield_search=False,conversation_style=ConversationStyle.Balanced):print(text,end="")[6]. AI drawing (provided by openai's dall-e)(This function will be called automatically in ask_stream, can directly use human language to let bing generate images)
Return value:List[Image]Image: bing's image reply. url attribute is image link, name is image nameimages=awaitclient.draw("drawing prompt")