UlukaDev commited on
Commit
e5ee1f0
·
verified ·
1 Parent(s): db12dcf

Upload moe_driver.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. moe_driver.py +36 -1
moe_driver.py CHANGED
@@ -32,6 +32,37 @@ SYSTEM = {0: CALC, 1: CALC} # per-id system prompt; extend later
32
  SERVER_DOWN_HINT = ("\nThe AI server isn't running. "
33
  "Double-click START HERE.bat first, then try again.")
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  print("Loading router + embedder...")
36
  embedder = SentenceTransformer("all-MiniLM-L6-v2")
37
  router = joblib.load(hf_hub_download(ROUTER, "router.joblib"))
@@ -73,7 +104,7 @@ def answer(q: str) -> tuple[int, str]:
73
  resp = requests.post(f"{SERVER}/v1/chat/completions", json={
74
  "messages": [{"role": "system", "content": SYSTEM[idx]},
75
  {"role": "user", "content": q}],
76
- "max_tokens": 384, "temperature": 0.0, "stream": True,
77
  }, stream=True, timeout=600)
78
  resp.raise_for_status()
79
 
@@ -118,6 +149,7 @@ if __name__ == "__main__":
118
  print(" Convert 1994 to Roman numerals")
119
  print("\033[91mTip: press Ctrl+C to stop an answer early.\033[0m "
120
  "Close the window when you are done.")
 
121
 
122
  while True:
123
  try:
@@ -126,6 +158,9 @@ if __name__ == "__main__":
126
  break
127
  if not q:
128
  continue
 
 
 
129
  try:
130
  answer(q)
131
  except KeyboardInterrupt:
 
32
  SERVER_DOWN_HINT = ("\nThe AI server isn't running. "
33
  "Double-click START HERE.bat first, then try again.")
34
 
35
+ DEFAULT_MAX_TOKENS = 384
36
+ max_tokens = DEFAULT_MAX_TOKENS
37
+
38
+
39
+ def handle_command(cmd: str) -> None:
40
+ """Handle a /command typed at the prompt. Never raises."""
41
+ global max_tokens
42
+ parts = cmd.split()
43
+ if parts[0].lower() != "/limit":
44
+ print("Unknown command. Available: /limit N "
45
+ "(sets the max answer length, default "
46
+ f"{DEFAULT_MAX_TOKENS})")
47
+ return
48
+ if len(parts) == 1:
49
+ print(f"Current output limit: {max_tokens} tokens. "
50
+ f"Usage: /limit 200")
51
+ return
52
+ try:
53
+ n = int(parts[1])
54
+ except ValueError:
55
+ print(f"'{parts[1]}' is not a number. Usage: /limit 200")
56
+ return
57
+ if n < 16 or n > 4096:
58
+ print("Please pick a limit between 16 and 4096.")
59
+ return
60
+ if n < 150:
61
+ print("Warning: below ~150, long correct answers may get cut off "
62
+ f"before they finish — {DEFAULT_MAX_TOKENS} is the safe default.")
63
+ max_tokens = n
64
+ print(f"Output limit set to {max_tokens} tokens.")
65
+
66
  print("Loading router + embedder...")
67
  embedder = SentenceTransformer("all-MiniLM-L6-v2")
68
  router = joblib.load(hf_hub_download(ROUTER, "router.joblib"))
 
104
  resp = requests.post(f"{SERVER}/v1/chat/completions", json={
105
  "messages": [{"role": "system", "content": SYSTEM[idx]},
106
  {"role": "user", "content": q}],
107
+ "max_tokens": max_tokens, "temperature": 0.0, "stream": True,
108
  }, stream=True, timeout=600)
109
  resp.raise_for_status()
110
 
 
149
  print(" Convert 1994 to Roman numerals")
150
  print("\033[91mTip: press Ctrl+C to stop an answer early.\033[0m "
151
  "Close the window when you are done.")
152
+ print(f"Type /limit 200 to shorten answers (default {DEFAULT_MAX_TOKENS}).")
153
 
154
  while True:
155
  try:
 
158
  break
159
  if not q:
160
  continue
161
+ if q.startswith("/"):
162
+ handle_command(q)
163
+ continue
164
  try:
165
  answer(q)
166
  except KeyboardInterrupt: