Skip to main content

a reverse engineering of ERNIEBot

Project description

ERNIEBot

PyPi Support_Platform

在Python上使用文心一言。可拓展为各种聊天机器人。

欢迎提交Pull Request或者Issues来改进此项目 Make a pull request to improve this project

功能 / Fetures

  • 基于ACS-Token逆向(暂时未解决)
  • 使用Selenium和Browsermob-Proxy来与文心一言模拟交互

使用 / Get Start

如果要在你的项目上使用:

  1. 执行pip install wenxin -i https://pypi.org/simple/
  2. 【已发现的问题】需要在你的项目根目录上加上/src/wenxin文件夹,然后将本项目src/wenxin/browsermob-proxy-2.1.4文件夹和chromedriver.exe复制到/src/wenxin中
  3. 使用以下代码:
from wenxin.wenxin import WenXinBot
from wenxin.wenxin import WenxinRevError

# wenxin_cookies_dict_list 的内容详见下文
wx = WenXinBot(wenxin_cookies_dict_list)
# 初始化selenium,debug=True时,会输出调试信息,方便调试。headless=False时,会打开浏览器。
wx.initSelenium(debug=False, headless=True)
# 超时设置,单位秒,防止长时间等待,当超时后,会将已经生成的文本返回
res = wx.chatViaSelenium('hello', timeout=20)
print(res)

wx = WenXinBot()需要传入一个cookie参数,获取方法如下:

  1. 使用一个获得资格的账号登录https://yiyan.baidu.com/ ,然后打开F12,找到如图所示的请求,右键另存为HAR

image

  1. 找到cookies,如下图所示,然后复制整个列表放到代码上。然后使用文本替换工具将true替换为Truefalse替换为False

image

  1. 替换文本完成后,得到的列表就是wx = WenXinBot()要传入的参数了。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Wenxin-1.1.4.tar.gz (18.1 kB view hashes)

Uploaded Source

Built Distribution

Wenxin-1.1.4-py3-none-any.whl (18.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page