nomid2 commited on
Commit
e4c9bed
·
verified ·
1 Parent(s): 4c6bca9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -39,7 +39,7 @@ if not REPLICATE_API_TOKEN:
39
 
40
  # Replicate API配置
41
  REPLICATE_BASE_URL = "https://api.replicate.com/v1"
42
- DEFAULT_MODEL = "anthropic/claude-3-5-sonnet"
43
 
44
  # 全局异常处理器
45
  @app.exception_handler(Exception)
@@ -85,20 +85,23 @@ def transform_openai_to_replicate(openai_request: Dict[str, Any], model_override
85
  if prompt_parts and not prompt.endswith("\n\nAssistant:"):
86
  prompt += "\n\nAssistant:"
87
 
88
- # 确定使用的模型
89
  model = model_override or openai_request.get("model", DEFAULT_MODEL)
90
 
91
- # 模型名称映射
92
  model_mapping = {
93
- "claude-4-sonnet": "anthropic/claude-3-5-sonnet",
94
- "claude-3-sonnet": "anthropic/claude-3-sonnet-20240229",
95
- "claude-3-haiku": "anthropic/claude-3-haiku-20240307"
 
 
96
  }
97
 
98
  if model in model_mapping:
99
  model = model_mapping[model]
100
  elif not model.startswith("anthropic/"):
101
- model = f"anthropic/{model}"
 
102
 
103
  replicate_request = {
104
  "stream": openai_request.get("stream", False),
@@ -250,6 +253,18 @@ async def list_models():
250
  "created": 1677610602,
251
  "owned_by": "anthropic"
252
  },
 
 
 
 
 
 
 
 
 
 
 
 
253
  {
254
  "id": "claude-3-sonnet",
255
  "object": "model",
 
39
 
40
  # Replicate API配置
41
  REPLICATE_BASE_URL = "https://api.replicate.com/v1"
42
+ DEFAULT_MODEL = "anthropic/claude-3.5-sonnet" # 使用实际存在的模型
43
 
44
  # 全局异常处理器
45
  @app.exception_handler(Exception)
 
85
  if prompt_parts and not prompt.endswith("\n\nAssistant:"):
86
  prompt += "\n\nAssistant:"
87
 
88
+ # 确定使用的模型 - 使用正确的 Replicate 模型名称
89
  model = model_override or openai_request.get("model", DEFAULT_MODEL)
90
 
91
+ # 正确的模型名称映射(基于搜索结果)
92
  model_mapping = {
93
+ "claude-4-sonnet": "anthropic/claude-4-sonnet", # 最新的 Claude 4
94
+ "claude-3.5-sonnet": "anthropic/claude-3.5-sonnet", # Claude 3.5 Sonnet
95
+ "claude-3-sonnet": "anthropic/claude-3-sonnet", # Claude 3 Sonnet
96
+ "claude-3.5-haiku": "anthropic/claude-3.5-haiku", # Claude 3.5 Haiku
97
+ "claude-3-haiku": "anthropic/claude-3-haiku", # Claude 3 Haiku
98
  }
99
 
100
  if model in model_mapping:
101
  model = model_mapping[model]
102
  elif not model.startswith("anthropic/"):
103
+ # 默认使用 claude-3.5-sonnet
104
+ model = "anthropic/claude-3.5-sonnet"
105
 
106
  replicate_request = {
107
  "stream": openai_request.get("stream", False),
 
253
  "created": 1677610602,
254
  "owned_by": "anthropic"
255
  },
256
+ {
257
+ "id": "claude-3.5-sonnet",
258
+ "object": "model",
259
+ "created": 1677610602,
260
+ "owned_by": "anthropic"
261
+ },
262
+ {
263
+ "id": "claude-3.5-haiku",
264
+ "object": "model",
265
+ "created": 1677610602,
266
+ "owned_by": "anthropic"
267
+ },
268
  {
269
  "id": "claude-3-sonnet",
270
  "object": "model",