sunholo 0.79.0__py3-none-any.whl → 0.79.2__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.
Files changed (79) hide show
  1. sunholo/agents/chat_history.py +1 -1
  2. sunholo/agents/dispatch_to_qa.py +1 -1
  3. sunholo/agents/fastapi/base.py +1 -1
  4. sunholo/agents/fastapi/qna_routes.py +1 -1
  5. sunholo/agents/flask/qna_routes.py +1 -1
  6. sunholo/agents/flask/vac_routes.py +1 -1
  7. sunholo/agents/langserve.py +1 -1
  8. sunholo/agents/pubsub.py +1 -1
  9. sunholo/agents/route.py +1 -1
  10. sunholo/agents/special_commands.py +1 -1
  11. sunholo/agents/swagger.py +1 -1
  12. sunholo/archive/archive.py +1 -1
  13. sunholo/auth/refresh.py +1 -1
  14. sunholo/auth/run.py +1 -1
  15. sunholo/azure/auth.py +1 -1
  16. sunholo/azure/blobs.py +1 -1
  17. sunholo/azure/event_grid.py +1 -1
  18. sunholo/bots/discord.py +1 -1
  19. sunholo/chunker/azure.py +1 -1
  20. sunholo/chunker/doc_handling.py +2 -2
  21. sunholo/chunker/encode_metadata.py +1 -1
  22. sunholo/chunker/images.py +1 -1
  23. sunholo/chunker/loaders.py +1 -1
  24. sunholo/chunker/message_data.py +1 -1
  25. sunholo/chunker/pdfs.py +1 -1
  26. sunholo/chunker/process_chunker_data.py +1 -1
  27. sunholo/chunker/publish.py +1 -1
  28. sunholo/chunker/pubsub.py +1 -1
  29. sunholo/chunker/splitter.py +1 -1
  30. sunholo/cli/chat_vac.py +1 -1
  31. sunholo/cli/cli.py +4 -1
  32. sunholo/components/llm.py +1 -1
  33. sunholo/components/retriever.py +19 -13
  34. sunholo/components/vectorstore.py +13 -2
  35. sunholo/database/alloydb.py +1 -1
  36. sunholo/database/alloydb_client.py +1 -1
  37. sunholo/database/database.py +1 -1
  38. sunholo/database/lancedb.py +1 -1
  39. sunholo/database/static_dbs.py +1 -1
  40. sunholo/discovery_engine/chunker_handler.py +1 -1
  41. sunholo/discovery_engine/discovery_engine_client.py +1 -1
  42. sunholo/embedder/embed_chunk.py +1 -1
  43. sunholo/gcs/add_file.py +1 -1
  44. sunholo/gcs/download_folder.py +1 -1
  45. sunholo/gcs/download_url.py +1 -1
  46. sunholo/gcs/metadata.py +1 -1
  47. sunholo/invoke/direct_vac_func.py +1 -1
  48. sunholo/invoke/invoke_vac_utils.py +1 -1
  49. sunholo/langfuse/callback.py +1 -1
  50. sunholo/langfuse/prompts.py +1 -1
  51. sunholo/llamaindex/__init__.py +1 -0
  52. sunholo/llamaindex/import_files.py +24 -17
  53. sunholo/llamaindex/llamaindex_class.py +274 -0
  54. sunholo/pubsub/process_pubsub.py +1 -1
  55. sunholo/pubsub/pubsub_manager.py +1 -1
  56. sunholo/qna/parsers.py +1 -1
  57. sunholo/qna/retry.py +1 -1
  58. sunholo/streaming/content_buffer.py +1 -1
  59. sunholo/streaming/langserve.py +1 -1
  60. sunholo/streaming/stream_lookup.py +1 -1
  61. sunholo/streaming/streaming.py +1 -1
  62. sunholo/summarise/summarise.py +1 -1
  63. sunholo/tools/web_browser.py +1 -1
  64. sunholo/utils/config.py +5 -5
  65. sunholo/utils/config_class.py +4 -4
  66. sunholo/vertex/extensions_call.py +1 -1
  67. sunholo/vertex/extensions_class.py +1 -1
  68. sunholo/vertex/genai_functions.py +1 -1
  69. sunholo/vertex/init.py +1 -1
  70. sunholo/vertex/memory_tools.py +29 -14
  71. {sunholo-0.79.0.dist-info → sunholo-0.79.2.dist-info}/METADATA +2 -2
  72. sunholo-0.79.2.dist-info/RECORD +140 -0
  73. {sunholo-0.79.0.dist-info → sunholo-0.79.2.dist-info}/WHEEL +1 -1
  74. sunholo/llamaindex/generate.py +0 -22
  75. sunholo-0.79.0.dist-info/RECORD +0 -140
  76. /sunholo/{logging.py → custom_logging.py} +0 -0
  77. {sunholo-0.79.0.dist-info → sunholo-0.79.2.dist-info}/LICENSE.txt +0 -0
  78. {sunholo-0.79.0.dist-info → sunholo-0.79.2.dist-info}/entry_points.txt +0 -0
  79. {sunholo-0.79.0.dist-info → sunholo-0.79.2.dist-info}/top_level.txt +0 -0
@@ -3,11 +3,13 @@ try:
3
3
  except ImportError:
4
4
  rag = None
5
5
 
6
- from ..logging import log
6
+ from ..custom_logging import log
7
7
  from ..utils import ConfigManager
8
8
  from ..vertex import init_vertex
9
9
  from .get_files import fetch_corpus
10
+ from .llamaindex_class import LlamaIndexVertexCorpusManager
10
11
  from ..components import load_memories
12
+
11
13
 
12
14
 
13
15
  def do_llamaindex(message_data, metadata, vector_name):
@@ -50,7 +52,6 @@ def do_llamaindex(message_data, metadata, vector_name):
50
52
 
51
53
  global_project_id = gcp_config.get('project_id')
52
54
  global_location = gcp_config.get('location')
53
- global_rag_id = gcp_config.get('rag_id')
54
55
  #global_data_store_id = gcp_config.get('data_store_id')
55
56
 
56
57
  memories = load_memories(vector_name)
@@ -70,26 +71,32 @@ def do_llamaindex(message_data, metadata, vector_name):
70
71
  rag_id = value.get('rag_id')
71
72
  project_id = gcp_config.get('project_id')
72
73
  location = gcp_config.get('location')
73
- try:
74
- corpus = fetch_corpus(
75
- project_id=project_id or global_project_id,
76
- location=location or global_location,
77
- rag_id=rag_id or global_rag_id
78
- )
79
- except Exception as err:
80
- log.warning(f"Failed to fetch LlamaIndex corpus: {err=}")
81
- continue
74
+
75
+ if rag_id:
76
+ try:
77
+ corpus = fetch_corpus(
78
+ project_id=project_id or global_project_id,
79
+ location=location or global_location,
80
+ rag_id=rag_id
81
+ )
82
+ except Exception as err:
83
+ log.warning(f"Failed to fetch LlamaIndex corpus from rag_id: {err=}")
84
+ continue
85
+ else:
86
+ try:
87
+ log.info("Using vertex llamaindex with own rag_id created via VAC name")
88
+ manager = LlamaIndexVertexCorpusManager(config, project_id=project_id, location=location)
89
+ # create or get existing:
90
+ corpus = manager.create_corpus(vector_name)
91
+ except Exception as err:
92
+ log.warning(f"Failed to fetch LlamaIndex corpus from display_name: {err=}")
93
+ continue
82
94
 
83
95
  corpuses.append(corpus)
96
+
84
97
  if not corpuses:
85
98
  log.info("No Vertex Llamaindex RAG corpus to import data")
86
99
  return None
87
-
88
- try:
89
- corpura = rag.list_corpora()
90
- log.info(f"All Corpora: {corpura} - {type(corpura)}")
91
- except Exception as err:
92
- log.warning(f"Could not list any corpora - {str(err)}")
93
100
 
94
101
  log.info(f"Found llamaindex corpus: {corpuses}")
95
102
 
@@ -0,0 +1,274 @@
1
+ import os
2
+ import tempfile
3
+
4
+ try:
5
+ from vertexai.preview import rag
6
+ except ImportError:
7
+ rag = None
8
+
9
+ from ..utils import ConfigManager
10
+ from ..custom_logging import log
11
+
12
+ try:
13
+ from ..cli.sun_rich import console
14
+ except ImportError:
15
+ console = None
16
+
17
+ class LlamaIndexVertexCorpusManager:
18
+ """
19
+ A manager class for handling RAG corpora operations with Vertex AI.
20
+
21
+ Attributes:
22
+ config (ConfigManager): Configuration manager for fetching project settings.
23
+ project_id (str): GCP project ID.
24
+ location (str): GCP location.
25
+ """
26
+
27
+ def __init__(self, config: ConfigManager = None, project_id: str = None, location: str = None):
28
+ """
29
+ Initializes the LlamaIndexVertexCorpusManager.
30
+
31
+ Args:
32
+ config (ConfigManager): Configuration manager for fetching project settings.
33
+ project_id (str): GCP project ID.
34
+ location (str): GCP location.
35
+
36
+ Raises:
37
+ ImportError: If vertexai is not installed.
38
+ """
39
+ from ..vertex.init import init_vertex
40
+ if rag is None:
41
+ raise ImportError("You must install vertexai via `pip install sunholo[gcp]`")
42
+
43
+ self.config = config
44
+ self.project_id = project_id
45
+ self.location = location
46
+
47
+ if config:
48
+ self.project_id = self.config.vacConfig('project_id') or project_id
49
+ self.location = self.config.vacConfig('location') or location
50
+
51
+ init_vertex(location=self.location, project_id=self.project_id)
52
+
53
+ def upload_text(self, text: str, corpus_display_name: str, description: str = None):
54
+ """
55
+ Uploads a text string to a specified corpus by saving it to a temporary file first.
56
+
57
+ Args:
58
+ text (str): The text content to upload.
59
+ corpus_display_name (str): The display name of the corpus.
60
+ description (str, optional): Description of the text upload.
61
+
62
+ Returns:
63
+ The uploaded file object.
64
+ """
65
+ # Create a temporary file and write the text to it
66
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.txt') as temp_file:
67
+ temp_file.write(text.encode('utf-8'))
68
+ temp_filename = temp_file.name
69
+
70
+ try:
71
+ # Upload the temporary file
72
+ uploaded_file = self.upload_file(temp_filename, corpus_display_name, description or text[:50])
73
+ finally:
74
+ # Clean up the temporary file
75
+ os.remove(temp_filename)
76
+
77
+ return uploaded_file
78
+
79
+ def upload_file(self, filename:str, corpus_display_name:str, description:str=None):
80
+ corpus = self.find_corpus_from_list(corpus_display_name)
81
+
82
+ rag_file = rag.upload_file(
83
+ corpus_name=corpus.name,
84
+ path=filename,
85
+ display_name=filename,
86
+ description=description or f"Upload for {filename}",
87
+ )
88
+ log.info("Uploaded file: {rag_file}")
89
+
90
+ return rag_file
91
+
92
+ def import_files(self, file_imports:list[str], corpus_display_name:str):
93
+ corpus = self.find_corpus_from_list(corpus_display_name)
94
+
95
+ log.info(f"Importing files: {file_imports} into {corpus.name}")
96
+ response = rag.import_files(
97
+ corpus_name=corpus.name,
98
+ paths=file_imports,
99
+ chunk_size=512, # Optional
100
+ chunk_overlap=100, # Optional
101
+ max_embedding_requests_per_min=900, # Optional
102
+ )
103
+ log.info(f"Imported files: {response}")
104
+
105
+ return response
106
+
107
+ def list_corpora(self):
108
+ """
109
+ List all VertexAI Corpus for the project/location
110
+ """
111
+ return rag.list_corpora()
112
+
113
+ def find_corpus_from_list(self, display_name: str):
114
+ """
115
+ Finds a corpus from the list of corpora by its display name.
116
+
117
+ Args:
118
+ display_name (str): The display name of the corpus.
119
+
120
+ Returns:
121
+ The found corpus object if it exists, otherwise None.
122
+ """
123
+ corpora = self.list_corpora()
124
+ for corp in corpora:
125
+ if display_name == corp.display_name:
126
+ log.info(f"Found existing corpus with display name: {display_name}")
127
+ return corp
128
+ return None
129
+
130
+ def create_corpus(self, display_name: str, description: str = None):
131
+ """
132
+ Creates a new corpus or returns an existing one with the specified display name.
133
+
134
+ Args:
135
+ display_name (str): The display name of the corpus.
136
+ description (str, optional): Description of the corpus.
137
+
138
+ Returns:
139
+ The created or found corpus object.
140
+ """
141
+ corp = self.find_corpus_from_list(display_name)
142
+ if corp:
143
+ return corp
144
+
145
+ corpus = rag.create_corpus(display_name=display_name, description=description or f"Corpus for {display_name}")
146
+ log.info(f"created Llamaindex corpus {corpus}")
147
+
148
+ return corpus
149
+
150
+ def delete_corpus(self, display_name: str):
151
+ """
152
+ Deletes a corpus by its display name.
153
+
154
+ Args:
155
+ display_name (str): The display name of the corpus.
156
+
157
+ Returns:
158
+ bool: True if the corpus was deleted, False otherwise.
159
+ """
160
+ corp = self.find_corpus_from_list(display_name)
161
+ if corp:
162
+ rag_id = corp.name
163
+ rag.delete_corpus(name=rag_id)
164
+ log.info(f"Deleted {rag_id}")
165
+ return True
166
+
167
+ log.warning(f"Could not find a corp to delete with name {display_name}")
168
+ return False
169
+
170
+ def fetch_corpus(self, display_name: str):
171
+ """
172
+ Fetches a corpus by its display name.
173
+
174
+ Args:
175
+ display_name (str): The display name of the corpus.
176
+
177
+ Returns:
178
+ The fetched corpus object.
179
+
180
+ Raises:
181
+ ValueError: If the corpus with the specified display name does not exist.
182
+ """
183
+ corp = self.find_corpus_from_list(display_name)
184
+ if not corp:
185
+ raise ValueError(f"Could not find any corpus with display_name: {display_name}")
186
+ return rag.get_corpus(name=corp.name)
187
+
188
+ def llamaindex_command(args):
189
+ if console is None:
190
+ raise ImportError("Need cli tools to use `sunholo llamaindex` - install via `pip install sunholo[cli]`")
191
+
192
+ config = ConfigManager(args.vac)
193
+ manager = LlamaIndexVertexCorpusManager(config=config)
194
+
195
+ if args.action == "create":
196
+ manager.create_corpus(display_name=args.display_name, description=args.description)
197
+ elif args.action == "delete":
198
+ manager.delete_corpus(display_name=args.display_name)
199
+ elif args.action == "fetch":
200
+ corpus = manager.fetch_corpus(display_name=args.display_name)
201
+ console.print(corpus)
202
+ elif args.action == "find":
203
+ corpus = manager.find_corpus_from_list(display_name=args.display_name)
204
+ console.print(corpus)
205
+ elif args.action == "list":
206
+ corpora = manager.list_corpora()
207
+ console.print(corpora)
208
+ elif args.action == "import_files":
209
+ manager.import_files(file_imports=args.file_imports, corpus_display_name=args.display_name)
210
+ elif args.action == "upload_file":
211
+ manager.upload_file(filename=args.filename, corpus_display_name=args.display_name, description=args.description)
212
+ elif args.action == "upload_text":
213
+ manager.upload_text(text=args.text, corpus_display_name=args.display_name, description=args.description)
214
+ else:
215
+ console.print(f"Unknown action: {args.action}")
216
+
217
+ def setup_llamaindex_subparser(subparsers):
218
+ """
219
+ Sets up an argparse subparser for the 'llamaindex' command.
220
+
221
+ Args:
222
+ subparsers: The subparsers object from argparse.ArgumentParser().
223
+ """
224
+ # LlamaIndex subparser setup
225
+ llamaindex_parser = subparsers.add_parser('llamaindex', help='Manage LlamaIndex corpora')
226
+ llamaindex_subparsers = llamaindex_parser.add_subparsers(dest='action', help='LlamaIndex subcommands')
227
+
228
+ # LlamaIndex create command
229
+ create_parser = llamaindex_subparsers.add_parser('create', help='Create a new corpus')
230
+ create_parser.add_argument('display_name', help='The name of the corpus')
231
+ create_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
232
+ create_parser.add_argument('--description', help='Description of the corpus', default=None)
233
+
234
+ # LlamaIndex delete command
235
+ delete_parser = llamaindex_subparsers.add_parser('delete', help='Delete a corpus')
236
+ delete_parser.add_argument('display_name', help='The name of the corpus')
237
+ delete_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
238
+
239
+ # LlamaIndex fetch command
240
+ fetch_parser = llamaindex_subparsers.add_parser('fetch', help='Fetch a corpus')
241
+ fetch_parser.add_argument('display_name', help='The name of the corpus')
242
+ fetch_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
243
+
244
+ # LlamaIndex find command
245
+ find_parser = llamaindex_subparsers.add_parser('find', help='Find a corpus')
246
+ find_parser.add_argument('display_name', help='The name of the corpus')
247
+ find_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
248
+
249
+ # LlamaIndex list command
250
+ list_parser = llamaindex_subparsers.add_parser('list', help='List all corpus')
251
+ list_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
252
+
253
+ # LlamaIndex import_files command
254
+ import_files_parser = llamaindex_subparsers.add_parser('import_files', help='Import files from URLs to a corpus')
255
+ import_files_parser.add_argument('display_name', help='The name of the corpus')
256
+ import_files_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
257
+ import_files_parser.add_argument('file_imports', nargs='+', help='The list of file URLs to import')
258
+
259
+ # LlamaIndex upload_file command
260
+ upload_file_parser = llamaindex_subparsers.add_parser('upload_file', help='Upload a local file to a corpus')
261
+ upload_file_parser.add_argument('display_name', help='The name of the corpus')
262
+ upload_file_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
263
+ upload_file_parser.add_argument('filename', help='The local file path to upload')
264
+ upload_file_parser.add_argument('--description', help='Description of the file upload', default=None)
265
+
266
+ # LlamaIndex upload_text command
267
+ upload_text_parser = llamaindex_subparsers.add_parser('upload_text', help='Upload text to a corpus')
268
+ upload_text_parser.add_argument('display_name', help='The name of the corpus')
269
+ upload_text_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
270
+ upload_text_parser.add_argument('text', help='The text content to upload')
271
+ upload_text_parser.add_argument('--description', help='Description of the text upload', default=None)
272
+
273
+ llamaindex_parser.set_defaults(func=llamaindex_command)
274
+
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  import base64
15
- from ..logging import log
15
+ from ..custom_logging import log
16
16
  from ..gcs.metadata import get_object_metadata
17
17
 
18
18
 
@@ -19,7 +19,7 @@ except ImportError:
19
19
  pubsub_v1 = None
20
20
 
21
21
  import json
22
- from ..logging import log
22
+ from ..custom_logging import log
23
23
  from ..utils.gcp_project import get_gcp_project
24
24
 
25
25
 
sunholo/qna/parsers.py CHANGED
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from sunholo.logging import log
15
+ from sunholo.custom_logging import log
16
16
 
17
17
  def document_to_dict(document):
18
18
  return {
sunholo/qna/retry.py CHANGED
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
  import time
15
15
  import traceback
16
- from ..logging import log
16
+ from ..custom_logging import log
17
17
 
18
18
 
19
19
  def retry_qna(qa_function, question, max_retries=1, initial_delay=5):
@@ -17,7 +17,7 @@ from langchain.schema import LLMResult
17
17
 
18
18
  import threading
19
19
  import re
20
- from ..logging import log
20
+ from ..custom_logging import log
21
21
 
22
22
  class ContentBuffer:
23
23
  """
@@ -1,5 +1,5 @@
1
1
  import json
2
- from ..logging import log
2
+ from ..custom_logging import log
3
3
 
4
4
  async def parse_langserve_token_async(token):
5
5
  """
@@ -1,5 +1,5 @@
1
1
  from ..utils import load_config_key
2
- from ..logging import log
2
+ from ..custom_logging import log
3
3
 
4
4
  def can_agent_stream(agent_name: str):
5
5
 
@@ -21,7 +21,7 @@ from .content_buffer import ContentBuffer, BufferStreamingStdOutCallbackHandler
21
21
 
22
22
  from ..qna.parsers import parse_output
23
23
 
24
- from ..logging import log
24
+ from ..custom_logging import log
25
25
  from ..utils import load_config_key
26
26
  from ..utils.parsers import check_kwargs_support
27
27
 
@@ -11,7 +11,7 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- from ..logging import log
14
+ from ..custom_logging import log
15
15
 
16
16
 
17
17
 
@@ -6,7 +6,7 @@ import urllib.parse
6
6
  import time
7
7
  from io import BytesIO
8
8
 
9
- from ..logging import log
9
+ from ..custom_logging import log
10
10
 
11
11
  from ..utils.parsers import get_clean_website_name
12
12
 
sunholo/utils/config.py CHANGED
@@ -36,7 +36,7 @@ def get_module_filepath(filepath: str):
36
36
  print(f'Absolute path: {abs_path}')
37
37
  ```
38
38
  """
39
- from ..logging import log
39
+ from ..custom_logging import log
40
40
 
41
41
  # Get the root directory of this Python script
42
42
  dir_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
@@ -55,7 +55,7 @@ def load_all_configs():
55
55
  Files are expected to be either YAML or JSON and must contain a 'kind' key at the root.
56
56
  Caching is used to avoid reloading files within a 5-minute window.
57
57
  """
58
- from ..logging import log
58
+ from ..custom_logging import log
59
59
 
60
60
  if not os.getenv("_CONFIG_FOLDER"):
61
61
  log.debug("_CONFIG_FOLDER is not set, using os.getcwd() instead")
@@ -102,7 +102,7 @@ def reload_config_file(config_file, filename):
102
102
  """
103
103
  Helper function to load a config file and update the cache.
104
104
  """
105
- from ..logging import log
105
+ from ..custom_logging import log
106
106
  with open(config_file, 'r') as file:
107
107
  if filename.endswith('.json'):
108
108
  config = json.load(file)
@@ -134,7 +134,7 @@ def load_config(filename: str=None) -> tuple[dict, str]:
134
134
  ```
135
135
  """
136
136
  global config_cache
137
- from ..logging import log
137
+ from ..custom_logging import log
138
138
 
139
139
  if filename is None:
140
140
  filename = os.getenv("_CONFIG_FILE", None)
@@ -194,7 +194,7 @@ def load_config_key(key: str, vector_name: str, kind: str):
194
194
  ```
195
195
  """
196
196
  # can't use sunholo.logging due to circular import
197
- from ..logging import log
197
+ from ..custom_logging import log
198
198
 
199
199
  if kind != 'agentConfig':
200
200
  assert isinstance(key, str), f"key must be a string got a {type(key)}"
@@ -38,7 +38,7 @@ class ConfigManager:
38
38
  self.configs_by_kind = self.load_all_configs()
39
39
 
40
40
  test_agent = self.vacConfig("agent")
41
- if not test_agent:
41
+ if not test_agent and self.vector_name != "global":
42
42
  print(f"WARNING: No vacConfig.agent found for {self.vector_name} - are you in right folder? {local_config_folder=} {self.config_folder=}")
43
43
 
44
44
  def load_all_configs(self):
@@ -49,7 +49,7 @@ class ConfigManager:
49
49
  Returns:
50
50
  dict: A dictionary of configurations grouped by their 'kind' key.
51
51
  """
52
- from ..logging import log
52
+ from ..custom_logging import log
53
53
 
54
54
  log.debug(f"Loading all configs from folder: {self.config_folder} and local folder: {self.local_config_folder}")
55
55
  global_configs_by_kind = self._load_configs_from_folder(self.config_folder)
@@ -75,7 +75,7 @@ class ConfigManager:
75
75
  Returns:
76
76
  dict: A dictionary of configurations grouped by their 'kind' key.
77
77
  """
78
- from ..logging import log
78
+ from ..custom_logging import log
79
79
 
80
80
  configs_by_kind = defaultdict(dict)
81
81
  current_time = datetime.now()
@@ -116,7 +116,7 @@ class ConfigManager:
116
116
  Returns:
117
117
  dict: The loaded configuration.
118
118
  """
119
- from ..logging import log
119
+ from ..custom_logging import log
120
120
  with open(config_file, 'r') as file:
121
121
  if filename.endswith('.json'):
122
122
  config = json.load(file)
@@ -1,6 +1,6 @@
1
1
  from .extensions_class import VertexAIExtensions
2
2
  from ..utils import ConfigManager
3
- from ..logging import log
3
+ from ..custom_logging import log
4
4
  import collections.abc
5
5
  import json
6
6
 
@@ -4,7 +4,7 @@ except ImportError:
4
4
  extensions = None
5
5
 
6
6
  from .init import init_vertex
7
- from ..logging import log
7
+ from ..custom_logging import log
8
8
  from ..utils.gcp_project import get_gcp_project
9
9
  from ..utils.gcp import is_running_on_cloudrun
10
10
  from ..auth import get_local_gcloud_token, get_cloud_run_token
@@ -5,7 +5,7 @@ except ImportError:
5
5
 
6
6
  from .init import init_genai
7
7
  from .safety import genai_safety
8
- from ..logging import log
8
+ from ..custom_logging import log
9
9
  import json
10
10
  from .type_dict_to_json import describe_typed_dict, openapi_to_typed_dict, is_typed_dict
11
11
 
sunholo/vertex/init.py CHANGED
@@ -1,4 +1,4 @@
1
- from ..logging import log
1
+ from ..custom_logging import log
2
2
  from ..utils.gcp_project import get_gcp_project
3
3
  from ..auth.refresh import get_default_email
4
4
  import os
@@ -4,14 +4,15 @@ try:
4
4
  except ImportError:
5
5
  rag = None
6
6
 
7
- from ..logging import log
8
- from ..utils.config import load_config_key
7
+ from ..custom_logging import log
9
8
  from ..components import load_memories
10
9
  from ..llamaindex.get_files import fetch_corpus
10
+ from ..llamaindex.llamaindex_class import LlamaIndexVertexCorpusManager
11
11
  from ..discovery_engine.discovery_engine_client import DiscoveryEngineClient
12
12
  from ..utils.gcp_project import get_gcp_project
13
+ from ..utils import ConfigManager
13
14
 
14
- def get_vertex_memories(vector_name):
15
+ def get_vertex_memories(vector_name:str=None, config:ConfigManager=None):
15
16
  """
16
17
  Retrieves a LlamaIndex corpus from Vertex AI based on the provided Google Cloud configuration.
17
18
 
@@ -39,7 +40,12 @@ def get_vertex_memories(vector_name):
39
40
  print("Error fetching corpus:", str(e))
40
41
  ```
41
42
  """
42
- gcp_config = load_config_key("gcp_config", vector_name=vector_name, kind="vacConfig")
43
+ if config is None:
44
+ if vector_name is None:
45
+ raise ValueError("config or vector_name are required")
46
+ config = ConfigManager(vector_name)
47
+
48
+ gcp_config = config.vacConfig("gcp_config")
43
49
 
44
50
  if not rag:
45
51
  raise ValueError("Need to install vertexai module via `pip install sunholo[gcp]`")
@@ -59,18 +65,22 @@ def get_vertex_memories(vector_name):
59
65
  if vectorstore == "llamaindex":
60
66
  log.info(f"Found vectorstore {vectorstore}")
61
67
  rag_id = value.get('rag_id')
62
- if rag_id is None:
63
- raise ValueError("Must specify rag_id if using vectorstore: llamaindex")
64
-
65
68
  project_id = value.get('project_id') or gcp_config.get('project_id')
66
69
  location = value.get('location') or gcp_config.get('location')
67
70
 
68
- try:
71
+ if rag_id:
72
+ log.info("Using rag_id for using vectorstore: llamaindex")
69
73
  corpus = fetch_corpus(
70
- project_id=project_id or get_gcp_project(),
71
- location=location or global_location,
72
- rag_id=rag_id
73
- )
74
+ project_id=project_id or get_gcp_project(),
75
+ location=location or global_location,
76
+ rag_id=rag_id
77
+ )
78
+ else:
79
+ log.info(f"Using display_name {vector_name} to derive rag_id")
80
+ manager = LlamaIndexVertexCorpusManager(project_id=project_id, location=location)
81
+ corpus = manager.find_corpus_from_list(vector_name)
82
+
83
+ try:
74
84
  corpus_tool = Tool.from_retrieval(
75
85
  retrieval=rag.Retrieval(
76
86
  source=rag.VertexRagStore(
@@ -116,9 +126,14 @@ def get_vertex_memories(vector_name):
116
126
 
117
127
  return tools
118
128
 
119
- def get_google_search_grounding(vector_name):
129
+ def get_google_search_grounding(vector_name:str=None, config:ConfigManager=None):
130
+ if config is None:
131
+ if vector_name is None:
132
+ raise ValueError("Must specify one of vector_name or config")
133
+ config = ConfigManager(vector_name)
134
+
120
135
  # can't have this and llamaindex memories?
121
- ground = load_config_key("grounding", vector_name=vector_name, kind="vacConfig")
136
+ ground = config.vacConfig("grounding")
122
137
  if ground and ground.get("google_search"):
123
138
  gs_tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval())
124
139
  log.info(f"Got Search Tool: {gs_tool}")
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.79.0
3
+ Version: 0.79.2
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.79.0.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.79.2.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0