windows timed input fix
frdel committed
Jul 12, 2024 at 10:44 UTC
d2374bfe699aad59f82a57c5106ed1be8f86a7bf
1 file changed
+17
-14
main.py
+17
-14
@@ -1,4 +1,3 @@
1
-import signal
1
import threading, time, models, os
2
from ansio import application_keypad, mouse_input, raw_input
3
from ansio.input import InputEvent, get_input_event
@@ -13,7 +12,9 @@ os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
12
13
14
def initialize():
16
- # chat model used by agents
15
+
16
+ # main chat model used by agents (smarter, more accurate)
17
+
18
# chat_llm = models.get_groq_llama70b(temperature=0.2)
19
# chat_llm = models.get_groq_llama70b_json(temperature=0.2)
20
# chat_llm = models.get_groq_llama8b(temperature=0.2)
@@ -30,12 +31,13 @@ def initialize():
31
# chat_llm = models.get_ollama(model_name="qwen:14b")
32
chat_llm = models.get_google_chat()
33
33
- utility_llm = models.get_anthropic_haiku(temperature=0)
34
35
+ # utility model used for helper functions (cheaper, faster)
36
+ utility_llm = models.get_anthropic_haiku(temperature=0)
37
38
# embedding model used for memory
37
- # embedding_llm = models.get_embedding_openai()
38
- embedding_llm = models.get_embedding_hf()
39
+ embedding_llm = models.get_embedding_openai()
40
+ # embedding_llm = models.get_embedding_hf()
41
42
# agent configuration
43
config = AgentConfig(
@@ -149,18 +151,19 @@ def capture_keys():
151
152
# User input with timeout
153
def timeout_input(prompt, timeout=10):
152
- def alarm_handler(signum, frame):
153
- raise TimeoutError()
154
+ result = []
155
+
156
+ def get_input():
157
+ result[0] = input(prompt)
158
155
- signal.signal(signal.SIGALRM, alarm_handler)
156
- signal.alarm(timeout)
159
+ input_thread = threading.Thread(target=get_input)
160
+ input_thread.start()
161
+ input_thread.join(timeout)
162
158
- try:
159
- return input(prompt)
160
- except TimeoutError:
163
+ if input_thread.is_alive():
164
return ""
162
- finally:
163
- signal.alarm(0) # Cancel the alarm
165
+ else:
166
+ return result[0]
167
168
if __name__ == "__main__":
169
print("Initializing framework...")