https://github.com/notedit/dify2openai
dify to openai api
https://github.com/notedit/dify2openai
Last synced: about 1 year ago
JSON representation
dify to openai api
- Host: GitHub
- URL: https://github.com/notedit/dify2openai
- Owner: notedit
- Created: 2024-09-07T15:50:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-08T07:32:32.000Z (over 1 year ago)
- Last Synced: 2025-02-04T15:43:44.277Z (over 1 year ago)
- Language: Python
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dify2openai
### 安装说明
1. 确保已安装 Python 3.7+。
2. 创建并激活虚拟环境(可选但推荐):
```bash
python -m venv venv
source venv/bin/activate # 在 Windows 上使用 venv\Scripts\activate
```
3. 安装所需依赖:
```bash
pip install -r requirements.txt
```
4. 创建一个 `.env` 文件,并添加您的 Dify API 密钥:
```
DIFY_API_KEY=your_dify_api_key_here
```
### 使用说明
1. 确保 `main.py` 和 `difyapi.py` 文件在同一目录下。
2. 运行 FastAPI 服务器:
```bash
python main.py
```
3. 服务器将在 `http://0.0.0.0:8000` 上运行。
4. 要使用聊天功能,向 `/chat/completions` 端点发送 POST 请求,格式如下:
```json
{
"messages": [
{"role": "user", "content": "你好,请介绍一下自己。"}
]
}
```
5. 如果需要保持对话上下文,可以在请求头中添加 `X-Task-Id`。
6. 服务器将以 Server-Sent Events (SSE) 格式返回流式响应。
注意:确保您有有效的 Dify API 密钥,并且了解 Dify API 的使用条款和限制。