assistant 2.0.1b2__tar.gz → 2.0.2b2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. {assistant-2.0.1b2/assistant.egg-info → assistant-2.0.2b2}/PKG-INFO +1 -1
  2. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/__init__.py +16 -26
  3. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/agent.py +39 -5
  4. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/builtin_cmds.py +28 -33
  5. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/config.py +12 -0
  6. assistant-2.0.2b2/assistant/entry_points/run_assistant.py +24 -0
  7. assistant-2.0.2b2/assistant/listen/__init__.py +22 -0
  8. assistant-2.0.2b2/assistant/listen/interface.py +68 -0
  9. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/listen/main.py +12 -5
  10. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/main.py +209 -217
  11. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/http_client.py +87 -12
  12. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/interface.py +58 -1
  13. assistant-2.0.2b2/assistant/nlp/message.py +60 -0
  14. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/__init__.py +1 -0
  15. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/google.py +2 -1
  16. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/llama_cpp.py +2 -0
  17. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/nim.py +2 -1
  18. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/ollama.py +2 -0
  19. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/openai.py +2 -0
  20. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/openrouter.py +2 -1
  21. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/providers/vllm.py +2 -1
  22. assistant-2.0.2b2/assistant/nlp/xonsh.py +114 -0
  23. assistant-2.0.2b2/assistant/ptk_shell/bindings.py +539 -0
  24. assistant-2.0.2b2/assistant/ptk_shell/completer.py +301 -0
  25. assistant-2.0.2b2/assistant/ptk_shell/operators.py +407 -0
  26. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/shell.py +431 -845
  27. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/setup_wizard.py +46 -12
  28. assistant-2.0.2b2/assistant/tools.py +648 -0
  29. assistant-2.0.2b2/assistant/tools_worker.py +64 -0
  30. {assistant-2.0.1b2 → assistant-2.0.2b2/assistant.egg-info}/PKG-INFO +1 -1
  31. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant.egg-info/SOURCES.txt +11 -10
  32. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant.egg-info/entry_points.txt +3 -0
  33. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant.egg-info/top_level.txt +1 -0
  34. {assistant-2.0.1b2 → assistant-2.0.2b2}/setup.cfg +2 -0
  35. {assistant-2.0.1b2 → assistant-2.0.2b2}/setup.py +7 -6
  36. assistant-2.0.2b2/tests/test_config.py +335 -0
  37. assistant-2.0.2b2/tests/test_init.py +193 -0
  38. assistant-2.0.2b2/tests/test_tools.py +505 -0
  39. assistant-2.0.2b2/tests/test_utils.py +236 -0
  40. assistant-2.0.2b2/tests/test_xontrib.py +445 -0
  41. assistant-2.0.2b2/xontrib/__init__.py +1 -0
  42. assistant-2.0.2b2/xontrib/assistant.py +511 -0
  43. assistant-2.0.1b2/assistant/_execer.py +0 -204
  44. assistant-2.0.1b2/assistant/entry_points/run_assistant.py +0 -16
  45. assistant-2.0.1b2/assistant/icons.py +0 -24
  46. assistant-2.0.1b2/assistant/listen/__init__.py +0 -18
  47. assistant-2.0.1b2/assistant/listen/interface.py +0 -49
  48. assistant-2.0.1b2/assistant/procs/pipelines.py +0 -21
  49. assistant-2.0.1b2/assistant/procs/specs.py +0 -51
  50. assistant-2.0.1b2/assistant/ptk_shell/bindings.py +0 -43
  51. assistant-2.0.1b2/assistant/ptk_shell/completer.py +0 -218
  52. assistant-2.0.1b2/assistant/tools.py +0 -1749
  53. assistant-2.0.1b2/tests/test_asssistant_nl.py +0 -25
  54. assistant-2.0.1b2/tests/test_nl_robustness.py +0 -38
  55. assistant-2.0.1b2/tests/test_robustness_and_environment.py +0 -56
  56. assistant-2.0.1b2/tests/test_tools_execution.py +0 -470
  57. assistant-2.0.1b2/tests/test_xonsh_advanced_features.py +0 -61
  58. assistant-2.0.1b2/tests/test_xonsh_syntax.py +0 -228
  59. {assistant-2.0.1b2 → assistant-2.0.2b2}/LICENSE +0 -0
  60. {assistant-2.0.1b2 → assistant-2.0.2b2}/MANIFEST.in +0 -0
  61. {assistant-2.0.1b2 → assistant-2.0.2b2}/README.md +0 -0
  62. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/__main__.py +0 -0
  63. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/as_client.py +0 -0
  64. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/as_service.py +0 -0
  65. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/codecache.py +0 -0
  66. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/conditions.py +0 -0
  67. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/entry_points/__init__.py +0 -0
  68. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/execer.py +0 -0
  69. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/history.py +0 -0
  70. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/listen/__main__.py +0 -0
  71. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/memory.py +0 -0
  72. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/__init__.py +0 -0
  73. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/clear.py +0 -0
  74. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/exit.py +0 -0
  75. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/nlp/think.py +0 -0
  76. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/parser.py +0 -0
  77. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/__init__.py +0 -0
  78. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/dialogs.py +0 -0
  79. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/floats.py +0 -0
  80. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/layout.py +0 -0
  81. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/strformat_utils.py +0 -0
  82. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/styles.py +0 -0
  83. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/ptk_shell/windows.py +0 -0
  84. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/say/__init__.py +0 -0
  85. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/say/interface.py +0 -0
  86. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/time.py +0 -0
  87. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/utils.py +0 -0
  88. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/version.py +0 -0
  89. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant/vocabulary.py +0 -0
  90. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant.egg-info/dependency_links.txt +0 -0
  91. {assistant-2.0.1b2 → assistant-2.0.2b2}/assistant.egg-info/requires.txt +0 -0
  92. {assistant-2.0.1b2 → assistant-2.0.2b2}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: assistant
3
- Version: 2.0.1b2
3
+ Version: 2.0.2b2
4
4
  Summary: Your very own Assistant. Because you deserve it.
5
5
  Home-page: https://gitlab.com/waser-technologies/technologies/assistant
6
6
  Author: Danny Waser
@@ -1,7 +1,10 @@
1
1
  # from xonsh.main import setup
2
2
  import os
3
+ import warnings
4
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="webrtcvad")
5
+ warnings.filterwarnings("ignore", category=UserWarning, module="webrtcvad")
3
6
 
4
- __version__ = "2.0.1b2"
7
+ __version__ = "2.0.2b2"
5
8
 
6
9
  USERNAME = os.environ.get("USER", "root")
7
10
  HOME = os.environ.get("HOME", f"/home/{USERNAME}" if USERNAME != "root" else "/root")
@@ -22,9 +25,9 @@ SYSTEM_ROLE = """Your role is to act as a natural language interface between the
22
25
  The common Xonsh shell session is a shared Xonsh REPL when you and the user can type valid shell command and python code seamlessly in the same environment."""
23
26
 
24
27
  DEFAULT_MODELS_BY_PROVIDER = {
25
- "ollama": ["qwen3.5:latest"],
28
+ "ollama": ["qwen3.6:latest"],
26
29
  "llama_cpp": ["qwen3.5:latest"],
27
- "lmstudio": ["qwen3.5:latest"],
30
+ "lmstudio": ["qwen3.6-35b-a3bt"],
28
31
  "openrouter": ["openrouter/free"],
29
32
  "google": ["gemini-flash-lite-latest"],
30
33
  "nvidia": [
@@ -42,7 +45,7 @@ DEFAULT_MODELS_BY_PROVIDER = {
42
45
 
43
46
  DEFAULT_CONFIG_PATH = os.path.expanduser("~/.assistant/config.toml")
44
47
 
45
- # TODO: improve prompts to imporove conversation flow for agents. (act as one, understand xonsh repl properly)
48
+ # TODO: improve prompts to improve conversation flow for agents. (act as one, understand xonsh repl properly)
46
49
  DEFAULT_CONFIG = {
47
50
  "provider": {
48
51
  "ollama": {
@@ -58,7 +61,7 @@ DEFAULT_CONFIG = {
58
61
  "context_length": 256000,
59
62
  "think": False,
60
63
  "temperature": 0.1,
61
- "max_token": 50,
64
+ "max_token": 1,
62
65
  },
63
66
  },
64
67
  "agent": {
@@ -70,10 +73,10 @@ DEFAULT_CONFIG = {
70
73
  "tools": [
71
74
  "xonsh",
72
75
  "web_search",
73
- "memory_search",
74
- "memory_add",
76
+ # "memory_search",
77
+ # "memory_add",
75
78
  ],
76
- "handoffs": ["system", "web", "memory"],
79
+ # "handoffs": ["system", "web", "memory"],
77
80
  },
78
81
  "system": {
79
82
  "name": "System",
@@ -109,7 +112,11 @@ DEFAULT_CONFIG = {
109
112
  },
110
113
  },
111
114
  "web_search": {"enabled": True, "searxng_url": "http://localhost:8888"},
112
- "completion": {"enabled": True},
115
+ "completion": {
116
+ "enabled": True,
117
+ "wait_timeout": 1,
118
+ "request_timeout": (10.0, 300.0),
119
+ },
113
120
  "execution": {
114
121
  "max_turns": 50,
115
122
  "temperature": 0.1,
@@ -124,21 +131,4 @@ DEFAULT_CONFIG = {
124
131
  "sliding_window_last": 8,
125
132
  "use_summarization": True,
126
133
  },
127
- "tuis": [
128
- "sudo",
129
- "vi",
130
- "vim",
131
- "nvim",
132
- "htop",
133
- "top",
134
- "gping",
135
- "less",
136
- "more",
137
- "man",
138
- "nano",
139
- "view",
140
- "edit",
141
- "xonsh",
142
- "ipython",
143
- ],
144
134
  }
@@ -16,6 +16,7 @@ from assistant.tools import TOOL_REGISTRY
16
16
  from assistant.utils import count_messages_tokens, count_message_tokens
17
17
  from assistant import ASSISTANT_PATH
18
18
  from assistant.nlp.providers import get_provider
19
+ from assistant.nlp.xonsh import XONSH_INTRO
19
20
  from assistant.main import get_random_thinking_sentence
20
21
 
21
22
 
@@ -366,6 +367,22 @@ class Orchestrator:
366
367
  # Clear abort event at start of new request
367
368
  self._abort_event.clear()
368
369
 
370
+ # Install signal handler only right before streaming
371
+ # Only works in main thread; ignore in thread workers
372
+ import signal as _sig
373
+
374
+ def _sigint_handler(signum, frame):
375
+ for _ag in self.agents.values():
376
+ if hasattr(_ag, "close_client"):
377
+ _ag.close_client()
378
+ raise KeyboardInterrupt("Ctrl+C")
379
+
380
+ try:
381
+ _sig.signal(_sig.SIGINT, _sigint_handler)
382
+ except ValueError:
383
+ # signal only works in main thread of the main interpreter
384
+ pass
385
+
369
386
  self._emit({"type": "status", "text": "Searching memory..."})
370
387
 
371
388
  # Memory Search (if enabled)
@@ -402,6 +419,14 @@ class Orchestrator:
402
419
  # Sync the static sys prompt once per session if possible
403
420
  # Cache for system prompt tokens to avoid re-calculating identical blocks
404
421
  while total_turns < max_turns:
422
+ # Check for abort at start of each turn
423
+ if self._abort_event.is_set():
424
+ self._abort_event.clear()
425
+ context_messages.append(
426
+ {"role": "assistant", "content": "Aborted by user."}
427
+ )
428
+ break
429
+
405
430
  _turn_t0 = time.perf_counter()
406
431
  agent = self.agents.get(active_agent_id)
407
432
  if not agent:
@@ -416,7 +441,7 @@ class Orchestrator:
416
441
  )
417
442
 
418
443
  # Construct system prompt (instructions + env + memory)
419
- sys_prompt = agent.instructions + "\n\n" + env_summary
444
+ sys_prompt = agent.instructions + f"\n{XONSH_INTRO}\n" + env_summary
420
445
  if memory_str:
421
446
  sys_prompt += memory_str
422
447
 
@@ -519,7 +544,9 @@ class Orchestrator:
519
544
  if _is_debug:
520
545
  sys.stderr.write(f"[ERROR] API Call failed: {e}\n")
521
546
  # Check if this is an abort
522
- if "Aborted" in str(e) or isinstance(e, KeyboardInterrupt):
547
+ if isinstance(e, KeyboardInterrupt):
548
+ raise
549
+ if "Aborted" in str(e):
523
550
  if _is_debug:
524
551
  sys.stderr.write(
525
552
  "[DEBUG] Abort exception caught, returning empty response\n"
@@ -737,7 +764,7 @@ class Orchestrator:
737
764
  temp_content = ""
738
765
 
739
766
  # 3. Tool calls
740
- if delta.tool_calls:
767
+ if hasattr(delta, "tool_calls") and delta.tool_calls:
741
768
  for tc_delta in delta.tool_calls:
742
769
  idx = int(getattr(tc_delta, "index", 0) or 0)
743
770
  while len(tool_calls) <= idx:
@@ -830,7 +857,14 @@ class Orchestrator:
830
857
  "args": args,
831
858
  }
832
859
  )
860
+
833
861
  res = TOOL_REGISTRY[fn_name]["fn"](args)
862
+
863
+ # Check for abort after tool execution
864
+ if self._abort_event.is_set():
865
+ self._abort_event.clear()
866
+ return None
867
+
834
868
  self._emit(
835
869
  {
836
870
  "type": "tool_output",
@@ -839,12 +873,12 @@ class Orchestrator:
839
873
  "is_error": res["is_error"],
840
874
  }
841
875
  )
842
-
876
+
843
877
  tool_msg = {
844
878
  "role": "tool",
845
879
  "tool_call_id": t.id,
846
880
  "name": fn_name,
847
- "content": res["content"],
881
+ "content": res["content"] or "",
848
882
  }
849
883
  # Optimization: populate cache immediately
850
884
  tool_msg["_tokens"] = count_message_tokens(tool_msg)
@@ -185,7 +185,7 @@ Run the following command:
185
185
  pip install -r stt-listen
186
186
  ```
187
187
  """
188
- _log_md(shell, output)
188
+ shell.log_error(output)
189
189
  return 0
190
190
 
191
191
  if not shell.kernel_interface.listen_interface.is_asr_server_up():
@@ -200,20 +200,16 @@ To start the server, run the following command (outside of Assistant in a separa
200
200
  uvicorn listen.Wav2Vec.as_service:app --port 5063
201
201
  ```
202
202
  """
203
- _log_md(shell, output)
203
+ shell.log_error(output)
204
204
  return 0
205
205
 
206
206
  try:
207
207
  if args[0] == "start":
208
- try:
209
- shell.start_listening()
210
- except (KeyboardInterrupt, EOFError):
211
- shell.stop_listening()
212
- return 0
208
+ shell.start_listening()
213
209
  return 0
214
210
  elif args[0] == "stop":
215
211
  shell.stop_listening()
216
- _log_md(shell, "# Stopped listening")
212
+ _log_md(shell, "Stopped listening.")
217
213
  return 0
218
214
  else:
219
215
  n = int(args[0])
@@ -223,6 +219,7 @@ uvicorn listen.Wav2Vec.as_service:app --port 5063
223
219
  _log_md(shell, "Usage: `listen [OPTIONS]... [INT]...`")
224
220
  return 0
225
221
  else:
222
+ shell.kernel_interface.spinner.start("Preparing to listen...")
226
223
  if not shell.kernel_interface.is_asr:
227
224
  output = """# Module Not Found Error
228
225
  To speak with Assistant, you need to install the listen module.
@@ -248,22 +245,30 @@ uvicorn listen.Wav2Vec.as_service:app --port 5063
248
245
  """
249
246
  _log_md(shell, output)
250
247
  return 0
251
- shell.kernel_interface.spinner.text = "Listening..."
252
- shell.kernel_interface.spinner.start()
253
- query = shell.kernel_interface.listen_interface.listen()
254
- shell.kernel_interface.spinner.stop()
255
- shell.kernel_interface.spinner.info("Stopped listening.")
256
- if query:
257
- from rich.markdown import Markdown
258
-
259
- shell.log_query(Markdown(f"> {query}"))
260
- answer = shell.kernel_interface.session_assistant(query)
261
- if answer:
262
- shell.say(answer)
248
+ # Start spinner before listening
249
+ shell.kernel_interface.spinner.start("Listening...")
250
+ try:
251
+ query = shell.kernel_interface.listen_interface.listen()
252
+ # Stop spinner and show stopped message
253
+ shell.kernel_interface.spinner.stop()
254
+ shell.kernel_interface.spinner.info("Stopped listening.")
255
+
256
+ if query:
257
+ shell.log_query(f"{query}")
258
+ try:
259
+ answer = shell.kernel_interface.assistant(query)
260
+ if answer:
261
+ shell.say(answer)
262
+ # else:
263
+ # shell.log_error("Assistant failed to reply.")
264
+ except Exception as e:
265
+ shell.kernel_interface.spinner.stop()
266
+ shell.log_error(e)
263
267
  else:
264
- _log_md(shell, "Assistant failed to reply.")
265
- else:
266
- _log_md(shell, f"# Nothing heard\nTranscript: '{query}'")
268
+ _log_md(shell, f"# Nothing heard\nTranscript: '{query}'")
269
+ except Exception as e:
270
+ shell.kernel_interface.spinner.stop()
271
+ _log_md(shell, f"# Error\n{str(e)}")
267
272
  return 0
268
273
 
269
274
 
@@ -766,16 +771,6 @@ BUILTIN_COMMANDS = {
766
771
  "description": "Text-to-speech output (requires TTS module)",
767
772
  "usage": "Usage: say [stop|STRING...]",
768
773
  },
769
- "exit": {
770
- "fn": None,
771
- "description": "Exit the shell",
772
- "usage": "Usage: exit",
773
- },
774
- "clear": {
775
- "fn": None,
776
- "description": "Clear the screen",
777
- "usage": "Usage: clear",
778
- },
779
774
  "echo": {
780
775
  "fn": echo_fn,
781
776
  "description": "Echo the STRING(s) to standard output",
@@ -225,6 +225,18 @@ class Config:
225
225
  "enabled", DEFAULT_CONFIG["completion"]["enabled"]
226
226
  )
227
227
 
228
+ @property
229
+ def completion_wait_timeout(self) -> float:
230
+ return self.raw.get("completion", {}).get(
231
+ "wait_timeout", DEFAULT_CONFIG["completion"]["wait_timeout"]
232
+ )
233
+
234
+ @property
235
+ def completion_request_timeout(self) -> tuple:
236
+ return self.raw.get("completion", {}).get(
237
+ "request_timeout", DEFAULT_CONFIG["completion"]["request_timeout"]
238
+ )
239
+
228
240
 
229
241
  _config_instance = None
230
242
  _config_path: Optional[str] = None
@@ -0,0 +1,24 @@
1
+ import signal
2
+ import sys
3
+
4
+
5
+ def _handle_sigint(signum, frame):
6
+ """Handle SIGINT during import by exiting immediately."""
7
+ sys.exit(130)
8
+
9
+
10
+ signal.signal(signal.SIGINT, _handle_sigint)
11
+
12
+ from assistant.main import main
13
+
14
+
15
+ def run():
16
+ try:
17
+ exit_code = main()
18
+ sys.exit(exit_code)
19
+ except SystemExit as e:
20
+ sys.exit(e.code if e.code is not None else 0)
21
+
22
+
23
+ if __name__ == "__main__":
24
+ run()
@@ -0,0 +1,22 @@
1
+ import sys
2
+
3
+ import warnings
4
+ with warnings.catch_warnings():
5
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="webrtcvad")
6
+ warnings.filterwarnings("ignore", category=UserWarning, module="webrtcvad")
7
+ try:
8
+ import listen
9
+ except (ModuleNotFoundError, ImportError) as e:
10
+ # print(e)
11
+ # print("To speak with Assistant, you need to install the listen module.")
12
+ # print("Run the following command:\n```shell\npip install -r stt-listen\n```")
13
+ raise e
14
+ # sys.exit(1)
15
+
16
+ if __name__ == "__main__":
17
+ from assistant.listen.main import main
18
+
19
+ try:
20
+ main()
21
+ except KeyboardInterrupt:
22
+ sys.exit(1)
@@ -0,0 +1,68 @@
1
+ import warnings
2
+ import threading
3
+
4
+ with warnings.catch_warnings():
5
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="webrtcvad")
6
+ warnings.filterwarnings("ignore", category=UserWarning, module="webrtcvad")
7
+ import requests
8
+
9
+ disclamer = """To speak with Assistant, you need to install the listen module.
10
+ Run the following command:
11
+ ```shell
12
+ pip install -r stt-listen
13
+ ```"""
14
+
15
+ try:
16
+ from listen import mic
17
+ except (ModuleNotFoundError, ImportError) as e:
18
+ e.msg = disclamer
19
+ raise e
20
+
21
+
22
+ class ListenInterface:
23
+ asr_host = "localhost"
24
+ asr_port = "5063"
25
+
26
+ def __init__(self, asr_host=asr_host, asr_port=asr_port, **kwargs):
27
+ self.asr_host = asr_host
28
+ self.asr_port = asr_port
29
+ self._current_mic = None
30
+
31
+ for k, v in kwargs.items():
32
+ setattr(self, k, v)
33
+
34
+ def is_asr_server_up(self):
35
+ try:
36
+ r = requests.get(f"http://{self.asr_host}:{self.asr_port}")
37
+ if r.status_code == 200:
38
+ return True
39
+ else:
40
+ return False
41
+ except (requests.ConnectionError, Exception):
42
+ return False
43
+
44
+ def listen(self):
45
+ """Listen for one utterance and return transcript."""
46
+ try:
47
+ source = mic.Microphone()
48
+ self._current_mic = source
49
+ source.record()
50
+ query = source.transcribe_until_silence()
51
+ source.stop_record()
52
+ try:
53
+ if hasattr(source, "vad_audio") and source.vad_audio is not None:
54
+ if hasattr(source.vad_audio, "pa"):
55
+ source.vad_audio.pa.terminate()
56
+ source.vad_audio.destroy()
57
+ except Exception:
58
+ pass
59
+ return query
60
+ except (KeyboardInterrupt, EOFError) as e:
61
+ raise e
62
+ finally:
63
+ self._current_mic = None
64
+
65
+ def stop(self):
66
+ """Stop the current listening operation."""
67
+ if self._current_mic is not None:
68
+ self._current_mic.stop_listening()
@@ -1,10 +1,17 @@
1
- import os, sys
1
+ import os
2
+ import sys
2
3
  import json
3
4
 
4
- # import websockets
5
- import asyncio
6
- import signal
7
- from time import sleep
5
+ import warnings
6
+ # Suppress pkg_resources deprecation warning from webrtcvad
7
+ with warnings.catch_warnings():
8
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="webrtcvad")
9
+ warnings.filterwarnings("ignore", category=UserWarning, module="webrtcvad")
10
+
11
+ # import websockets
12
+ import asyncio
13
+ import signal
14
+ from time import sleep
8
15
 
9
16
  # from websockets.exceptions import ConnectionClosedOK
10
17
  from rich.console import Console