Upload 3 files
Browse files- Dockerfile +4 -4
- api/utils.py +17 -0
Dockerfile
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
FROM hpyp/bbapi:latest
|
| 2 |
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# 安装curl
|
| 8 |
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
| 9 |
|
|
|
|
| 10 |
COPY entrypoint.sh /entrypoint.sh
|
| 11 |
RUN chmod +x /entrypoint.sh
|
| 12 |
|
|
|
|
| 1 |
FROM hpyp/bbapi:latest
|
| 2 |
|
| 3 |
+
# 覆盖utils.py
|
| 4 |
+
COPY api/utils.py /app/api/utils.py
|
| 5 |
|
| 6 |
+
# 安装curl用于调试
|
|
|
|
|
|
|
| 7 |
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
+
# 设置entrypoint
|
| 10 |
COPY entrypoint.sh /entrypoint.sh
|
| 11 |
RUN chmod +x /entrypoint.sh
|
| 12 |
|
api/utils.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import httpx
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
async def process_non_streaming_response(request):
|
| 5 |
+
try:
|
| 6 |
+
async with httpx.AsyncClient() as client:
|
| 7 |
+
# 通过Cloudflare Worker访问
|
| 8 |
+
response = await client.post(
|
| 9 |
+
"https://hfblackbox.1224435936.workers.dev/api/v1/chat/completions",
|
| 10 |
+
json=await request.json(),
|
| 11 |
+
headers=dict(request.headers)
|
| 12 |
+
)
|
| 13 |
+
response.raise_for_status()
|
| 14 |
+
return response.json()
|
| 15 |
+
except Exception as e:
|
| 16 |
+
logging.error(f"请求失败: {str(e)}")
|
| 17 |
+
raise
|