Skip to main content

阿里通义千问逆向工程API

Project description

revTongYi

PyPi Downloads

阿里通义千问、通义万相 Python逆向API

pip install revTongYi --upgrade

通义千问 - AI对话

  • 需要通义千问测试资格
# 非流式模式
import revTongYi.qianwen as qwen

question = "人工智能将对人类社会发展产生什么影响?"

chatbot = qwen.Chatbot(
    cookies=<cookies_dict>  # 以dict形式提供cookies
)
# chatbot = qwen.Chatbot(
#     cookies_str=<cookies_str>  # 您也可以使用字符串形式提供cookies,cookies字符串可以从浏览器的请求头中获取
# )

print(chatbot.ask(prompt=question))
# 流式模式
import revTongYi.qianwen as qwen

question = "人工智能将对人类社会发展产生什么影响?"

chatbot = qwen.Chatbot(
    cookies=<cookies_dict>  # 以dict形式提供cookies
)

for resp in chatbot.ask(prompt=question, stream=True):
    print(resp)

连续对话

返回值中有个msgId,下一次调用ask时以parentId传入这个值,即可继续对话。

列出会话列表

sessions = chatbot.list_session()

删除指定会话

chatbot.delete_session(sessionId=<session_id>)

修改会话标题

chatbot.update_session(sessionId=<session_id>, summary=<new_title>)

CLI模式

  1. 安装 Chrome/EdgeFirefox 上的Cookies Editor插件
  2. 前往https://tongyi.aliyun.com/chat 并登录
  3. 打开此插件,点击Export->Export as JSON,将复制的Cookies内容保存到文件cookies.json
python -m revTongYi.__init__

通义万相 - AI图片生成

import revTongYi.wanxiang as wanx

imagebot = wanx.Imagebot(
    cookies=<cookies_dict>  # 以dict形式提供cookies
)

print(imagebot.generate(prompt="草原"))
# 生成四张图片,downloadUrl为图片下载链接

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

revtongyi-0.0.3.1.tar.gz (20.6 kB view hashes)

Uploaded Source

Built Distribution

revtongyi-0.0.3.1-py3-none-any.whl (18.8 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