-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
93 lines (73 loc) · 2.4 KB
/
utils.py
File metadata and controls
93 lines (73 loc) · 2.4 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
# utils.py - Librería compartida para GCM
import os
import sys
import platform
import subprocess
DEFAULT_EMOJIS = {
'windows': '🪟',
'macos': '🍎',
'linux': '🐧',
'cygwin': '🪟',
'git bash': '🪟',
'unknown': '❓'
}
ENVIRONMENT_EMOJI = '🌐'
USAGE_EMOJI = '📊'
PROMPT_EMOJI = '📝'
RESPONSE_EMOJI = '💬'
TOTAL_EMOJI = '🧮'
EXPENSIVE_EMOJI = '💸'
CHEAP_EMOJI = '💵'
ENERGY_EMOJI = '🔌'
def detect_environment(emojis=None):
emojis = emojis or DEFAULT_EMOJIS
system = platform.system().lower()
term = os.environ.get('TERM', '').lower()
shell = os.environ.get('SHELL', '').lower()
msystem = os.environ.get('MSYSTEM', '').lower()
ostype = os.environ.get('OSTYPE', '').lower()
if 'darwin' in ostype or system == 'darwin':
return 'MACOS', emojis.get('macos', '🍎')
elif 'linux' in ostype or system == 'linux':
return 'LINUX', emojis.get('linux', '🐧')
elif 'cygwin' in ostype or 'cygwin' in term or 'cygwin' in shell:
return 'CYGWIN', emojis.get('cygwin', '🪟')
elif 'msys' in ostype or 'mingw' in ostype or 'mingw' in msystem:
return 'GITBASH', emojis.get('git bash', '🪟')
elif system == 'windows':
return 'WINDOWS', emojis.get('windows', '🪟')
else:
return 'UNKNOWN', emojis.get('unknown', '❓')
def format_usage(usage_data):
if not usage_data:
return ""
prompt = usage_data.get('prompt_tokens', 0)
completion = usage_data.get('completion_tokens', 0)
total = usage_data.get('total_tokens', 0)
return f"{USAGE_EMOJI} Tokens used: {PROMPT_EMOJI} Prompt={prompt}, " \
f"{RESPONSE_EMOJI} Response={completion}, " \
f"{TOTAL_EMOJI} Total={total}"
def get_cost(USE_OLLAMA, MODEL_TIER):
if USE_OLLAMA:
return ENERGY_EMOJI
if MODEL_TIER == "cheap":
return CHEAP_EMOJI
return EXPENSIVE_EMOJI
def get_commit_count():
try:
result = subprocess.run(
["git", "rev-list", "--count", "HEAD"],
capture_output=True,
text=True,
check=True
)
count = int(result.stdout.strip())
return count
except Exception:
return 0
def print_inline(message):
sys.stdout.write(message)
sys.stdout.flush()
if __name__ == "__main__":
env, emoji = detect_environment()
print(f"Detected environment: {ENVIRONMENT_EMOJI} {env} {emoji}")