auto-coder-web 0.1.38__py3-none-any.whl → 0.1.39__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- auto_coder_web/common_router/model_router.py +157 -1
- auto_coder_web/version.py +1 -1
- auto_coder_web/web/asset-manifest.json +3 -3
- auto_coder_web/web/index.html +1 -1
- auto_coder_web/web/static/js/{main.2922014a.js → main.c3e68e66.js} +3 -3
- auto_coder_web/web/static/js/{main.2922014a.js.LICENSE.txt → main.c3e68e66.js.LICENSE.txt} +4 -0
- auto_coder_web/web/static/js/{main.2922014a.js.map → main.c3e68e66.js.map} +1 -1
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.39.dist-info}/METADATA +1 -1
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.39.dist-info}/RECORD +12 -12
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.39.dist-info}/WHEEL +0 -0
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.39.dist-info}/entry_points.txt +0 -0
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.39.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,22 @@
|
|
1
|
-
from fastapi import APIRouter, HTTPException
|
1
|
+
from fastapi import APIRouter, HTTPException, Request
|
2
2
|
from typing import List, Dict, Optional
|
3
|
+
import json
|
4
|
+
import os
|
3
5
|
from pydantic import BaseModel
|
4
6
|
from autocoder import models as model_utils
|
5
7
|
|
6
8
|
router = APIRouter()
|
7
9
|
|
10
|
+
async def get_project_path(request: Request):
|
11
|
+
"""获取项目路径作为依赖"""
|
12
|
+
return request.app.state.project_path
|
13
|
+
|
14
|
+
# Path for providers JSON file
|
15
|
+
PROVIDERS_FILE = os.path.expanduser("~/.auto-coder/keys/models_providers.json")
|
16
|
+
|
17
|
+
# Ensure directory exists
|
18
|
+
os.makedirs(os.path.dirname(PROVIDERS_FILE), exist_ok=True)
|
19
|
+
|
8
20
|
class Model(BaseModel):
|
9
21
|
name: str
|
10
22
|
description: str = ""
|
@@ -154,3 +166,147 @@ async def update_model_speed(model_name: str, speed: float):
|
|
154
166
|
raise HTTPException(status_code=404, detail="Model not found")
|
155
167
|
except Exception as e:
|
156
168
|
raise HTTPException(status_code=500, detail=str(e))
|
169
|
+
|
170
|
+
# Provider management endpoints
|
171
|
+
class ModelInfo(BaseModel):
|
172
|
+
id: str
|
173
|
+
name: str
|
174
|
+
input_price: float
|
175
|
+
output_price: float
|
176
|
+
is_reasoning: bool
|
177
|
+
|
178
|
+
class ProviderConfig(BaseModel):
|
179
|
+
name: str
|
180
|
+
base_url: str
|
181
|
+
models: List[ModelInfo]
|
182
|
+
|
183
|
+
def load_providers() -> List[Dict]:
|
184
|
+
"""Load providers from JSON file"""
|
185
|
+
# Default providers if file doesn't exist
|
186
|
+
default_providers = [
|
187
|
+
{
|
188
|
+
"name": "volcanoEngine",
|
189
|
+
"base_url": "https://ark.cn-beijing.volces.com/api/v3",
|
190
|
+
"models": [
|
191
|
+
{
|
192
|
+
"id": "deepseek-v3-241226",
|
193
|
+
"name": "Deepseek V3",
|
194
|
+
"input_price": 1.0,
|
195
|
+
"output_price": 4.0,
|
196
|
+
"is_reasoning": False
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"id": "deepseek-r1-250120",
|
200
|
+
"name": "Deepseek R1",
|
201
|
+
"input_price": 2.0,
|
202
|
+
"output_price": 8.0,
|
203
|
+
"is_reasoning": True
|
204
|
+
}
|
205
|
+
]
|
206
|
+
},
|
207
|
+
{
|
208
|
+
"name": "openrouter",
|
209
|
+
"base_url": "https://openrouter.ai/api/v1",
|
210
|
+
"models": [
|
211
|
+
{
|
212
|
+
"id": "anthropic/claude-3.7-sonnet:thinking",
|
213
|
+
"name": "Claude 3.7 Sonnet Thinking",
|
214
|
+
"input_price": 22.0,
|
215
|
+
"output_price": 111.0,
|
216
|
+
"is_reasoning": True
|
217
|
+
},
|
218
|
+
{
|
219
|
+
"id": "anthropic/claude-3.7-sonnet",
|
220
|
+
"name": "Claude 3.7 Sonnet",
|
221
|
+
"input_price": 22.0,
|
222
|
+
"output_price": 111.0,
|
223
|
+
"is_reasoning": False
|
224
|
+
}
|
225
|
+
]
|
226
|
+
}
|
227
|
+
]
|
228
|
+
|
229
|
+
if not os.path.exists(PROVIDERS_FILE):
|
230
|
+
return default_providers
|
231
|
+
try:
|
232
|
+
with open(PROVIDERS_FILE, 'r',encoding='utf-8') as f:
|
233
|
+
# 根据名字去重,优先保留文件中的提供商配置
|
234
|
+
loaded_providers = json.load(f)
|
235
|
+
providers_map = {provider["name"]: provider for provider in loaded_providers}
|
236
|
+
|
237
|
+
# 只添加名字不重复的默认提供商
|
238
|
+
for default_provider in default_providers:
|
239
|
+
if default_provider["name"] not in providers_map:
|
240
|
+
providers_map[default_provider["name"]] = default_provider
|
241
|
+
|
242
|
+
return list(providers_map.values())
|
243
|
+
except Exception as e:
|
244
|
+
print(f"Error loading providers: {e}")
|
245
|
+
return default_providers
|
246
|
+
|
247
|
+
def save_providers(providers: List[Dict]) -> None:
|
248
|
+
"""Save providers to JSON file"""
|
249
|
+
with open(PROVIDERS_FILE, 'w',encoding='utf-8') as f:
|
250
|
+
# 根据名字去重,然后再统一保存
|
251
|
+
json.dump(providers, f, indent=2,ensure_ascii=False)
|
252
|
+
|
253
|
+
@router.get("/api/providers", response_model=List[ProviderConfig])
|
254
|
+
async def get_providers():
|
255
|
+
"""Get all available providers"""
|
256
|
+
try:
|
257
|
+
providers = load_providers()
|
258
|
+
return providers
|
259
|
+
except Exception as e:
|
260
|
+
raise HTTPException(status_code=500, detail=str(e))
|
261
|
+
|
262
|
+
@router.post("/api/providers", response_model=ProviderConfig)
|
263
|
+
async def add_provider(provider: ProviderConfig):
|
264
|
+
"""Add a new provider"""
|
265
|
+
try:
|
266
|
+
providers = load_providers()
|
267
|
+
|
268
|
+
# Check if provider with same name already exists
|
269
|
+
if any(p["name"] == provider.name for p in providers):
|
270
|
+
raise HTTPException(status_code=400, detail="Provider with this name already exists")
|
271
|
+
|
272
|
+
providers.append(provider.model_dump())
|
273
|
+
save_providers(providers)
|
274
|
+
return provider
|
275
|
+
except Exception as e:
|
276
|
+
raise HTTPException(status_code=500, detail=str(e))
|
277
|
+
|
278
|
+
@router.put("/api/providers/{provider_name}", response_model=ProviderConfig)
|
279
|
+
async def update_provider(provider_name: str, provider: ProviderConfig):
|
280
|
+
"""Update an existing provider"""
|
281
|
+
try:
|
282
|
+
providers = load_providers()
|
283
|
+
updated = False
|
284
|
+
|
285
|
+
for p in providers:
|
286
|
+
if p["name"] == provider_name:
|
287
|
+
p.update(provider.model_dump())
|
288
|
+
updated = True
|
289
|
+
break
|
290
|
+
|
291
|
+
if not updated:
|
292
|
+
raise HTTPException(status_code=404, detail="Provider not found")
|
293
|
+
|
294
|
+
save_providers(providers)
|
295
|
+
return provider
|
296
|
+
except Exception as e:
|
297
|
+
raise HTTPException(status_code=500, detail=str(e))
|
298
|
+
|
299
|
+
@router.delete("/api/providers/{provider_name}")
|
300
|
+
async def delete_provider(provider_name: str):
|
301
|
+
"""Delete a provider by name"""
|
302
|
+
try:
|
303
|
+
providers = load_providers()
|
304
|
+
providers_list = [p for p in providers if p["name"] != provider_name]
|
305
|
+
|
306
|
+
if len(providers) == len(providers_list):
|
307
|
+
raise HTTPException(status_code=404, detail="Provider not found")
|
308
|
+
|
309
|
+
save_providers(providers_list)
|
310
|
+
return {"message": f"Provider {provider_name} deleted successfully"}
|
311
|
+
except Exception as e:
|
312
|
+
raise HTTPException(status_code=500, detail=str(e))
|
auto_coder_web/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.39"
|
@@ -1,15 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"files": {
|
3
3
|
"main.css": "/static/css/main.0ef9afe0.css",
|
4
|
-
"main.js": "/static/js/main.
|
4
|
+
"main.js": "/static/js/main.c3e68e66.js",
|
5
5
|
"static/js/453.d855a71b.chunk.js": "/static/js/453.d855a71b.chunk.js",
|
6
6
|
"index.html": "/index.html",
|
7
7
|
"main.0ef9afe0.css.map": "/static/css/main.0ef9afe0.css.map",
|
8
|
-
"main.
|
8
|
+
"main.c3e68e66.js.map": "/static/js/main.c3e68e66.js.map",
|
9
9
|
"453.d855a71b.chunk.js.map": "/static/js/453.d855a71b.chunk.js.map"
|
10
10
|
},
|
11
11
|
"entrypoints": [
|
12
12
|
"static/css/main.0ef9afe0.css",
|
13
|
-
"static/js/main.
|
13
|
+
"static/js/main.c3e68e66.js"
|
14
14
|
]
|
15
15
|
}
|
auto_coder_web/web/index.html
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.c3e68e66.js"></script><link href="/static/css/main.0ef9afe0.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|