Spaces:
Sleeping
Sleeping
Chunhua Liao
commited on
Commit
·
27a9663
1
Parent(s):
c64b342
Remove ALLOWED_MODELS_PRODUCTION and use filter_free_models for all Hugging Face Spaces model filtering
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import logging
|
|
8 |
# Import the existing app components
|
9 |
from app.models import ResearchGoal, ContextMemory
|
10 |
from app.agents import SupervisorAgent
|
11 |
-
from app.utils import logger, is_huggingface_space, get_deployment_environment
|
12 |
from app.tools.arxiv_search import ArxivSearchTool
|
13 |
import requests
|
14 |
|
@@ -32,17 +32,6 @@ def fetch_available_models():
|
|
32 |
logger.info(f"Detected deployment environment: {deployment_env}")
|
33 |
logger.info(f"Is Hugging Face Spaces: {is_hf_spaces}")
|
34 |
|
35 |
-
# Define cost-effective models for production deployment
|
36 |
-
ALLOWED_MODELS_PRODUCTION = [
|
37 |
-
"google/gemini-2.0-flash-001",
|
38 |
-
"google/gemini-flash-1.5",
|
39 |
-
"openai/gpt-3.5-turbo",
|
40 |
-
"anthropic/claude-3-haiku",
|
41 |
-
"meta-llama/llama-3.1-8b-instruct",
|
42 |
-
"mistralai/mistral-7b-instruct",
|
43 |
-
"microsoft/phi-3-mini-4k-instruct"
|
44 |
-
]
|
45 |
-
|
46 |
try:
|
47 |
response = requests.get("https://openrouter.ai/api/v1/models", timeout=10)
|
48 |
response.raise_for_status()
|
@@ -51,11 +40,14 @@ def fetch_available_models():
|
|
51 |
# Extract all model IDs
|
52 |
all_models = sorted([model.get("id") for model in models_data if model.get("id")])
|
53 |
|
|
|
|
|
|
|
54 |
# Apply filtering based on environment
|
55 |
if is_hf_spaces:
|
56 |
-
#
|
57 |
-
available_models =
|
58 |
-
logger.info(f"Hugging Face Spaces: Filtered to {len(available_models)}
|
59 |
else:
|
60 |
# Use all models in local/development environment
|
61 |
available_models = all_models
|
@@ -64,7 +56,11 @@ def fetch_available_models():
|
|
64 |
except Exception as e:
|
65 |
logger.error(f"Failed to fetch models from OpenRouter: {e}")
|
66 |
# Fallback to safe defaults
|
67 |
-
|
|
|
|
|
|
|
|
|
68 |
|
69 |
return available_models
|
70 |
|
|
|
8 |
# Import the existing app components
|
9 |
from app.models import ResearchGoal, ContextMemory
|
10 |
from app.agents import SupervisorAgent
|
11 |
+
from app.utils import logger, is_huggingface_space, get_deployment_environment, filter_free_models
|
12 |
from app.tools.arxiv_search import ArxivSearchTool
|
13 |
import requests
|
14 |
|
|
|
32 |
logger.info(f"Detected deployment environment: {deployment_env}")
|
33 |
logger.info(f"Is Hugging Face Spaces: {is_hf_spaces}")
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
try:
|
36 |
response = requests.get("https://openrouter.ai/api/v1/models", timeout=10)
|
37 |
response.raise_for_status()
|
|
|
40 |
# Extract all model IDs
|
41 |
all_models = sorted([model.get("id") for model in models_data if model.get("id")])
|
42 |
|
43 |
+
# Create filtered free models list
|
44 |
+
free_models = filter_free_models(all_models)
|
45 |
+
|
46 |
# Apply filtering based on environment
|
47 |
if is_hf_spaces:
|
48 |
+
# Use only free models for Hugging Face Spaces
|
49 |
+
available_models = free_models
|
50 |
+
logger.info(f"Hugging Face Spaces: Filtered to {len(available_models)} free models")
|
51 |
else:
|
52 |
# Use all models in local/development environment
|
53 |
available_models = all_models
|
|
|
56 |
except Exception as e:
|
57 |
logger.error(f"Failed to fetch models from OpenRouter: {e}")
|
58 |
# Fallback to safe defaults
|
59 |
+
if is_hf_spaces:
|
60 |
+
# Use a known free model as fallback
|
61 |
+
available_models = ["google/gemini-2.0-flash-001:free"]
|
62 |
+
else:
|
63 |
+
available_models = ["google/gemini-2.0-flash-001"]
|
64 |
|
65 |
return available_models
|
66 |
|