Spaces:
Running
Running
updated model selector
Browse files- src/config/model_selector.py +25 -16
src/config/model_selector.py
CHANGED
@@ -1,21 +1,30 @@
|
|
1 |
from src.utils.runtime_selector import detect_runtime_environment
|
|
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
4 |
load_dotenv()
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
"
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from src.utils.runtime_selector import detect_runtime_environment
|
2 |
+
from cost_benefit import get_best_model
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
load_dotenv()
|
6 |
|
7 |
+
def choose_best_model(return_full=False):
|
8 |
+
env = detect_runtime_environment()
|
9 |
+
print(f"[INFO] Runtime Environment: {env}")
|
10 |
+
|
11 |
+
weights = {
|
12 |
+
"w_size": 0.1,
|
13 |
+
"w_token_cost": 100,
|
14 |
+
"w_speed": 0.5
|
15 |
+
}
|
16 |
+
|
17 |
+
result = get_best_model(weights, env)
|
18 |
+
|
19 |
+
if isinstance(result, str) or not result.get("model"):
|
20 |
+
if env == "cpu-local":
|
21 |
+
if os.getenv("GEMINI_KEY"):
|
22 |
+
print("[INFO] Falling back to Gemini for cpu-local.")
|
23 |
+
return {"model": "gemini-2.0-flash"} if return_full else "gemini-2.0-flash"
|
24 |
+
else:
|
25 |
+
print("[WARN] GOOGLE_API_KEY missing. Falling back to llama3.2.")
|
26 |
+
return {"model": "llama3.2"} if return_full else "llama3.2"
|
27 |
+
return {"model": "llama3.2"} if return_full else "llama3.2"
|
28 |
+
|
29 |
+
print(f"[INFO] Auto-selected model: {result['model']}")
|
30 |
+
return result if return_full else result["model"]
|