Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -43,25 +43,25 @@ logger = logging.getLogger(__name__)
|
|
43 |
|
44 |
# Model configuration mapping for different API requirements and limits
|
45 |
MODEL_CONFIGS = {
|
46 |
-
"DeepSeek-V3-0324": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "DeepSeek"},
|
47 |
-
"DeepSeek-R1": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "DeepSeek"},
|
48 |
-
"Meta-Llama-3.1-405B-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta"},
|
49 |
-
"Llama-3.2-90B-Vision-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta"},
|
50 |
-
"Llama-3.3-70B-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta"},
|
51 |
-
"Llama-4-Scout-17B-16E-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta"},
|
52 |
-
"Llama-4-Maverick-17B-128E-Instruct-FP8": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta"},
|
53 |
-
"gpt-4o-mini": {"max_tokens":
|
54 |
-
"gpt-4.1": {"max_tokens":
|
55 |
-
"gpt-4o": {"max_tokens":
|
56 |
-
"o3-mini": {"max_tokens":
|
57 |
-
"o1": {"max_tokens":
|
58 |
-
"o1-mini": {"max_tokens":
|
59 |
-
"o1-preview": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Anthropic"},
|
60 |
-
"Phi-4-multimodal-instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Microsoft"},
|
61 |
-
"Mistral-large-2407": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Mistral"},
|
62 |
-
"Codestral-2501": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Mistral"},
|
63 |
# Default configuration for other models
|
64 |
-
"default": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Other"}
|
65 |
}
|
66 |
|
67 |
# Try to import Streamlit Ace
|
@@ -335,14 +335,15 @@ Here's the complete Manim code:
|
|
335 |
# Get configuration for this model (or use default)
|
336 |
config = MODEL_CONFIGS.get(model_name, MODEL_CONFIGS["default"])
|
337 |
|
338 |
-
#
|
339 |
-
|
340 |
-
|
341 |
-
"
|
342 |
-
|
|
|
343 |
|
344 |
-
#
|
345 |
-
|
346 |
|
347 |
# Check if we need to specify API version
|
348 |
if config["api_version"]:
|
@@ -366,11 +367,19 @@ Here's the complete Manim code:
|
|
366 |
api_version=config["api_version"]
|
367 |
)
|
368 |
|
369 |
-
# Make the API call with the version-specific client
|
370 |
-
response = version_specific_client.complete(
|
|
|
|
|
|
|
|
|
371 |
else:
|
372 |
-
# Use the existing client
|
373 |
-
response = models["client"].complete(
|
|
|
|
|
|
|
|
|
374 |
|
375 |
# Process the response
|
376 |
completed_code = response.choices[0].message.content
|
|
|
43 |
|
44 |
# Model configuration mapping for different API requirements and limits
|
45 |
MODEL_CONFIGS = {
|
46 |
+
"DeepSeek-V3-0324": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "DeepSeek", "warning": None},
|
47 |
+
"DeepSeek-R1": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "DeepSeek", "warning": None},
|
48 |
+
"Meta-Llama-3.1-405B-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta", "warning": None},
|
49 |
+
"Llama-3.2-90B-Vision-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta", "warning": None},
|
50 |
+
"Llama-3.3-70B-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta", "warning": None},
|
51 |
+
"Llama-4-Scout-17B-16E-Instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta", "warning": None},
|
52 |
+
"Llama-4-Maverick-17B-128E-Instruct-FP8": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Meta", "warning": None},
|
53 |
+
"gpt-4o-mini": {"max_tokens": 15000, "param_name": "max_tokens", "api_version": None, "category": "OpenAI", "warning": None},
|
54 |
+
"gpt-4.1": {"max_tokens": 15000, "param_name": "max_tokens", "api_version": None, "category": "OpenAI", "warning": None},
|
55 |
+
"gpt-4o": {"max_tokens": 15000, "param_name": "max_tokens", "api_version": None, "category": "OpenAI", "warning": None},
|
56 |
+
"o3-mini": {"max_tokens": 15000, "param_name": "max_tokens", "api_version": "2024-12-01-preview", "category": "Anthropic", "warning": None},
|
57 |
+
"o1": {"max_tokens": 15000, "param_name": "max_completion_tokens", "api_version": "2024-12-01-preview", "category": "Anthropic", "warning": "Uses special parameters. Will use gpt-4o instead."},
|
58 |
+
"o1-mini": {"max_tokens": 15000, "param_name": "max_completion_tokens", "api_version": "2024-12-01-preview", "category": "Anthropic", "warning": "Uses special parameters. Will use gpt-4o instead."},
|
59 |
+
"o1-preview": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Anthropic", "warning": None},
|
60 |
+
"Phi-4-multimodal-instruct": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Microsoft", "warning": None},
|
61 |
+
"Mistral-large-2407": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Mistral", "warning": None},
|
62 |
+
"Codestral-2501": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Mistral", "warning": None},
|
63 |
# Default configuration for other models
|
64 |
+
"default": {"max_tokens": 4000, "param_name": "max_tokens", "api_version": None, "category": "Other", "warning": None}
|
65 |
}
|
66 |
|
67 |
# Try to import Streamlit Ace
|
|
|
335 |
# Get configuration for this model (or use default)
|
336 |
config = MODEL_CONFIGS.get(model_name, MODEL_CONFIGS["default"])
|
337 |
|
338 |
+
# Check if this is a model that requires max_completion_tokens
|
339 |
+
if config["param_name"] == "max_completion_tokens":
|
340 |
+
# For models requiring max_completion_tokens (Anthropic models)
|
341 |
+
st.warning(f"Model {model_name} requires special handling. Switching to gpt-4o.")
|
342 |
+
model_name = "gpt-4o"
|
343 |
+
config = MODEL_CONFIGS["gpt-4o"]
|
344 |
|
345 |
+
# Prepare common API parameters
|
346 |
+
messages = [UserMessage(prompt)]
|
347 |
|
348 |
# Check if we need to specify API version
|
349 |
if config["api_version"]:
|
|
|
367 |
api_version=config["api_version"]
|
368 |
)
|
369 |
|
370 |
+
# Make the API call with the version-specific client and normal max_tokens
|
371 |
+
response = version_specific_client.complete(
|
372 |
+
messages=messages,
|
373 |
+
model=model_name,
|
374 |
+
max_tokens=config["max_tokens"]
|
375 |
+
)
|
376 |
else:
|
377 |
+
# Use the existing client with normal max_tokens
|
378 |
+
response = models["client"].complete(
|
379 |
+
messages=messages,
|
380 |
+
model=model_name,
|
381 |
+
max_tokens=config["max_tokens"]
|
382 |
+
)
|
383 |
|
384 |
# Process the response
|
385 |
completed_code = response.choices[0].message.content
|