Metadata-Version: 2.1
Name: revTongYi
Version: 0.0.3.1
Summary: 阿里通义千问逆向工程API
Project-URL: Homepage, https://github.com/xw5xr6/revTongYi
Project-URL: Bug Tracker, https://github.com/xw5xr6/revTongYi/issues
Author-email: xw5xr6 <xw5xr6@hotmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Requires-Dist: fake-useragent
Requires-Dist: requests
Description-Content-Type: text/markdown

# revTongYi


[![PyPi](https://img.shields.io/pypi/v/revTongYi.svg)](https://pypi.python.org/pypi/revTongYi)
[![Downloads](https://static.pepy.tech/badge/revTongYi)](https://pypi.python.org/pypi/revTongYi)

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

```bash
pip install revTongYi --upgrade
```

## 通义千问 - AI对话

- 需要通义千问测试资格

```python
# 非流式模式
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))
```

```python
# 流式模式
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`传入这个值，即可继续对话。

### 列出会话列表

```python
sessions = chatbot.list_session()
```

### 删除指定会话

```python
chatbot.delete_session(sessionId=<session_id>)
```

### 修改会话标题

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

### CLI模式

1. 安装 [Chrome/Edge](https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm) 或 [Firefox](https://addons.mozilla.org/en-US/firefox/addon/cookie-editor/) 上的Cookies Editor插件
2. 前往https://tongyi.aliyun.com/chat 并登录
3. 打开此插件，点击`Export`->`Export as JSON`，将复制的Cookies内容保存到文件`cookies.json`

```bash
python -m revTongYi.__init__
```

## 通义万相 - AI图片生成

```python
import revTongYi.wanxiang as wanx

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

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