ReEdgeGPT

ReEdgeGPT

Python库实现必应AI聊天功能交互

ReEdgeGPT是一个开源Python库,实现了与必应AI聊天功能的交互。该库支持自动化对话、图像生成和插件集成,提供简单易用的API和异步操作。开发者可利用ReEdgeGPT构建聊天机器人和AI应用。项目已在GitHub开源,并提供详细文档。

Rome意大利首都古罗马梵蒂冈文化中心Github开源项目

ReEdgeGPT

Downloads

The reverse engineering the chat feature of the new version of Bing

Documentation Status

ReEdgeGPT Doc Click Here!

If you have any problem watch bottom Q&A first.

  • Notice! Copilot now easier to raise CaptchaChallenge: User needs to solve CAPTCHA to continue.
    • Pls manual send message to Copilot and retry.
    • Microsoft change cookie expiration time from one week to only 3 days.

Another README

<details>

繁體中文

</details> <summary>

Setup

</summary> <details open>

Install package

python3 -m pip install re_edge_gpt --upgrade

Requirements

  • python 3.9+
  • A Microsoft Account with access to https://bing.com/chat (Optional, depending on your region)
  • Required in a supported country or region with New Bing (Chinese mainland VPN required)

Authentication

!!! POSSIBLY NOT REQUIRED ANYMORE !!!

In some regions, Microsoft has made the chat feature available to everyone, so you might be able to skip this step. You can check this with a browser (with user-agent set to reflect Edge), by trying to start a chat without logging in.

It was also found that it might depend on your IP address. For example, if you try to access the chat features from an IP that is known to belong to a datacenter range (vServers, root servers, VPN, common proxies, ...), you might be required to log in while being able to access the features just fine from your home IP address.

If you receive the following error, you can try providing a cookie and see if it works then:

Exception: Authentication failed. You have not been accepted into the beta.

Collect cookies

  • a) (Easy) Install the latest version of Microsoft Edge
  • b) (Advanced) Alternatively, you can use any browser and set the user-agent to look like you're using Edge (e.g., Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51). You can do this easily with an extension like "User-Agent Switcher and Manager" for Chrome and Firefox.
  1. Get a browser that looks like Microsoft Edge.
  2. Open bing.com/chat
  3. If you see a chat feature, you are good to continue...
  4. Install the cookie editor extension for Chrome or Firefox
  5. Go to bing.com/chat
  6. Open the extension
  7. Click "Export" on the bottom right, then "Export as JSON" (This saves your cookies to clipboard)
  8. Paste your cookies into a file bing_cookies.json.
    • NOTE: The cookies file name MUST follow the regex pattern bing_cookies.json, so that they could be recognized by internal cookie processing mechanisms

Use cookies in code:

import json from re_edge_gpt import Chatbot async def create_bot(): cookies = json.loads(open("./path/to/bing_cookies.json", encoding="utf-8").read()) bot = await Chatbot.create(cookies=cookies) return bot
</details> <summary>

How to use Chatbot

</summary> <details>

Run from Command Line

 $ python3 -m re_edge_gpt -h

        ReEdgeGPT - A demo of reverse engineering the Bing GPT chatbot

        !help for help

        Type !exit to exit

usage: __main__.py [-h] [--enter-once] [--search-result] [--no-stream] [--rich] [--proxy PROXY] [--wss-link WSS_LINK]
                  [--style {creative,balanced,precise}] [--prompt PROMPT] [--cookie-file COOKIE_FILE]
                  [--history-file HISTORY_FILE] [--locale LOCALE]

options:
  -h, --help            show this help message and exit
  --enter-once
  --search-result
  --no-stream
  --rich
  --proxy PROXY         Proxy URL (e.g. socks5://127.0.0.1:1080)
  --wss-link WSS_LINK   WSS URL(e.g. wss://sydney.bing.com/sydney/ChatHub)
  --style {creative,balanced,precise}
  --prompt PROMPT       prompt to start with
  --cookie-file COOKIE_FILE
                        path to cookie file
  --history-file HISTORY_FILE
                        path to history file
  --locale LOCALE       your locale (e.g. en-US, zh-CN, en-IE, en-GB)

(China/US/UK/Norway has enhanced support for locale)

Run in Python

1. The Chatbot class and asyncio for more granular control

Use Async for the best experience, for example:

import asyncio import json from pathlib import Path from re_edge_gpt import Chatbot from re_edge_gpt import ConversationStyle # If you are using jupyter pls install this package # from nest_asyncio import apply async def test_ask() -> None: bot = None try: cookies = json.loads(open( str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read()) bot = await Chatbot.create(cookies=cookies) response = await bot.ask( prompt="How to boil the egg", conversation_style=ConversationStyle.balanced, simplify_response=True ) # If you are using non ascii char you need set ensure_ascii=False print(json.dumps(response, indent=2, ensure_ascii=False)) # Raw response # print(response) assert response except Exception as error: raise error finally: if bot is not None: await bot.close() if __name__ == "__main__": # If you are using jupyter pls use nest_asyncio apply() # apply() try: loop = asyncio.get_running_loop() except RuntimeError: loop = asyncio.get_event_loop() loop.run_until_complete(test_ask())
</details> <summary>

Use copilot as default mode

</summary> <details>

Collect cookies

  • a) (Easy) Install the latest version of Microsoft Edge
  • b) (Advanced) Alternatively, you can use any browser and set the user-agent to look like you're using Edge (e.g., Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51). You can do this easily with an extension like "User-Agent Switcher and Manager" for Chrome and Firefox.
  1. Get a browser that looks like Microsoft Edge.
  2. Open copilot.microsoft.com
  3. If you see a chat feature, you are good to continue...
  4. Install the cookie editor extension for Chrome or Firefox
  5. Go to copilot.microsoft.com)
  6. Open the extension
  7. Click "Export" on the bottom right, then "Export as JSON" (This saves your cookies to clipboard)
  8. Paste your cookies into a file copilot_cookies.json.
    • NOTE: The cookies file name MUST follow the regex pattern copilot_cookies.json, so that they could be recognized by internal cookie processing mechanisms

Use cookies in code:

import asyncio import json from pathlib import Path from re_edge_gpt import Chatbot from re_edge_gpt import ConversationStyle # If you are using jupyter pls install this package # from nest_asyncio import apply async def test_ask() -> None: bot = None try: mode = "Copilot" if mode == "Bing": cookies: list[dict] = json.loads(open( str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read()) else: cookies: list[dict] = json.loads(open( str(Path(str(Path.cwd()) + "/copilot_cookies.json")), encoding="utf-8").read()) # Notice when mode != "Bing" (Bing is default) will set mode is copilot bot = await Chatbot.create(cookies=cookies, mode=mode) response = await bot.ask( prompt="Is your name Copilot", conversation_style=ConversationStyle.balanced, simplify_response=True ) # If you are using non ascii char you need set ensure_ascii=False print(json.dumps(response, indent=2, ensure_ascii=False)) # Raw response # print(response) assert response except Exception as error: raise error finally: if bot is not None: await bot.close() if __name__ == "__main__": # If you are using jupyter pls use nest_asyncio apply() # apply() try: loop = asyncio.get_running_loop() except RuntimeError: loop = asyncio.get_event_loop() loop.run_until_complete(test_ask())

When u ask copilot what is your name

are_u_bing.png

</details> <summary>

How to generate image

</summary> <details>

Getting authentication

Chromium based browsers (Edge, Opera, Vivaldi, Brave)

  • Go to https://bing.com/
  • F12 to open console
  • In the JavaScript console, type cookieStore.get("_U").then(result => console.log(result.value)) and press enter
  • Copy the output. This is used in --U or auth_cookie.

Firefox

  • Go to https://bing.com/.
  • F12 to open developer tools
  • navigate to the storage tab
  • expand the cookies tab
  • click on the https://bing.com cookie
  • copy the value from the _U
import os import shutil from pathlib import Path from re_edge_gpt import ImageGen, ImageGenAsync # create a temporary output directory for testing purposes test_output_dir = "test_output" # download a test image test_image_url = "https://picsum.photos/200" auth_cooker = open("bing_cookies.txt", "r+").read() sync_gen = ImageGen(auth_cookie=auth_cooker) async_gen = ImageGenAsync(auth_cookie=auth_cooker) def test_save_images_sync(): sync_gen.save_images([test_image_url], test_output_dir) sync_gen.save_images([test_image_url], test_output_dir, file_name="test_image") # check if the image was downloaded and saved correctly assert os.path.exists(os.path.join(test_output_dir, "test_image_0.jpeg")) assert os.path.exists(os.path.join(test_output_dir, "0.jpeg")) # Generate image list sync def test_generate_image_sync(): image_list = sync_gen.get_images("tree") print(image_list) if __name__ == "__main__": # Make dir to save image Path("test_output").mkdir(exist_ok=True) # Save image test_save_images_sync() # Generate image sync test_generate_image_sync() # Remove dir shutil.rmtree(test_output_dir)
</details> <summary>

Plugins support

</summary> <details>

https://github.com/Integration-Automation/ReEdgeGPT/issues/119

Example:

import asyncio import json from pathlib import Path from random import choice from string import ascii_uppercase from re_edge_gpt import Chatbot from re_edge_gpt import ConversationStyle # If you are using jupyter pls install this package # from nest_asyncio import apply async def test_ask() -> None: bot = None try: cookies: list[dict] = json.loads(open( str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read()) bot = await Chatbot.create(cookies=cookies, mode="Bing", plugin_ids=["c310c353-b9f0-4d76-ab0d-1dd5e979cf68"]) prompt = """Rome (Italian and Latin: Roma, Italian: [ˈroːma] ⓘ) is the capital city of Italy. It is also the capital of the Lazio region, the centre of the Metropolitan City of Rome Capital, and a special comune (municipality) named Comune di Roma Capitale. With 2,860,009 residents in 1,285 km2 (496.1 sq mi),[2] Rome is the country's most populated comune and the third most populous city in the European Union by population within city limits. The Metropolitan City of Rome, with a population of 4,355,725 residents, is the most populous metropolitan city in Italy.[3] Its metropolitan area is the third-most populous within Italy.[5] Rome is located in the central-western portion of the Italian Peninsula, within Lazio (Latium), along the shores of the Tiber. Vatican City (the smallest country in the world)[6] is an independent country inside the city boundaries of Rome, the only existing example of a country within a city. Rome is often referred to as the City of Seven Hills due to its geographic location, and also as the "Eternal City". Rome is generally considered to be the cradle of Western civilization and Western Christian culture, and the centre of the Catholic Church.[7][8][9] Rome's history spans 28 centuries. While Roman mythology dates the founding of Rome at around 753 BC, the site has been inhabited for much longer, making it a major human settlement for almost three millennia and one of the oldest continuously occupied cities in Europe.[10] The city's early population originated from a mix of Latins, Etruscans, and Sabines. Eventually, the city successively became the capital of the Roman Kingdom, the Roman Republic and the Roman Empire, and is regarded by many as the first-ever Imperial city and metropolis.[11] It was first called The Eternal City (Latin: Urbs Aeterna; Italian: La Città Eterna) by the Roman poet Tibullus in the 1st century BC, and the expression was also taken up by Ovid, Virgil, and Livy.[12][13] Rome is also called "Caput Mundi" (Capital of the World). After the fall of the Empire in the west, which marked the beginning of the Middle Ages, Rome slowly fell under the political control of the Papacy, and in the 8th century, it became the capital of the Papal States, which lasted until 1870. Beginning with the Renaissance, almost all popes since Nicholas V (14471455) pursued a coherent architectural and urban programme over four hundred years, aimed at making the city the artistic and cultural centre of the world.[14] In this way, Rome first became one of the major centres of the Renaissance[15] and then became the birthplace of both the Baroque style and Neoclassicism. Famous artists, painters, sculptors, and architects made Rome the centre of their activity, creating masterpieces throughout the city. In 1871, Rome became the capital of the Kingdom of Italy, which, in 1946, became the Italian Republic. In 2019, Rome was the 14th most visited city in the world, with 8.6 million tourists, the third most visited city in the European Union, and the most popular tourist destination in Italy.[16] Its historic centre is listed by UNESCO as a World Heritage Site.[17] The host city for the 1960 Summer Olympics, Rome is also the seat of several specialised agencies of the United Nations, such as the Food and Agriculture Organization (FAO), the World Food Programme (WFP) and the International Fund for Agricultural Development (IFAD). The city also hosts the Secretariat of the Parliamentary Assembly of the Union for the Mediterranean[18] (UfM) as well as the headquarters of many multinational companies, such as Eni, Enel, TIM, Leonardo, and banks such as BNL. Numerous companies are based within Rome's EUR business district, such as the luxury fashion house Fendi located in the Palazzo della Civiltà Italiana. The presence of renowned international brands in the city has made Rome an important centre of fashion and design, and the Cinecittà Studios have been the set of many Academy Award–winning movies.[19] Name and symbol Etymology According to the Ancient Romans' founding myth,[20] the name Roma came from the city's founder and first king, Romulus.[1] However, it is possible that the name Romulus was actually derived from Rome itself.[21] As early as the 4th century, there have been alternative theories proposed on the origin of the name Roma. Several hypotheses have been advanced focusing on its linguistic roots which however remain uncertain:[22] From Rumon or Rumen, archaic name of the Tiber,

编辑推荐精选

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
蛙��蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI辅助写作AI工具蛙蛙写作AI写作工具学术助手办公助手营销助手AI助手
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

下拉加载更多