smgc commited on
Commit
641eced
1 Parent(s): 4e08475

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +50 -15
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("/", response_class=HTMLResponse)
141
- async def read_root():
142
- """返回欢迎页面"""
143
- html_content = """
144
- <html>
145
- <head>
146
- <title>Welcome to API</title>
147
- </head>
148
- <body>
149
- <h1>Welcome to API</h1>
150
- <p>This API is used to interact with the ChatGPT model. You can send messages to the model and receive responses.</p>
151
- </body>
152
- </html>
153
- """
154
- return HTMLResponse(content=html_content, status_code=200)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")