阿里通义千问逆向工程API
Project description
revTongYi
原作者
xw5xr6已销号跑路,现接手维护
阿里通义千问、通义万相 Python逆向API
近期更改
2024/04/03
- 修改sessionId判断,优化报错
2024/03/29
- 以对象封装响应数据,方便使用
2024/03/11
- 添加识图功能。
- 响应数据格式有变动,请尽快适配。
pip install revTongYi --upgrade
以下接口的返回值均可在源码或方法的 Type Hints 里查看
通义千问 - 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)
识图对话
# 获取图片二进制的示例
import requests
image_bytes = requests.get("https://avatars.githubusercontent.com/u/152763253").content
chatbot.ask(
prompt="这是什么?",
image=image_bytes # 传入图片的二进制数据,会自动上传给千问
)
连续对话
返回值中有msgId和sessionId,下一次调用ask时以parentId和sessionId传入这两个值,即可继续对话。
新建对话
调用ask时不传入sessionId参数或传入空字符串即可。
列出会话列表
sessions = chatbot.list_session()
删除指定会话
chatbot.delete_session(sessionId=<session_id>)
修改会话标题
chatbot.update_session(sessionId=<session_id>, summary=<new_title>)
获取会话历史记录
history = chatbot.get_session_history(sessionId=<session_id>)
CLI模式
- 安装 Chrome/Edge 或 Firefox 上的Cookies Editor插件
- 前往 https://qianwen.aliyun.com/ 并登录
- 打开此插件,点击
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
Release history Release notifications | RSS feed
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.1.2.1.tar.gz
(20.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file revtongyi-0.1.2.1.tar.gz.
File metadata
- Download URL: revtongyi-0.1.2.1.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a68e2d50c71f0c1d359f5bc457d02038d745eed8b174427acf46a5b4f8377ff9
|
|
| MD5 |
e771c710076f2da2fba931085b0ed404
|
|
| BLAKE2b-256 |
b4d8184e9786b76fd0ca450f5322b9353ecdfbd92488631faea1199946845c9c
|
File details
Details for the file revtongyi-0.1.2.1-py3-none-any.whl.
File metadata
- Download URL: revtongyi-0.1.2.1-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6589bb3d784bf6991646f648bed25f9ceb7292151ed2e99ff9d3af480a65ec4
|
|
| MD5 |
3d411caaf216595631ebcf7b9bbfad81
|
|
| BLAKE2b-256 |
67015ea07eb3f30f0c6d60485530f220272fd2a0ea2ac2a71aac5feb29729954
|