ASUllmAPI 2.0.4__tar.gz → 2.0.5__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.
@@ -3,6 +3,7 @@ from concurrent.futures import ThreadPoolExecutor
3
3
  import time
4
4
  import json
5
5
  import asyncio
6
+ import sys
6
7
 
7
8
 
8
9
  def begin_task_execution(async_func):
@@ -13,17 +14,31 @@ def begin_task_execution(async_func):
13
14
  If an event loop doesn't exist, it reverts back to existing asyncio logic.
14
15
  """
15
16
  def wrap(*args, **kwargs):
16
- try:
17
- asyncio.get_running_loop() # Triggers RuntimeError if no running event loop
18
- # Create a separate thread so we can block before returning
17
+ # It is safer to use a if/else statement than try/except since
18
+ # the underlying code we wrap our function around can also raise RuntimeErrors.
19
+ # When this happens, multiple asyncio.run() executions occur, which is dangerous.
20
+ if is_jupyter():
19
21
  with ThreadPoolExecutor(1) as pool:
20
22
  result = pool.submit(lambda: asyncio.run(async_func(*args, **kwargs))).result()
21
- except RuntimeError:
23
+ else:
22
24
  result = asyncio.run(async_func(*args, **kwargs))
23
25
  return result
24
26
  return wrap
25
27
 
26
28
 
29
+ def is_jupyter():
30
+ try:
31
+ # Check if 'IPython' is in sys.modules
32
+ if 'IPython' in sys.modules:
33
+ from IPython import get_ipython
34
+ # Check if we're in an IPython environment
35
+ if get_ipython() is not None:
36
+ return True
37
+ except ImportError:
38
+ pass
39
+ return False
40
+
41
+
27
42
  def load_json_buffer(string):
28
43
  try:
29
44
  return json.loads(string)
@@ -98,15 +98,6 @@ async def interact_with_websocket(uri: str, queue: asyncio.Queue,
98
98
  queue.task_done()
99
99
  # END - QUERY QUEUE LOOP
100
100
  except (asyncio.TimeoutError, websockets.ConnectionClosed, Exception) as exc:
101
- time.sleep(reconnect_timeout_secs)
102
- # If the query is already complete, we don't want to increment the error count
103
- if response_payloads[qid]["success"] == 0:
104
- error_ct += 1
105
- # Reset buffer stream so that you don't get messed by pre-existing data.
106
- response_payloads[qid]["response"] = ""
107
- else:
108
- logging.info(f"Query ID {qid} completed...")
109
- queue.task_done()
110
101
  if isinstance(exc, asyncio.TimeoutError):
111
102
  logging.error(f"Error {error_ct} on {qid} stream timeout: resetting connection...")
112
103
  elif isinstance(exc, ResponseDataError):
@@ -118,6 +109,16 @@ async def interact_with_websocket(uri: str, queue: asyncio.Queue,
118
109
  else:
119
110
  logging.error(f"Error {error_ct} on {qid}: {traceback.format_exc()}")
120
111
 
112
+ time.sleep(reconnect_timeout_secs)
113
+ # If the query is already complete, we don't want to increment the error count
114
+ if response_payloads[qid]["success"] == 0:
115
+ error_ct += 1
116
+ # Reset buffer stream so that you don't get messed by pre-existing data.
117
+ response_payloads[qid]["response"] = ""
118
+ else:
119
+ logging.info(f"Query ID {qid} completed...")
120
+ queue.task_done()
121
+
121
122
  # prevent any further retries if at error limit.
122
123
  if error_ct == error_threshold:
123
124
  error_ct = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ASUllmAPI
3
- Version: 2.0.4
3
+ Version: 2.0.5
4
4
  Summary: A simple python package to facilitate connection to ASU LLM API
5
5
  Author-email: Stella Wenxing Liu <stellawenxingliu@gmail.com>, Varun Shourie <svarun195@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/ASU/aiml-ssmdv-student-support-ml-data-visualization
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ASUllmAPI
3
- Version: 2.0.4
3
+ Version: 2.0.5
4
4
  Summary: A simple python package to facilitate connection to ASU LLM API
5
5
  Author-email: Stella Wenxing Liu <stellawenxingliu@gmail.com>, Varun Shourie <svarun195@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/ASU/aiml-ssmdv-student-support-ml-data-visualization
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ASUllmAPI"
3
- version = "2.0.4"
3
+ version = "2.0.5"
4
4
  authors = [
5
5
  { name="Stella Wenxing Liu", email="stellawenxingliu@gmail.com" },
6
6
  { name="Varun Shourie", email="svarun195@gmail.com" }
File without changes
File without changes
File without changes
File without changes