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为图片下载链接
Metadata
Release files for revTongYi 0.1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| revtongyi-0.1.2.1.tar.gz | 20.9 kB | Without provenance | Details for revtongyi-0.1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| revtongyi-0.1.2.1-py3-none-any.whl | Python 3 | none | any | Details for revtongyi-0.1.2.1-py3-none-any.whl |
Total release size: 41.7 kB
Release files / revtongyi-0.1.2.1.tar.gz
| Download URL | revtongyi-0.1.2.1.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a68e2d50c71f0c1d359f5bc457d02038d745eed8b174427acf46a5b4f8377ff9
|
|
BLAKE2b-256 checksum How to use checksums |
b4d8184e9786b76fd0ca450f5322b9353ecdfbd92488631faea1199946845c9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Release files / revtongyi-0.1.2.1-py3-none-any.whl
| Download URL | revtongyi-0.1.2.1-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6589bb3d784bf6991646f648bed25f9ceb7292151ed2e99ff9d3af480a65ec4
|
|
BLAKE2b-256 checksum How to use checksums |
67015ea07eb3f30f0c6d60485530f220272fd2a0ea2ac2a71aac5feb29729954
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Security for revTongYi 0.1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.