ASUllmAPI 2.0.5__tar.gz → 2.0.7__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.
@@ -6,19 +6,26 @@ __author__ = ['swliu', 'vshourie']
6
6
 
7
7
  class ModelConfig:
8
8
 
9
- def __init__(self, access_token: str = None, action: str = None, api_url: str = "", enable_history: bool = False,
10
- enable_search: bool = True, history: List[Dict[str, str]] = None, model_max_tokens: int = None,
11
- model_temperature: float = None, model_top_k: int = None, model_top_p: int = None, name: str = "",
12
- project_id: str = None, provider: str = "", response_format_type: str = "",
13
- search_collection: str = "asu", search_db_type: str = "milvus", search_output_fields: List[str] = None,
9
+ def __init__(self, access_token: str = None, action: str = None, api_url: str = "",
10
+ enhance_prompt_timezone: str = None, enhance_prompt_time: bool = None,
11
+ enhance_prompt_date: bool = None, enhance_prompt_verbosity: str = None,
12
+ enable_history: bool = False, enable_search: bool = True, history: List[Dict[str, str]] = None,
13
+ model_max_tokens: int = None, model_temperature: float = None, model_top_k: int = None,
14
+ model_top_p: int = None, name: str = "", project_id: str = None, provider: str = "",
15
+ response_format_type: str = "", search_collection: str = "asu", search_db_type: str = "opensearch",
16
+ search_expr: str = None, search_output_fields: List[str] = None, search_reranker: bool = False,
14
17
  search_retrieval_type: str = "chunk", search_source_name: List[str] = None, search_tags: list = None,
15
- search_top_k: int = 3, semantic_caching: bool = False, session_id: str = None,
16
- system_prompt: str = None):
18
+ search_top_k: int = 3, search_prompt_mode: str = "unrestricted", search_prompt: str = None,
19
+ semantic_caching: bool = False, session_id: str = None, system_prompt: str = None):
17
20
  self.access_token = access_token
18
21
  self.action = action
19
22
  self.api_url = api_url
20
23
  self.enable_history = enable_history
21
24
  self.enable_search = enable_search
25
+ self.enhance_prompt_timezone = enhance_prompt_timezone
26
+ self.enhance_prompt_time = enhance_prompt_time
27
+ self.enhance_prompt_date = enhance_prompt_date
28
+ self.enhance_prompt_verbosity = enhance_prompt_verbosity
22
29
  self.history = history
23
30
  self.model_max_tokens = model_max_tokens
24
31
  self.model_temperature = model_temperature
@@ -30,11 +37,15 @@ class ModelConfig:
30
37
  self.response_format_type = response_format_type
31
38
  self.search_collection = search_collection
32
39
  self.search_db_type = search_db_type
40
+ self.search_expr = search_expr
33
41
  self.search_output_fields = search_output_fields
42
+ self.search_prompt = search_prompt
43
+ self.search_prompt_mode = search_prompt_mode
44
+ self.search_reranker = search_reranker
45
+ self.search_retrieval_type = search_retrieval_type
34
46
  self.search_source_name = search_source_name
35
47
  self.search_tags = search_tags
36
48
  self.search_top_k = search_top_k
37
- self.search_retrieval_type = search_retrieval_type
38
49
  self.semantic_caching = semantic_caching
39
50
  self.session_id = session_id
40
51
  self.system_prompt = system_prompt
@@ -76,6 +87,8 @@ class ModelConfig:
76
87
  payload["model_provider"] = self.provider
77
88
  if self.project_id:
78
89
  payload["project_id"] = self.project_id
90
+ if self.prompt_enhancers:
91
+ payload["enhance_prompt"] = self.prompt_enhancers
79
92
  if self.response_format:
80
93
  payload["response_format"] = self.response_format
81
94
  if self.search_params:
@@ -102,6 +115,22 @@ class ModelConfig:
102
115
  model_params["system_prompt"] = self.system_prompt
103
116
  return model_params
104
117
 
118
+ @property
119
+ def prompt_enhancers(self):
120
+ self.__validate_access()
121
+
122
+ prompt_enhancer_params = {}
123
+ if self.enhance_prompt_date is not None:
124
+ prompt_enhancer_params["date"] = self.enhance_prompt_date
125
+ if self.enhance_prompt_time is not None:
126
+ prompt_enhancer_params["time"] = self.enhance_prompt_time
127
+ if self.enhance_prompt_timezone is not None:
128
+ prompt_enhancer_params["timezone"] = self.enhance_prompt_timezone
129
+ if self.enhance_prompt_verbosity is not None:
130
+ prompt_enhancer_params["verbosity"] = self.enhance_prompt_verbosity
131
+
132
+ return prompt_enhancer_params
133
+
105
134
  @property
106
135
  def search_params(self):
107
136
  self.__validate_access()
@@ -113,8 +142,16 @@ class ModelConfig:
113
142
  search_params["top_k"] = self.search_top_k
114
143
  search_params["retrieval_type"] = self.search_retrieval_type
115
144
 
145
+ if self.search_prompt_mode is not None:
146
+ search_params["prompt_mode"] = self.search_prompt_mode
147
+ if self.search_expr is not None:
148
+ search_params["expr"] = self.search_expr
149
+ if self.search_prompt is not None:
150
+ search_params["search_prompt"] = self.search_prompt
116
151
  if self.search_source_name is not None:
117
152
  search_params["source_name"] = self.search_source_name
153
+ if self.search_reranker is not None:
154
+ search_params["reranker"] = self.search_reranker
118
155
  if self.search_tags is not None:
119
156
  search_params["tags"] = self.search_tags
120
157
  if self.search_output_fields is not None:
@@ -99,29 +99,36 @@ async def interact_with_websocket(uri: str, queue: asyncio.Queue,
99
99
  # END - QUERY QUEUE LOOP
100
100
  except (asyncio.TimeoutError, websockets.ConnectionClosed, Exception) as exc:
101
101
  if isinstance(exc, asyncio.TimeoutError):
102
- logging.error(f"Error {error_ct} on {qid} stream timeout: resetting connection...")
102
+ logging.error(f"Error {error_ct} on Question ID {qid} stream timeout: resetting connection...")
103
103
  elif isinstance(exc, ResponseDataError):
104
- logging.error(f"Error {error_ct} on {qid}: invalid response from endpoint.\n"
104
+ logging.error(f"Error {error_ct} on Question ID {qid}: invalid response from endpoint.\n"
105
105
  f"{response_payloads[qid]}")
106
106
  elif isinstance(exc, websockets.ConnectionClosed):
107
- logging.error(f"Error {error_ct} on {qid}: WebSocket connection closed on "
107
+ logging.error(f"Error {error_ct} on Question ID {qid}: WebSocket connection closed on "
108
108
  f"query ID {qid}. Reopening...")
109
+ elif isinstance(exc, websockets.exceptions.InvalidStatusCode):
110
+ logging.error(f"Error {error_ct} on Question ID {qid}: Server rejected the connection. "
111
+ f"Check URI again.")
109
112
  else:
110
- logging.error(f"Error {error_ct} on {qid}: {traceback.format_exc()}")
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
-
122
- # prevent any further retries if at error limit.
123
- if error_ct == error_threshold:
124
- error_ct = 0
113
+ logging.error(f"Error {error_ct} on Question ID {qid}: {traceback.format_exc()}")
114
+
115
+ try:
116
+ # If the query is already complete, we don't want to increment the error count
117
+ if response_payloads[qid]["success"] == 0:
118
+ error_ct += 1
119
+ # Reset buffer stream so that you don't get messed by pre-existing data.
120
+ response_payloads[qid]["response"] = ""
121
+ else:
122
+ logging.info(f"Query ID {qid} completed...")
123
+ queue.task_done()
124
+ except KeyError:
125
+ logging.error(f"Question ID {qid} does not exist in the queue. Exiting...")
126
+ return
127
+ finally:
128
+ # prevent any further retries if at error limit.
129
+ if error_ct == error_threshold:
130
+ error_ct = 0
131
+ time.sleep(reconnect_timeout_secs)
125
132
  # END - WEBSOCKET LOOP
126
133
  logging.info("WebSocket connection closed. Queue appears to be empty...")
127
134
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ASUllmAPI
3
- Version: 2.0.5
3
+ Version: 2.0.7
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.5
3
+ Version: 2.0.7
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.5"
3
+ version = "2.0.7"
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
File without changes