Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -137,21 +137,56 @@ def verify_api_key(credentials: HTTPAuthorizationCredentials = Security(security
|
|
| 137 |
return credentials.credentials
|
| 138 |
|
| 139 |
# 根路径GET请求处理
|
| 140 |
-
@app.get("/"
|
| 141 |
-
async def
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
# 聊天完成处理
|
| 157 |
@app.post("/ai/v1/chat/completions")
|
|
|
|
| 137 |
return credentials.credentials
|
| 138 |
|
| 139 |
# 根路径GET请求处理
|
| 140 |
+
@app.get("/")
|
| 141 |
+
async def root():
|
| 142 |
+
return JSONResponse(content={
|
| 143 |
+
"service": "AI Chat Completion Proxy",
|
| 144 |
+
"usage": {
|
| 145 |
+
"endpoint": "/ai/v1/chat/completions",
|
| 146 |
+
"method": "POST",
|
| 147 |
+
"headers": {
|
| 148 |
+
"Content-Type": "application/json",
|
| 149 |
+
"Authorization": "Bearer YOUR_API_KEY"
|
| 150 |
+
},
|
| 151 |
+
"body": {
|
| 152 |
+
"model": "One of: " + ", ".join(MODELS),
|
| 153 |
+
"messages": [
|
| 154 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 155 |
+
{"role": "user", "content": "Hello, who are you?"}
|
| 156 |
+
],
|
| 157 |
+
"stream": False,
|
| 158 |
+
"temperature": 0.7,
|
| 159 |
+
"max_tokens": 8000
|
| 160 |
+
}
|
| 161 |
+
},
|
| 162 |
+
"availableModels": MODELS,
|
| 163 |
+
"endpoints": {
|
| 164 |
+
"/ai/v1/chat/completions": "Chat completion endpoint",
|
| 165 |
+
"/ai/v1/images/generations": "Image generation endpoint",
|
| 166 |
+
"/ai/v1/models": "List available models"
|
| 167 |
+
},
|
| 168 |
+
"note": "Replace YOUR_API_KEY with your actual API key."
|
| 169 |
+
})
|
| 170 |
+
|
| 171 |
+
# 返回模型列表
|
| 172 |
+
@app.get("/ai/v1/models")
|
| 173 |
+
async def list_models(api_key: str = Depends(verify_api_key)):
|
| 174 |
+
"""返回可用模型列表。"""
|
| 175 |
+
models = [
|
| 176 |
+
{
|
| 177 |
+
"id": model,
|
| 178 |
+
"object": "model",
|
| 179 |
+
"created": int(time.time()),
|
| 180 |
+
"owned_by": "chaton",
|
| 181 |
+
"permission": [],
|
| 182 |
+
"root": model,
|
| 183 |
+
"parent": None,
|
| 184 |
+
} for model in MODELS
|
| 185 |
+
]
|
| 186 |
+
return JSONResponse(content={
|
| 187 |
+
"object": "list",
|
| 188 |
+
"data": models
|
| 189 |
+
})
|
| 190 |
|
| 191 |
# 聊天完成处理
|
| 192 |
@app.post("/ai/v1/chat/completions")
|