sunholo 0.83.4__py3-none-any.whl → 0.84.0__py3-none-any.whl
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.
- sunholo/agents/flask/__init__.py +2 -1
- sunholo/database/alloydb_client.py +31 -2
- sunholo/invoke/async_class.py +89 -0
- sunholo/llamaindex/llamaindex_class.py +9 -1
- sunholo/llamaindex/user_history.py +16 -8
- sunholo/utils/config_class.py +1 -1
- {sunholo-0.83.4.dist-info → sunholo-0.84.0.dist-info}/METADATA +3 -3
- {sunholo-0.83.4.dist-info → sunholo-0.84.0.dist-info}/RECORD +12 -11
- {sunholo-0.83.4.dist-info → sunholo-0.84.0.dist-info}/LICENSE.txt +0 -0
- {sunholo-0.83.4.dist-info → sunholo-0.84.0.dist-info}/WHEEL +0 -0
- {sunholo-0.83.4.dist-info → sunholo-0.84.0.dist-info}/entry_points.txt +0 -0
- {sunholo-0.83.4.dist-info → sunholo-0.84.0.dist-info}/top_level.txt +0 -0
sunholo/agents/flask/__init__.py
CHANGED
|
@@ -9,6 +9,7 @@ except ImportError:
|
|
|
9
9
|
pass
|
|
10
10
|
|
|
11
11
|
from .database import get_vector_size
|
|
12
|
+
from .uuid import generate_uuid_from_object_id
|
|
12
13
|
from ..custom_logging import log
|
|
13
14
|
from ..utils import ConfigManager
|
|
14
15
|
|
|
@@ -122,10 +123,10 @@ class AlloyDBClient:
|
|
|
122
123
|
region=self.config["region"],
|
|
123
124
|
cluster=self.config["cluster"],
|
|
124
125
|
instance=self.config["instance"],
|
|
125
|
-
password=self.password,
|
|
126
126
|
database=self.database,
|
|
127
127
|
ip_type=self.config.get("ip_type") or IPTypes.PRIVATE
|
|
128
128
|
)
|
|
129
|
+
self._loop = engine._loop
|
|
129
130
|
|
|
130
131
|
log.info(f"Created AlloyDB engine for {engine}")
|
|
131
132
|
|
|
@@ -190,6 +191,34 @@ class AlloyDBClient:
|
|
|
190
191
|
await conn.close()
|
|
191
192
|
|
|
192
193
|
return result
|
|
194
|
+
|
|
195
|
+
def get_document_from_docstore(self, source:str, vector_name):
|
|
196
|
+
query = self._get_document_from_docstore(source, vector_name)
|
|
197
|
+
|
|
198
|
+
return self.execute_sql(query)
|
|
199
|
+
|
|
200
|
+
async def get_document_from_docstore_async(self, source:str, vector_name:str):
|
|
201
|
+
query = self._get_document_from_docstore(source, vector_name)
|
|
202
|
+
|
|
203
|
+
document = await self.execute_sql_async(query)
|
|
204
|
+
|
|
205
|
+
return document
|
|
206
|
+
|
|
207
|
+
def _get_document_from_docstore(self, source:str, vector_name:str):
|
|
208
|
+
if not isinstance(source, str):
|
|
209
|
+
raise ValueError("The 'source' parameter must be a single string, not a list of strings or other iterable.")
|
|
210
|
+
|
|
211
|
+
table_name = f"{vector_name}_docstore"
|
|
212
|
+
doc_id = generate_uuid_from_object_id(source)
|
|
213
|
+
|
|
214
|
+
query = f"""
|
|
215
|
+
SELECT *
|
|
216
|
+
FROM {table_name}
|
|
217
|
+
WHERE doc_id = {doc_id}
|
|
218
|
+
LIMIT 1;
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
return query
|
|
193
222
|
|
|
194
223
|
async def get_sources_from_docstore_async(self, sources, vector_name, search_type="OR", just_source_name=False):
|
|
195
224
|
"""Fetches sources from the docstore asynchronously."""
|
|
@@ -233,7 +262,7 @@ class AlloyDBClient:
|
|
|
233
262
|
FROM {table_name}
|
|
234
263
|
WHERE {conditions}
|
|
235
264
|
ORDER BY langchain_metadata->>'objectId' ASC
|
|
236
|
-
LIMIT
|
|
265
|
+
LIMIT 50;
|
|
237
266
|
"""
|
|
238
267
|
|
|
239
268
|
return query
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Callable, List, Any, Coroutine, Tuple
|
|
4
|
+
|
|
5
|
+
# Setup basic logging configuration
|
|
6
|
+
logging.basicConfig(level=logging.INFO)
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
class AsyncTaskRunner:
|
|
10
|
+
"""
|
|
11
|
+
# Example async functions for testing
|
|
12
|
+
async def api_call_1(url, params):
|
|
13
|
+
await asyncio.sleep(1)
|
|
14
|
+
if "fail" in params:
|
|
15
|
+
raise ValueError(f"Error in api_call_1 with params: {params}")
|
|
16
|
+
return f"api_call_1 response from {url} with params {params}"
|
|
17
|
+
|
|
18
|
+
async def api_call_2(url, params):
|
|
19
|
+
await asyncio.sleep(2)
|
|
20
|
+
if "fail" in params:
|
|
21
|
+
raise ValueError(f"Error in api_call_2 with params: {params}")
|
|
22
|
+
return f"api_call_2 response from {url} with params {params}"
|
|
23
|
+
|
|
24
|
+
# Example usage in an existing async function
|
|
25
|
+
async def example_usage():
|
|
26
|
+
runner = AsyncTaskRunner()
|
|
27
|
+
|
|
28
|
+
runner.add_task(api_call_1, "http://example.com", {"key": "value"})
|
|
29
|
+
runner.add_task(api_call_2, "http://example.org", {"key": "fail"})
|
|
30
|
+
|
|
31
|
+
# Run all tasks within the existing event loop
|
|
32
|
+
results = await runner.run_async()
|
|
33
|
+
for result in results:
|
|
34
|
+
print(result)
|
|
35
|
+
|
|
36
|
+
# Example of calling run_sync() in a synchronous context
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
runner = AsyncTaskRunner()
|
|
39
|
+
|
|
40
|
+
runner.add_task(api_call_1, "http://example.com", {"key": "value"})
|
|
41
|
+
runner.add_task(api_call_2, "http://example.org", {"key": "fail"})
|
|
42
|
+
|
|
43
|
+
# Running in a synchronous context
|
|
44
|
+
results = runner.run_sync()
|
|
45
|
+
for result in results:
|
|
46
|
+
print(result)
|
|
47
|
+
"""
|
|
48
|
+
def __init__(self):
|
|
49
|
+
self.tasks = []
|
|
50
|
+
|
|
51
|
+
def add_task(self, func: Callable[..., Coroutine], *args: Any):
|
|
52
|
+
"""Adds a task (function and its arguments) to the list of tasks to be executed."""
|
|
53
|
+
logger.info(f"Adding task: {func.__name__} with args: {args}")
|
|
54
|
+
self.tasks.append(func(*args))
|
|
55
|
+
|
|
56
|
+
def add_group(self, functions: List[Callable[..., Coroutine]], *args: Any):
|
|
57
|
+
"""Adds a group of functions that should run in parallel with the same arguments."""
|
|
58
|
+
group_tasks = [func(*args) for func in functions]
|
|
59
|
+
logger.info(f"Adding group of tasks with args: {args}")
|
|
60
|
+
self.tasks.append(asyncio.gather(*group_tasks, return_exceptions=True))
|
|
61
|
+
|
|
62
|
+
async def run_async(self) -> List[Any]:
|
|
63
|
+
"""Runs all tasks using the current event loop and returns the results."""
|
|
64
|
+
logger.info("Running tasks asynchronously")
|
|
65
|
+
results = await asyncio.gather(*self.tasks, return_exceptions=True)
|
|
66
|
+
self._log_results(results)
|
|
67
|
+
return results
|
|
68
|
+
|
|
69
|
+
def run_sync(self) -> List[Any]:
|
|
70
|
+
"""Runs all tasks synchronously (blocking) using a new event loop and returns the results."""
|
|
71
|
+
try:
|
|
72
|
+
logger.info("Running tasks synchronously")
|
|
73
|
+
loop = asyncio.get_running_loop()
|
|
74
|
+
return loop.run_until_complete(self.run_async())
|
|
75
|
+
except RuntimeError:
|
|
76
|
+
loop = asyncio.new_event_loop()
|
|
77
|
+
asyncio.set_event_loop(loop)
|
|
78
|
+
results = loop.run_until_complete(self.run_async())
|
|
79
|
+
loop.close()
|
|
80
|
+
return results
|
|
81
|
+
|
|
82
|
+
def _log_results(self, results: List[Any]):
|
|
83
|
+
"""Logs the results of the task executions."""
|
|
84
|
+
for result in results:
|
|
85
|
+
if isinstance(result, Exception):
|
|
86
|
+
logger.error(f"Task resulted in an error: {result}")
|
|
87
|
+
else:
|
|
88
|
+
logger.info(f"Task completed successfully: {result}")
|
|
89
|
+
|
|
@@ -198,7 +198,12 @@ class LlamaIndexVertexCorpusManager:
|
|
|
198
198
|
"""
|
|
199
199
|
List all VertexAI Corpus for the project/location
|
|
200
200
|
"""
|
|
201
|
-
|
|
201
|
+
try:
|
|
202
|
+
return rag.list_corpora()
|
|
203
|
+
except Exception as err:
|
|
204
|
+
log.error(f"Could not list corpora: {str(err)}")
|
|
205
|
+
return []
|
|
206
|
+
|
|
202
207
|
|
|
203
208
|
def find_corpus_from_list(self, display_name: str):
|
|
204
209
|
"""
|
|
@@ -410,3 +415,6 @@ def setup_llamaindex_subparser(subparsers):
|
|
|
410
415
|
query_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
|
|
411
416
|
|
|
412
417
|
llamaindex_parser.set_defaults(func=llamaindex_command)
|
|
418
|
+
|
|
419
|
+
# If no subcommand is provided, print the help message
|
|
420
|
+
llamaindex_parser.set_defaults(func=lambda args: llamaindex_parser.print_help() if args.action is None else llamaindex_command)
|
|
@@ -49,13 +49,21 @@ def add_user_history_rag(
|
|
|
49
49
|
|
|
50
50
|
def get_user_history_chunks(user_id:str, config:ConfigManager, query):
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
try:
|
|
53
|
+
manager = LlamaIndexVertexCorpusManager(config)
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
manager.create_corpus(user_id)
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
response = manager.query_corpus(query, user_id)
|
|
58
|
+
log.info(f"User history got: {response=}")
|
|
59
|
+
user_history_memory = []
|
|
60
|
+
for chunk in response.contexts.contexts:
|
|
61
|
+
user_history_memory.append(chunk.text)
|
|
62
|
+
|
|
63
|
+
log.info(f"User history chunks: {user_history_memory}")
|
|
64
|
+
|
|
65
|
+
return "\n".join(user_history_memory)
|
|
66
|
+
except Exception as err:
|
|
67
|
+
log.error(f"Could not find user history due to error: {str(err)}")
|
|
68
|
+
|
|
69
|
+
return f"No user history available due to error: {str(err)}"
|
sunholo/utils/config_class.py
CHANGED
|
@@ -89,7 +89,7 @@ class ConfigManager:
|
|
|
89
89
|
continue
|
|
90
90
|
if filename.endswith(('.yaml', '.yml', '.json')):
|
|
91
91
|
config_file = os.path.join(folder, filename)
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
if filename in self.config_cache:
|
|
94
94
|
cached_config, cache_time = self.config_cache[filename]
|
|
95
95
|
time_to_recache = (current_time - cache_time)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sunholo
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.84.0
|
|
4
4
|
Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
|
|
5
5
|
Home-page: https://github.com/sunholo-data/sunholo-py
|
|
6
|
-
Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.
|
|
6
|
+
Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.84.0.tar.gz
|
|
7
7
|
Author: Holosun ApS
|
|
8
8
|
Author-email: multivac@sunholo.com
|
|
9
9
|
License: Apache License, Version 2.0
|
|
@@ -49,7 +49,7 @@ Requires-Dist: httpx ; extra == 'all'
|
|
|
49
49
|
Requires-Dist: jsonschema ; extra == 'all'
|
|
50
50
|
Requires-Dist: lancedb ; extra == 'all'
|
|
51
51
|
Requires-Dist: langchain >=0.2.12 ; extra == 'all'
|
|
52
|
-
Requires-Dist:
|
|
52
|
+
Requires-Dist: langchain-experimental >=0.0.61 ; extra == 'all'
|
|
53
53
|
Requires-Dist: langchain-community >=0.2.11 ; extra == 'all'
|
|
54
54
|
Requires-Dist: langchain-openai >=0.1.20 ; extra == 'all'
|
|
55
55
|
Requires-Dist: langchain-google-genai >=1.0.5 ; extra == 'all'
|
|
@@ -11,7 +11,7 @@ sunholo/agents/swagger.py,sha256=2tzGmpveUMmTREykZvVnDj3j295wyOMu7mUFDnXdY3c,106
|
|
|
11
11
|
sunholo/agents/fastapi/__init__.py,sha256=S_pj4_bTUmDGoq_exaREHlOKThi0zTuGT0VZY0YfODQ,88
|
|
12
12
|
sunholo/agents/fastapi/base.py,sha256=W-cyF8ZDUH40rc-c-Apw3-_8IIi2e4Y9qRtnoVnsc1Q,2521
|
|
13
13
|
sunholo/agents/fastapi/qna_routes.py,sha256=lKHkXPmwltu9EH3RMwmD153-J6pE7kWQ4BhBlV3to-s,3864
|
|
14
|
-
sunholo/agents/flask/__init__.py,sha256=
|
|
14
|
+
sunholo/agents/flask/__init__.py,sha256=poJDKMr2qj8qMb99JqCvCPSiEt1tj2tLQ3hKW3f2aVw,107
|
|
15
15
|
sunholo/agents/flask/base.py,sha256=FgSaCODyoTtlstJtsqlLPScdgRUtv9_plxftdzHdVFo,809
|
|
16
16
|
sunholo/agents/flask/qna_routes.py,sha256=uwUD1yrzOPH27m2AXpiQrPk_2VfJOQOM6dAynOWQtoQ,22532
|
|
17
17
|
sunholo/agents/flask/vac_routes.py,sha256=JHBrz9URmRzxoNAiqEeI-5qWyKfVSZ1Ix__1t19p6HI,19527
|
|
@@ -59,7 +59,7 @@ sunholo/components/retriever.py,sha256=bKIVT7_18Ut3OJd0E0jyiISPnD9qkHWVjcQPT4i1_
|
|
|
59
59
|
sunholo/components/vectorstore.py,sha256=xKk7micTRwZckaI7U6PxvFz_ZSjCH48xPTDYiDcv2tc,5913
|
|
60
60
|
sunholo/database/__init__.py,sha256=bpB5Nk21kwqYj-qdVnvNgXjLsbflnH4g-San7OHMqR4,283
|
|
61
61
|
sunholo/database/alloydb.py,sha256=YH8wNPS8gN-TDZEXQcVHxwd1NScHRfAxma3gK4R6KCk,11740
|
|
62
|
-
sunholo/database/alloydb_client.py,sha256=
|
|
62
|
+
sunholo/database/alloydb_client.py,sha256=JYozFOOdeDNEB1D2_If488qS1Qc7emHowUEQL0fgU1E,14617
|
|
63
63
|
sunholo/database/database.py,sha256=VqhZdkXUNdvWn8sUcUV3YNby1JDVf7IykPVXWBtxo9U,7361
|
|
64
64
|
sunholo/database/lancedb.py,sha256=DyfZntiFKBlVPaFooNN1Z6Pl-LAs4nxWKKuq8GBqN58,715
|
|
65
65
|
sunholo/database/static_dbs.py,sha256=8cvcMwUK6c32AS2e_WguKXWMkFf5iN3g9WHzsh0C07Q,442
|
|
@@ -83,6 +83,7 @@ sunholo/gcs/download_folder.py,sha256=ijJTnS595JqZhBH8iHFErQilMbkuKgL-bnTCMLGuvl
|
|
|
83
83
|
sunholo/gcs/download_url.py,sha256=q1NiJSvEhdNrmU5ZJ-sBCMC_J5CxzrajY8LRgdPOV_M,6130
|
|
84
84
|
sunholo/gcs/metadata.py,sha256=oQLcXi4brsZ74aegWyC1JZmhlaEV270HS5_UWtAYYWE,898
|
|
85
85
|
sunholo/invoke/__init__.py,sha256=bELcqIjzKvaupcIN5OQmDgGx_8jARtH9T6PCe8UgcvE,99
|
|
86
|
+
sunholo/invoke/async_class.py,sha256=J-qMgarhdi6nPQyOIFM5k0wF7nqr8aJGaz99-Ye6XGQ,3507
|
|
86
87
|
sunholo/invoke/direct_vac_func.py,sha256=L_Gz7hEbZQqAZn2j5ehB-eIXmCEYmSZ7F95mjbYP9Nw,4489
|
|
87
88
|
sunholo/invoke/invoke_vac_utils.py,sha256=sJc1edHTHMzMGXjji1N67c3iUaP7BmAL5nj82Qof63M,2053
|
|
88
89
|
sunholo/langfuse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -91,8 +92,8 @@ sunholo/langfuse/prompts.py,sha256=27BsVfihM6-h1jscbkGSO4HsATl-d4ZN6tcNCVztWoY,1
|
|
|
91
92
|
sunholo/llamaindex/__init__.py,sha256=DlY_cHWCsVEV1C5WBgDdHRgOMlJc8pDoCRukUJ8PT9w,88
|
|
92
93
|
sunholo/llamaindex/get_files.py,sha256=6rhXCDqQ_lrIapISQ_OYQDjiSATXvS_9m3qq53-oIl0,781
|
|
93
94
|
sunholo/llamaindex/import_files.py,sha256=Bnic5wz8c61af9Kwq8KSrNBbc4imYnzMtBCb2jzSImI,6224
|
|
94
|
-
sunholo/llamaindex/llamaindex_class.py,sha256=
|
|
95
|
-
sunholo/llamaindex/user_history.py,sha256=
|
|
95
|
+
sunholo/llamaindex/llamaindex_class.py,sha256=wtMS97YMsfA2IWLTd5mzr73DV4_fi5I5GVD7AC4wVm0,17375
|
|
96
|
+
sunholo/llamaindex/user_history.py,sha256=ZtkecWuF9ORduyGB8kF8gP66bm9DdvCI-ZiK6Kt-cSE,2265
|
|
96
97
|
sunholo/lookup/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
97
98
|
sunholo/lookup/model_lookup.yaml,sha256=O7o-jP53MLA06C8pI-ILwERShO-xf6z_258wtpZBv6A,739
|
|
98
99
|
sunholo/patches/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -118,7 +119,7 @@ sunholo/utils/__init__.py,sha256=Hv02T5L2zYWvCso5hzzwm8FQogwBq0OgtUbN_7Quzqc,89
|
|
|
118
119
|
sunholo/utils/api_key.py,sha256=Ct4bIAQZxzPEw14hP586LpVxBAVi_W9Serpy0BK-7KI,244
|
|
119
120
|
sunholo/utils/big_context.py,sha256=gJIP7_ZL-YSLhOMq8jmFTMqH1wq8eB1NK7oKPeZAq2s,5578
|
|
120
121
|
sunholo/utils/config.py,sha256=aG29MXcL5qzQMtCMqcdy-2ysDCYf9Zn_ZLk5NNOQNSE,8982
|
|
121
|
-
sunholo/utils/config_class.py,sha256=
|
|
122
|
+
sunholo/utils/config_class.py,sha256=tp3mXrwbgOISvI1iT-NhEffD6QpIUK65ik7aT_gi-5o,9819
|
|
122
123
|
sunholo/utils/config_schema.py,sha256=Wv-ncitzljOhgbDaq9qnFqH5LCuxNv59dTGDWgd1qdk,4189
|
|
123
124
|
sunholo/utils/gcp.py,sha256=uueODEpA-P6O15-t0hmcGC9dONLO_hLfzSsSoQnkUss,4854
|
|
124
125
|
sunholo/utils/gcp_project.py,sha256=Fa0IhCX12bZ1ctF_PKN8PNYd7hihEUfb90kilBfUDjg,1411
|
|
@@ -134,9 +135,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
|
|
|
134
135
|
sunholo/vertex/memory_tools.py,sha256=q_phxgGX2TG2j2MXNULF2xGzQnQPENwjPN9nZ_A9Gh0,7526
|
|
135
136
|
sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
|
|
136
137
|
sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
|
|
137
|
-
sunholo-0.
|
|
138
|
-
sunholo-0.
|
|
139
|
-
sunholo-0.
|
|
140
|
-
sunholo-0.
|
|
141
|
-
sunholo-0.
|
|
142
|
-
sunholo-0.
|
|
138
|
+
sunholo-0.84.0.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
|
|
139
|
+
sunholo-0.84.0.dist-info/METADATA,sha256=YeMjnUjnqWzP1QNrPWTwDGjJ4WtmEm0OTgxAzuvP1ME,7412
|
|
140
|
+
sunholo-0.84.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
141
|
+
sunholo-0.84.0.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
|
|
142
|
+
sunholo-0.84.0.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
|
|
143
|
+
sunholo-0.84.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|