ASUllmAPI 2.0.7__tar.gz → 2.0.11__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.
@@ -7,19 +7,24 @@ __author__ = ['swliu', 'vshourie']
7
7
  class ModelConfig:
8
8
 
9
9
  def __init__(self, access_token: str = None, action: str = None, api_url: str = "",
10
+ chat_upload_images: List[str] = None, chat_upload_docs: List[str] = None,
10
11
  enhance_prompt_timezone: str = None, enhance_prompt_time: bool = None,
11
12
  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
+ enable_history: bool = False, enable_search: bool = True, history: List[Dict[str, str]] = None,
13
14
  model_max_tokens: int = None, model_temperature: float = None, model_top_k: int = None,
14
15
  model_top_p: int = None, name: str = "", project_id: str = None, provider: str = "",
15
16
  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,
17
+ search_expr: str = None, search_output_fields: List[str] = None, rerank: bool = False,
18
+ search_reranker_model: str = None, search_reranker_provider: str = None,
17
19
  search_retrieval_type: str = "chunk", search_source_name: List[str] = None, search_tags: list = None,
18
20
  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):
21
+ semantic_caching: bool = False, session_id: str = None, system_prompt: str = None,
22
+ query_id: str = None):
20
23
  self.access_token = access_token
21
24
  self.action = action
22
25
  self.api_url = api_url
26
+ self.chat_upload_images = chat_upload_images
27
+ self.chat_upload_docs = chat_upload_docs
23
28
  self.enable_history = enable_history
24
29
  self.enable_search = enable_search
25
30
  self.enhance_prompt_timezone = enhance_prompt_timezone
@@ -41,7 +46,9 @@ class ModelConfig:
41
46
  self.search_output_fields = search_output_fields
42
47
  self.search_prompt = search_prompt
43
48
  self.search_prompt_mode = search_prompt_mode
44
- self.search_reranker = search_reranker
49
+ self.rerank = rerank
50
+ self.search_reranker_model = search_reranker_model
51
+ self.search_reranker_provider = search_reranker_provider
45
52
  self.search_retrieval_type = search_retrieval_type
46
53
  self.search_source_name = search_source_name
47
54
  self.search_tags = search_tags
@@ -49,6 +56,7 @@ class ModelConfig:
49
56
  self.semantic_caching = semantic_caching
50
57
  self.session_id = session_id
51
58
  self.system_prompt = system_prompt
59
+ self.query_id = query_id
52
60
 
53
61
  self.__validate_access()
54
62
 
@@ -73,6 +81,8 @@ class ModelConfig:
73
81
  payload = {"query": query}
74
82
  if self.action:
75
83
  payload["action"] = self.action
84
+ if self.chat_upload:
85
+ payload["chat_upload"] = self.chat_upload
76
86
  if self.enable_history is not None:
77
87
  payload["enable_history"] = self.enable_history
78
88
  if self.enable_search is not None:
@@ -95,9 +105,20 @@ class ModelConfig:
95
105
  payload["search_params"] = self.search_params
96
106
  if self.semantic_caching:
97
107
  payload["semantic_caching"] = self.semantic_caching
108
+ if self.query_id:
109
+ payload["query_id"] = self.query_id
98
110
 
99
111
  return payload
100
112
 
113
+ @property
114
+ def chat_upload(self):
115
+ chat_upload_payload = {}
116
+ if self.chat_upload_docs:
117
+ chat_upload_payload['docs'] = self.chat_upload_docs
118
+ if self.chat_upload_images:
119
+ chat_upload_payload['images'] = self.chat_upload_images
120
+ return chat_upload_payload
121
+
101
122
  @property
102
123
  def model_params(self):
103
124
  self.__validate_access()
@@ -150,8 +171,12 @@ class ModelConfig:
150
171
  search_params["search_prompt"] = self.search_prompt
151
172
  if self.search_source_name is not None:
152
173
  search_params["source_name"] = self.search_source_name
153
- if self.search_reranker is not None:
154
- search_params["reranker"] = self.search_reranker
174
+ if self.rerank is not None:
175
+ search_params["rerank"] = self.rerank
176
+ if self.search_reranker_model is not None:
177
+ search_params["reranker_model"] = self.search_reranker_model
178
+ if self.search_reranker_provider is not None:
179
+ search_params["reranker_provider"] = self.search_reranker_provider
155
180
  if self.search_tags is not None:
156
181
  search_params["tags"] = self.search_tags
157
182
  if self.search_output_fields is not None:
@@ -123,11 +123,13 @@ async def interact_with_websocket(uri: str, queue: asyncio.Queue,
123
123
  queue.task_done()
124
124
  except KeyError:
125
125
  logging.error(f"Question ID {qid} does not exist in the queue. Exiting...")
126
+ queue.task_done()
126
127
  return
127
128
  finally:
128
129
  # prevent any further retries if at error limit.
129
130
  if error_ct == error_threshold:
130
131
  error_ct = 0
132
+ queue.task_done()
131
133
  time.sleep(reconnect_timeout_secs)
132
134
  # END - WEBSOCKET LOOP
133
135
  logging.info("WebSocket connection closed. Queue appears to be empty...")
@@ -139,6 +141,14 @@ async def batch_query_llm_socket(model: ModelConfig, queries: Dict[Union[str, in
139
141
  ws_timeout_min: int = 8,
140
142
  error_threshold: int = 100,
141
143
  reconnect_timeout_secs: int = 2) -> Dict[Union[str, int], Dict[str, Any]]:
144
+ return await async_batch_query_llm_socket(model, queries, max_concurrent_tasks, ws_timeout_min,
145
+ error_threshold, reconnect_timeout_secs)
146
+
147
+
148
+ async def async_batch_query_llm_socket(model: ModelConfig, queries: Dict[Union[str, int], str],
149
+ max_concurrent_tasks: int = 3, ws_timeout_min: int = 8,
150
+ error_threshold: int = 100,
151
+ reconnect_timeout_secs: int = 2) -> Dict[Union[str, int], Dict[str, Any]]:
142
152
  payloads = {}
143
153
  for qid, message in queries.items():
144
154
  payloads[qid] = model.compute_payload(message)
@@ -162,12 +172,18 @@ async def query_llm_socket(model: ModelConfig, query: str,
162
172
  ws_timeout_min: int = 8,
163
173
  error_threshold: int = 100,
164
174
  reconnect_timeout_secs: int = 2) -> Dict[str, Any]:
175
+ return await async_query_llm_socket(model, query, ws_timeout_min, error_threshold, reconnect_timeout_secs)
176
+
177
+
178
+ async def async_query_llm_socket(model: ModelConfig, query: str,
179
+ ws_timeout_min: int = 8,
180
+ error_threshold: int = 100,
181
+ reconnect_timeout_secs: int = 2) -> Dict[str, Any]:
165
182
  response_payloads = {0: DEFAULT_RESPONSE.copy()}
166
183
  tmp_payload = model.compute_payload(query=query)
167
184
  if query != "":
168
185
  queue = asyncio.Queue()
169
186
  await queue.put((0, tmp_payload))
170
-
171
187
  await interact_with_websocket(model.api_url, queue, response_payloads, ws_timeout_min,
172
188
  error_threshold, reconnect_timeout_secs)
173
189
  return response_payloads[0]
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: ASUllmAPI
3
- Version: 2.0.7
3
+ Version: 2.0.11
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
@@ -15,6 +15,7 @@ Requires-Dist: requests
15
15
  Requires-Dist: tqdm
16
16
  Requires-Dist: websockets
17
17
  Requires-Dist: certifi
18
+ Dynamic: license-file
18
19
 
19
20
  # ASU LLM API
20
21
  This package allows individuals at Arizona State University to access ASU GPT through API. You will need API access token, API endpoints in order to use this package.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: ASUllmAPI
3
- Version: 2.0.7
3
+ Version: 2.0.11
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
@@ -15,6 +15,7 @@ Requires-Dist: requests
15
15
  Requires-Dist: tqdm
16
16
  Requires-Dist: websockets
17
17
  Requires-Dist: certifi
18
+ Dynamic: license-file
18
19
 
19
20
  # ASU LLM API
20
21
  This package allows individuals at Arizona State University to access ASU GPT through API. You will need API access token, API endpoints in order to use this package.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ASUllmAPI"
3
- version = "2.0.7"
3
+ version = "2.0.11"
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