(no commit message)
This commit is contained in:
51
utils/model_selection.py
Normal file
51
utils/model_selection.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""Model selection utilities for nanocode."""
|
||||
|
||||
import os
|
||||
from .display import RESET, BOLD, DIM, BLUE, GREEN, RED
|
||||
|
||||
# Available OpenRouter models
|
||||
AVAILABLE_MODELS = {
|
||||
"1": ("Claude 3.5 Sonnet", "anthropic/claude-3.5-sonnet"),
|
||||
"2": ("Claude 3.5 Haiku", "anthropic/claude-3.5-haiku"),
|
||||
"3": ("GPT-4o", "openai/gpt-4o"),
|
||||
"4": ("GPT-4o mini", "openai/gpt-4o-mini"),
|
||||
"5": ("Gemini Pro 1.5", "google/gemini-pro-1.5"),
|
||||
"6": ("Llama 3.1 405B", "meta-llama/llama-3.1-405b-instruct"),
|
||||
"7": ("DeepSeek V3", "deepseek/deepseek-chat"),
|
||||
"8": ("Qwen 2.5 72B", "qwen/qwen-2.5-72b-instruct"),
|
||||
}
|
||||
|
||||
|
||||
def select_model():
|
||||
"""Interactive model selection or use environment variable."""
|
||||
# Check environment variable first
|
||||
model_env = os.getenv("MODEL")
|
||||
if model_env:
|
||||
print(f"{GREEN}⏺ Using model from environment: {model_env}{RESET}")
|
||||
return model_env
|
||||
|
||||
print(f"\n{BOLD}Select a model:{RESET}")
|
||||
for key, (name, model_id) in AVAILABLE_MODELS.items():
|
||||
print(f" {BLUE}{key}{RESET}. {name} ({DIM}{model_id}{RESET})")
|
||||
print(f" {BLUE}c{RESET}. Custom model (enter manually)")
|
||||
|
||||
while True:
|
||||
try:
|
||||
choice = input(f"\n{BOLD}{BLUE}❯{RESET} Enter choice (1-8 or c): ").strip().lower()
|
||||
|
||||
if choice in AVAILABLE_MODELS:
|
||||
name, model_id = AVAILABLE_MODELS[choice]
|
||||
print(f"{GREEN}⏺ Selected: {name}{RESET}")
|
||||
return model_id
|
||||
elif choice == "c":
|
||||
custom_model = input(f"{BOLD}{BLUE}❯{RESET} Enter model ID (e.g., openai/gpt-4): ").strip()
|
||||
if custom_model:
|
||||
print(f"{GREEN}⏺ Selected custom model: {custom_model}{RESET}")
|
||||
return custom_model
|
||||
else:
|
||||
print(f"{RED}⏺ Invalid model ID{RESET}")
|
||||
else:
|
||||
print(f"{RED}⏺ Invalid choice. Please enter 1-8 or c{RESET}")
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print(f"\n{RED}⏺ Model selection cancelled{RESET}")
|
||||
exit(1)
|
||||
Reference in New Issue
Block a user