-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_model.py
More file actions
executable file
·115 lines (96 loc) · 3.9 KB
/
switch_model.py
File metadata and controls
executable file
·115 lines (96 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
"""
Model switching utility for awesh
"""
import os
import sys
from pathlib import Path
def get_config_path():
"""Get the path to the awesh config file"""
home = Path.home()
return home / '.aweshrc'
def load_config():
"""Load current configuration"""
config_path = get_config_path()
config = {}
if config_path.exists():
with open(config_path, 'r') as f:
for line in f:
line = line.strip()
if line and '=' in line and not line.startswith('#'):
key, value = line.split('=', 1)
config[key.strip()] = value.strip()
return config
def save_config(config):
"""Save configuration to file"""
config_path = get_config_path()
with open(config_path, 'w') as f:
f.write("# awesh configuration file\n\n")
f.write("# Verbose level: 0 = silent, 1 = normal, 2 = debug\n")
f.write("VERBOSE=0\n\n")
# AI Provider and Model
f.write(f"# Default to OpenRouter with Mistral\n")
f.write(f"AI_PROVIDER={config.get('AI_PROVIDER', 'openrouter')}\n")
f.write(f"MODEL={config.get('MODEL', 'mistralai/mistral-small-3.1-24b-instruct:free')}\n\n")
# API Keys
if 'OPENROUTER_API_KEY' in config:
f.write(f"# OpenRouter API key\n")
f.write(f"OPENROUTER_API_KEY={config['OPENROUTER_API_KEY']}\n\n")
if 'OPENAI_API_KEY' in config:
f.write(f"# OpenAI API key (fallback for free models)\n")
f.write(f"OPENAI_API_KEY={config['OPENAI_API_KEY']}\n\n")
if 'OPENAI_FREE_MODEL' in config:
f.write(f"# Free OpenAI model as fallback\n")
f.write(f"OPENAI_FREE_MODEL={config['OPENAI_FREE_MODEL']}\n")
def switch_to_openrouter_mistral():
"""Switch to OpenRouter with Mistral"""
config = load_config()
config['AI_PROVIDER'] = 'openrouter'
config['MODEL'] = 'mistralai/mistral-small-3.1-24b-instruct:free'
save_config(config)
print("✅ Switched to OpenRouter with Mistral (free)")
def switch_to_openai_free():
"""Switch to OpenAI free model"""
config = load_config()
config['AI_PROVIDER'] = 'openai'
config['MODEL'] = 'gpt-3.5-turbo'
save_config(config)
print("✅ Switched to OpenAI gpt-3.5-turbo (free)")
def switch_to_openai_gpt5():
"""Switch to OpenAI GPT-5"""
config = load_config()
config['AI_PROVIDER'] = 'openai'
config['MODEL'] = 'gpt-5'
save_config(config)
print("✅ Switched to OpenAI GPT-5")
def show_current_config():
"""Show current configuration"""
config = load_config()
print("Current awesh configuration:")
print(f" AI Provider: {config.get('AI_PROVIDER', 'not set')}")
print(f" Model: {config.get('MODEL', 'not set')}")
print(f" OpenRouter API Key: {'✅ Set' if 'OPENROUTER_API_KEY' in config else '❌ Not set'}")
print(f" OpenAI API Key: {'✅ Set' if 'OPENAI_API_KEY' in config else '❌ Not set'}")
def main():
if len(sys.argv) < 2:
print("awesh model switcher")
print("Usage:")
print(" python3 switch_model.py mistral - Switch to OpenRouter Mistral (free)")
print(" python3 switch_model.py openai - Switch to OpenAI gpt-3.5-turbo (free)")
print(" python3 switch_model.py gpt5 - Switch to OpenAI GPT-5")
print(" python3 switch_model.py status - Show current configuration")
return
command = sys.argv[1].lower()
if command == 'mistral':
switch_to_openrouter_mistral()
elif command == 'openai':
switch_to_openai_free()
elif command == 'gpt5' or command == 'gpt-5':
switch_to_openai_gpt5()
elif command == 'status':
show_current_config()
else:
print(f"Unknown command: {command}")
print("Use 'mistral', 'openai', 'gpt5', or 'status'")
if __name__ == '__main__':
main()