Skip to content

Commit 78598a8

Browse files
committed
暂存
1 parent 39c2278 commit 78598a8

28 files changed

+1923
-1111
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Python Package
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.7", "3.8", "3.9", "3.10"]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
python -m pip install pytest pytest-cov black isort
27+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28+
pip install -e .
29+
- name: Lint with black
30+
run: |
31+
black --check .
32+
- name: Lint with isort
33+
run: |
34+
isort --check-only --profile black .
35+
- name: Test with pytest
36+
run: |
37+
pytest --cov=pydify tests/
38+
- name: Build package
39+
run: |
40+
pip install build
41+
python -m build
42+
- name: Check package
43+
run: |
44+
pip install twine
45+
twine check dist/*
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Upload Python Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: "3.x"
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install build twine
20+
- name: Build and publish
21+
env:
22+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
23+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
24+
run: |
25+
python -m build
26+
twine upload dist/*

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ htmlcov/
3535
*.swo
3636
*~
3737

38-
test.py
38+
test.py
39+
40+
./examples/test_examples.py

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 变更日志
2+
3+
所有对 Pydify 的重要更改都将记录在此文件中。
4+
5+
## [0.1.0] - 2023-03-16
6+
7+
### 添加
8+
9+
- 初始版本发布
10+
- 支持 Chatbot 应用类型
11+
- 支持 Text Generation 应用类型
12+
- 支持 Agent 应用类型
13+
- 支持 Workflow 应用类型
14+
- 支持 Chatflow 应用类型
15+
- 添加流式响应处理
16+
- 添加文件上传功能
17+
- 添加会话管理功能
18+
- 添加文本到音频转换功能

MANIFEST.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include LICENSE
2+
include README.md
3+
include README.rst
4+
include pyproject.toml
5+
include CHANGELOG.md
6+
include RELEASE.md
7+
include PUBLISH_GUIDE.md
8+
include test_install.py
9+
10+
recursive-include examples *.py
11+
recursive-exclude examples *.pyc
12+
recursive-exclude tests *.py *.pyc

PUBLISH_GUIDE.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Pydify 发布指南
2+
3+
## 已完成的工作
4+
5+
1. **项目结构设置**
6+
7+
- 创建了正确的包目录结构 (`pydify/`)
8+
- 添加了必要的包元数据文件 (`setup.py`, `pyproject.toml`, `MANIFEST.in`)
9+
- 创建了测试目录结构 (`tests/`)
10+
- 添加了版本信息 (`__version__`)
11+
12+
2. **文档**
13+
14+
- 创建了详细的 `README.md``README.rst`
15+
- 添加了 `CHANGELOG.md` 记录版本变更
16+
- 添加了 `RELEASE.md` 提供发布流程指南
17+
- 创建了安装测试脚本 `test_install.py`
18+
19+
3. **CI/CD 配置**
20+
21+
- 添加了 GitHub Actions 工作流配置
22+
- 创建了构建和测试脚本 `build_and_test.sh`
23+
24+
4. **包构建和测试**
25+
- 成功构建了源代码分发包和轮子分发包
26+
- 通过了 `twine check` 检查
27+
- 在开发模式下安装并测试了包
28+
29+
## 发布到 PyPI 的步骤
30+
31+
1. **准备发布**
32+
33+
- 确保所有测试通过:`pytest`
34+
- 确认版本号正确:
35+
- `pydify/__init__.py` 中的 `__version__`
36+
- `setup.py` 中的 `version`
37+
- 更新 `CHANGELOG.md`
38+
39+
2. **构建包**
40+
41+
```bash
42+
# 清理旧的构建文件
43+
rm -rf build/ dist/ *.egg-info/
44+
45+
# 构建包
46+
python -m build
47+
```
48+
49+
3. **检查包**
50+
51+
```bash
52+
twine check dist/*
53+
```
54+
55+
4. **发布到 TestPyPI(推荐先测试)**
56+
57+
```bash
58+
# 上传到 TestPyPI
59+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
60+
61+
# 从 TestPyPI 安装测试
62+
pip install --index-url https://test.pypi.org/simple/ pydify
63+
```
64+
65+
5. **发布到 PyPI**
66+
67+
```bash
68+
# 上传到 PyPI
69+
twine upload dist/*
70+
```
71+
72+
6. **创建 GitHub 发布**
73+
- 在 GitHub 上创建一个新的发布
74+
- 标记版本号(例如 v0.1.0)
75+
- 添加发布说明
76+
- 发布
77+
78+
## 发布后检查
79+
80+
1. **安装和验证**
81+
82+
```bash
83+
pip install pydify
84+
python test_install.py
85+
```
86+
87+
2. **更新文档**
88+
- 确保文档与最新版本一致
89+
90+
## 注意事项
91+
92+
- 首次发布到 PyPI 需要注册账号
93+
- 确保包名 `pydify` 在 PyPI 上未被占用
94+
- 如果需要更新包,请增加版本号后重新构建和上传
95+
- 发布前确保所有敏感信息(如 API 密钥)已从代码中移除

README.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
======
2+
Pydify
3+
======
4+
5+
Pydify是一个Python SDK,用于与Dify API进行交互。它提供了一组简单易用的客户端类,让您能够轻松地使用Dify的各种功能。
6+
7+
===========
8+
功能特点
9+
===========
10+
11+
* **多种应用类型支持**:支持Chatbot、Agent、Text Generation、Workflow和Chatflow应用类型
12+
* **流式响应处理**:支持处理流式(streaming)返回的消息
13+
* **文件上传**:支持上传图像等文件进行多模态理解
14+
* **会话管理**:提供会话历史记录管理功能
15+
* **文本到音频转换**:支持将文本转换为音频
16+
17+
====
18+
安装
19+
====
20+
21+
.. code-block:: bash
22+
23+
pip install pydify
24+
25+
==========
26+
快速开始
27+
==========
28+
29+
以下是一个基本的聊天机器人示例:
30+
31+
.. code-block:: python
32+
33+
from pydify import ChatbotClient
34+
35+
# 初始化客户端
36+
client = ChatbotClient(
37+
api_key="your_api_key",
38+
app_id="your_app_id"
39+
)
40+
41+
# 发送消息
42+
response = client.send_message("Hello, how are you?")
43+
print(response)
44+
45+
# 流式响应处理
46+
def handle_message(message):
47+
print(f"接收到消息: {message}")
48+
49+
def handle_end():
50+
print("消息结束")
51+
52+
client.send_message(
53+
"Tell me a story",
54+
streaming=True,
55+
message_handler=handle_message,
56+
message_end_handler=handle_end
57+
)
58+
59+
更多示例请查看项目的examples目录。
60+
61+
=======
62+
许可证
63+
=======
64+
65+
MIT
66+
67+
==========
68+
更多信息
69+
==========
70+
71+
完整文档请参考项目的README.md文件或访问GitHub仓库。

RELEASE.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# 发布指南
2+
3+
本文档提供了如何发布 Pydify 包到 PyPI 的指南。
4+
5+
## 准备发布
6+
7+
1. 确保所有测试通过:
8+
9+
```bash
10+
pytest
11+
```
12+
13+
2. 更新版本号:
14+
15+
-`pydify/__init__.py`中更新`__version__`
16+
-`setup.py`中更新`version`
17+
18+
3. 更新 CHANGELOG.md(如果有)
19+
20+
## 构建包
21+
22+
```bash
23+
# 安装构建工具
24+
pip install --upgrade build
25+
26+
# 构建包
27+
python -m build
28+
```
29+
30+
这将在`dist/`目录下创建源代码分发包(.tar.gz)和轮子分发包(.whl)。
31+
32+
## 检查包
33+
34+
```bash
35+
# 安装twine
36+
pip install --upgrade twine
37+
38+
# 检查包
39+
twine check dist/*
40+
```
41+
42+
## 测试发布到 TestPyPI(可选)
43+
44+
```bash
45+
# 上传到TestPyPI
46+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
47+
48+
# 从TestPyPI安装测试
49+
pip install --index-url https://test.pypi.org/simple/ pydify
50+
```
51+
52+
## 发布到 PyPI
53+
54+
```bash
55+
# 上传到PyPI
56+
twine upload dist/*
57+
```
58+
59+
## 创建 GitHub 发布
60+
61+
1. 在 GitHub 上创建一个新的发布
62+
2. 标记版本号(例如 v0.1.0)
63+
3. 添加发布说明
64+
4. 发布
65+
66+
## 发布后
67+
68+
1. 安装发布的包并进行验证:
69+
70+
```bash
71+
pip install pydify
72+
python test_install.py
73+
```
74+
75+
2. 更新文档(如果有)
76+
77+
3. 通知用户新版本发布

build_and_test.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# 构建和测试Pydify包的脚本
3+
4+
set -e # 遇到错误立即退出
5+
6+
echo "=== 清理旧的构建文件 ==="
7+
rm -rf build/ dist/ *.egg-info/
8+
9+
echo "=== 安装开发依赖 ==="
10+
pip install -e ".[dev]"
11+
12+
echo "=== 运行代码格式化 ==="
13+
black .
14+
isort .
15+
16+
echo "=== 运行测试 ==="
17+
pytest
18+
19+
echo "=== 构建包 ==="
20+
pip install build
21+
python -m build
22+
23+
echo "=== 检查包 ==="
24+
pip install twine
25+
twine check dist/*
26+
27+
echo "=== 完成! ==="
28+
echo "如果要发布到PyPI,请运行:"
29+
echo "twine upload dist/*"
30+
echo "或者测试发布到TestPyPI:"
31+
echo "twine upload --repository-url https://test.pypi.org/legacy/ dist/*"

0 commit comments

Comments
 (0)