sunholo 0.70.0__py3-none-any.whl → 0.70.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.
@@ -138,4 +138,4 @@ def pick_vectorstore(vs_str: str, vector_name: str, embeddings, read_only=None):
138
138
  return vectorstore
139
139
 
140
140
  else:
141
- raise NotImplementedError(f'No llm implemented for {vs_str}')
141
+ log.warning(f'No llm implemented for {vs_str}')
@@ -34,6 +34,8 @@ def do_discovery_engine(message_data, metadata, vector_name):
34
34
  vectorstore = value.get('vectorstore')
35
35
  if vectorstore == "discovery_engine" or vectorstore == "vertex_ai_search":
36
36
  log.info(f"Found vectorstore {vectorstore}")
37
+ if value.get('read_only'):
38
+ continue
37
39
  #location = gcp_config.get('location')
38
40
  corpus = DiscoveryEngineClient(
39
41
  data_store_id=vector_name,
@@ -64,6 +64,8 @@ def do_llamaindex(message_data, metadata, vector_name):
64
64
  vectorstore = value.get('vectorstore')
65
65
  if vectorstore == "llamaindex":
66
66
  log.info(f"Found vectorstore {vectorstore}")
67
+ if value.get('read_only'):
68
+ continue
67
69
  rag_id = value.get('rag_id')
68
70
  project_id = gcp_config.get('project_id')
69
71
  location = gcp_config.get('location')
sunholo/utils/parsers.py CHANGED
@@ -14,6 +14,38 @@
14
14
  import re
15
15
  import hashlib
16
16
 
17
+ def validate_extension_id(ext_id):
18
+ """
19
+ Ensures the passed string fits the criteria for an extension ID.
20
+ If not, changes it so it will be.
21
+
22
+ Criteria:
23
+ - Length should be 4-63 characters.
24
+ - Valid characters are lowercase letters, numbers, and hyphens ("-").
25
+ - Should start with a number or a lowercase letter.
26
+
27
+ Args:
28
+ ext_id (str): The extension ID to validate and correct.
29
+
30
+ Returns:
31
+ str: The validated and corrected extension ID.
32
+ """
33
+ # Replace invalid characters
34
+ ext_id = re.sub(r'[^a-z0-9-]', '-', ext_id.lower())
35
+
36
+ # Ensure it starts with a number or a lowercase letter
37
+ if not re.match(r'^[a-z0-9]', ext_id):
38
+ ext_id = 'a' + ext_id
39
+
40
+ # Trim to 63 characters
41
+ ext_id = ext_id[:63]
42
+
43
+ # Pad to at least 4 characters
44
+ while len(ext_id) < 4:
45
+ ext_id += 'a'
46
+
47
+ return ext_id
48
+
17
49
  def contains_url(message_data):
18
50
  """
19
51
  Check if the provided text contains a URL.
@@ -0,0 +1,138 @@
1
+ # https://cloud.google.com/vertex-ai/generative-ai/docs/extensions/create-extension
2
+ # https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/extension#python
3
+ from vertexai.preview import extensions
4
+ from .init import init_vertex
5
+ from ..logging import log
6
+ from ..utils.gcp_project import get_gcp_project
7
+ from ..utils.parsers import validate_extension_id
8
+
9
+ def get_extension_import_config(
10
+ display_name: str,
11
+ description: str,
12
+ api_spec_gcs: dict,
13
+ service_account_name: dict,
14
+ tool_use_examples: list):
15
+
16
+ tool_use_examples = [
17
+ {
18
+ "extensionOperation": {
19
+ "operationId": "say_hello",
20
+ },
21
+ "displayName": "Say hello in the requested language",
22
+ "query": "Say hello in French",
23
+ "requestParams": {
24
+ "fields": [
25
+ {
26
+ "key": "apiServicePrompt",
27
+ "value": {
28
+ "string_value": "French",
29
+ }
30
+ }
31
+ ]
32
+ },
33
+ "responseParams": {
34
+ "fields": [
35
+ {
36
+ "key": "apiServiceOutput",
37
+ "value": {
38
+ "string_value": "bonjour",
39
+ },
40
+ }
41
+ ],
42
+ },
43
+ "responseSummary": "Bonjour"
44
+ }
45
+ ]
46
+
47
+
48
+ return {
49
+ "displayName": display_name,
50
+ "description": description,
51
+ "manifest": {
52
+ "name": "EXTENSION_NAME_LLM",
53
+ "description": "DESCRIPTION_LLM",
54
+ "apiSpec": {
55
+ "openApiGcsUri": api_spec_gcs,
56
+ },
57
+ "authConfig": {
58
+ "authType": "OAUTH",
59
+ "oauthConfig": {"service_account": service_account_name}
60
+ }
61
+ },
62
+ "toolUseExamples": tool_use_examples,
63
+ }
64
+
65
+ # once an extension is available, call it in code here
66
+ def create_extension_instance(
67
+ display_name: str,
68
+ description: str,
69
+ open_api_gcs_uri: str,
70
+ llm_name: str=None,
71
+ llm_description: str=None,
72
+ runtime_config: dict=None,
73
+ service_account: str=None,
74
+ ):
75
+ """
76
+ Args:
77
+ - display_name: for the human. parsed to be used as extension_name
78
+ - description: for the human
79
+ - open_api_gcs_uri: location on GCS where open_ai yaml spec is
80
+ - llm_name: for the model. If None, uses display_name
81
+ - llm_description: for the model. If None, uses description
82
+ - service_account: If not specified, the Vertex AI Extension Service Agent is used to execute the extension.
83
+
84
+ """
85
+ project_id = get_gcp_project()
86
+ extension_name = f"projects/{project_id}/locations/us-central1/extensions/{validate_extension_id(display_name)}"
87
+
88
+ extension = extensions.Extension.create(
89
+ extension_name=extension_name,
90
+ display_name=display_name,
91
+ description=description,
92
+ runtime_config=runtime_config or None,
93
+ manifest={
94
+ "name": llm_name or display_name,
95
+ "description": llm_description or description,
96
+ "api_spec": {
97
+ "open_api_gcs_uri": open_api_gcs_uri
98
+ },
99
+ "auth_config": {
100
+ "auth_type": "GOOGLE_SERVICE_ACCOUNT_AUTH",
101
+ "google_service_account_config": service_account or {},
102
+ },
103
+ },
104
+ )
105
+ log.info(f"Creating Vertex Extension: {extension=}")
106
+
107
+ return extension
108
+
109
+
110
+
111
+ def create_extension_code_interpreter(
112
+ code_artifacts_bucket=None
113
+ ):
114
+
115
+ # only us-central for now
116
+ location = "us-central1"
117
+ init_vertex(location=location)
118
+
119
+ runtime_config=None
120
+ if code_artifacts_bucket:
121
+ runtime_config = {"codeInterpreterRuntimeConfig":
122
+ {
123
+ "fileInputGcsBucket": code_artifacts_bucket,
124
+ "fileOutputGcsBucket": code_artifacts_bucket
125
+ }
126
+ }
127
+
128
+ code_extension = create_extension_instance(
129
+ display_name="Code Interpreter",
130
+ description="This extension generates and executes code in the specified language",
131
+ open_api_gcs_uri="gs://vertex-extension-public/code_interpreter.yaml",
132
+ llm_name="code_interpreter_tool",
133
+ llm_description="Google Code Interpreter Extension",
134
+ runtime_config=runtime_config
135
+ )
136
+ log.info(f"Created code extension: {code_extension=}")
137
+
138
+ return code_extension
@@ -65,34 +65,43 @@ def get_vertex_memories(vector_name):
65
65
  project_id = gcp_config.get('project_id')
66
66
  location = gcp_config.get('location')
67
67
 
68
- corpus = fetch_corpus(
69
- project_id=project_id or get_gcp_project(),
70
- location=location or global_location,
71
- rag_id=rag_id
72
- )
73
- corpus_tool = Tool.from_retrieval(
74
- retrieval=rag.Retrieval(
75
- source=rag.VertexRagStore(
76
- rag_corpora=[corpus.name], # Currently only 1 corpus is allowed.
77
- similarity_top_k=10, # Optional
78
- ),
68
+ try:
69
+ corpus = fetch_corpus(
70
+ project_id=project_id or get_gcp_project(),
71
+ location=location or global_location,
72
+ rag_id=rag_id
79
73
  )
80
- )
81
- tools.append(corpus_tool)
74
+ corpus_tool = Tool.from_retrieval(
75
+ retrieval=rag.Retrieval(
76
+ source=rag.VertexRagStore(
77
+ rag_corpora=[corpus.name], # Currently only 1 corpus is allowed.
78
+ similarity_top_k=10, # Optional
79
+ ),
80
+ )
81
+ )
82
+ tools.append(corpus_tool)
83
+ except Exception as err:
84
+ log.error(f"Failed to fetch vertex.rag: {str(err)} - skipping")
85
+ continue
86
+
82
87
  elif vectorstore == "discovery_engine" or vectorstore == "vertex_ai_search":
83
88
 
84
- de = DiscoveryEngineClient(vector_name, project_id=get_gcp_project())
85
- log.info(f"Found vectorstore {vectorstore}")
89
+ try:
90
+ de = DiscoveryEngineClient(vector_name, project_id=get_gcp_project())
91
+ log.info(f"Found vectorstore {vectorstore}")
86
92
 
87
- data_store_path = de.data_store_path()
88
- corpus_tool = Tool.from_retrieval(
89
- grounding.Retrieval(grounding.VertexAISearch(datastore=data_store_path))
90
- )
91
- tools.append(corpus_tool)
93
+ data_store_path = de.data_store_path()
94
+ corpus_tool = Tool.from_retrieval(
95
+ grounding.Retrieval(grounding.VertexAISearch(datastore=data_store_path))
96
+ )
97
+ tools.append(corpus_tool)
98
+ except Exception as err:
99
+ log.error(f"Failed to fetch DiscoveryEngine groudning - {str(err)} - skipping")
100
+ continue
92
101
 
93
102
 
94
103
  if not tools:
95
- log.warning("No llamaindex Vertex corpus configurations could be found")
104
+ log.warning("No Vertex corpus configurations could be found")
96
105
 
97
106
  return tools
98
107
 
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.70.0
3
+ Version: 0.70.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.70.0.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.70.2.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -46,7 +46,7 @@ sunholo/cli/swagger.py,sha256=absYKAU-7Yd2eiVNUY-g_WLl2zJfeRUNdWQ0oH8M_HM,1564
46
46
  sunholo/components/__init__.py,sha256=IDoylb74zFKo6NIS3RQqUl0PDFBGVxM1dfUmO7OJ44U,176
47
47
  sunholo/components/llm.py,sha256=T4we3tGmqUj4tPwxQr9M6AXv_BALqZV_dRSvINan-oU,10374
48
48
  sunholo/components/retriever.py,sha256=jltG91N5r2P9RWKPW8A8tU3ilghciBczxapauW83Ir8,6377
49
- sunholo/components/vectorstore.py,sha256=BxtMF_wX8Zrexr67P07OTSJPjucTewmcPM5OQwIXHPM,5630
49
+ sunholo/components/vectorstore.py,sha256=egFPeejf8kwM3Wx486X-FBzwoSSEziC2NV4LdxB2sXY,5616
50
50
  sunholo/database/__init__.py,sha256=Zz0Shcq-CtStf9rJGIYB_Ybzb8rY_Q9mfSj-nviM490,241
51
51
  sunholo/database/alloydb.py,sha256=d9W0pbZB0jTVIGF5OVaQ6kXHo-X3-6e9NpWNmV5e9UY,10464
52
52
  sunholo/database/alloydb_client.py,sha256=AYA0SSaBy-1XEfeZI97sMGehfrwnfbwZ8sE0exzI2E0,7254
@@ -61,7 +61,7 @@ sunholo/database/sql/sb/delete_source_row.sql,sha256=r6fEuUKdbiLHCDGKSbKINDCpJjs
61
61
  sunholo/database/sql/sb/return_sources.sql,sha256=89KAnxfK8n_qGK9jy1OQT8f9n4uYUtYL5cCxbC2mj_c,255
62
62
  sunholo/database/sql/sb/setup.sql,sha256=CvoFvZQev2uWjmFa3aj3m3iuPFzAAJZ0S7Qi3L3-zZI,89
63
63
  sunholo/discovery_engine/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
64
- sunholo/discovery_engine/chunker_handler.py,sha256=puNnV6vKnjNqk28FLnsIPMNsC-1Y6s20PK7ioi8qwzc,4491
64
+ sunholo/discovery_engine/chunker_handler.py,sha256=H1HHDqWMCkchJER1_oU9TOLxqf2PygiMO6CL3uKZP64,4563
65
65
  sunholo/discovery_engine/create_new.py,sha256=7oZG78T6lW0EspRzlo7-qRyXFSuFxDn2dfSAVEaqlqY,978
66
66
  sunholo/discovery_engine/discovery_engine_client.py,sha256=n4euIZjc3pWUYfoFhpvReIzHXnIYO8J9nKC8euKSTgY,14581
67
67
  sunholo/embedder/__init__.py,sha256=sI4N_CqgEVcrMDxXgxKp1FsfsB4FpjoXgPGkl4N_u4I,44
@@ -76,7 +76,7 @@ sunholo/langfuse/prompts.py,sha256=HO4Zy9usn5tKooBPCKksuw4Lff3c03Ny5wqn4ce_xZM,1
76
76
  sunholo/llamaindex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  sunholo/llamaindex/generate.py,sha256=l1Picr-hVwkmAUD7XmTCa63qY9ERliFHQXwyX3BqB2Q,686
78
78
  sunholo/llamaindex/get_files.py,sha256=6rhXCDqQ_lrIapISQ_OYQDjiSATXvS_9m3qq53-oIl0,781
79
- sunholo/llamaindex/import_files.py,sha256=LIFBXxgXgRYMdVpq3FkycIoMMhLSXkKdKzK7qDuqOmQ,5566
79
+ sunholo/llamaindex/import_files.py,sha256=h5kQCNtWoMNh9Hgn_kIJvV-Vu_AwwGIvbmuNq3yQ4Rk,5638
80
80
  sunholo/lookup/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
81
81
  sunholo/lookup/model_lookup.yaml,sha256=O7o-jP53MLA06C8pI-ILwERShO-xf6z_258wtpZBv6A,739
82
82
  sunholo/patches/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -103,17 +103,18 @@ sunholo/utils/config.py,sha256=5lzO9CkLpDslp66ZwSBC_95aA1FQs-zpiOLi5YaYWbM,8907
103
103
  sunholo/utils/config_schema.py,sha256=Wv-ncitzljOhgbDaq9qnFqH5LCuxNv59dTGDWgd1qdk,4189
104
104
  sunholo/utils/gcp.py,sha256=uueODEpA-P6O15-t0hmcGC9dONLO_hLfzSsSoQnkUss,4854
105
105
  sunholo/utils/gcp_project.py,sha256=0ozs6tzI4qEvEeXb8MxLnCdEVoWKxlM6OH05htj7_tc,1325
106
- sunholo/utils/parsers.py,sha256=NEfH6ZIYfMa-nuVaYmq9KhS0MNAYoKDbxvibT5MvGqM,4403
106
+ sunholo/utils/parsers.py,sha256=z98cQ1v2_ScnqHxCtApNeAN2the8MdvS6RpKL6vWyOU,5287
107
107
  sunholo/utils/timedelta.py,sha256=BbLabEx7_rbErj_YbNM0MBcaFN76DC4PTe4zD2ucezg,493
108
108
  sunholo/utils/user_ids.py,sha256=SQd5_H7FE7vcTZp9AQuQDWBXd4FEEd7TeVMQe1H4Ny8,292
109
109
  sunholo/utils/version.py,sha256=jjU_4anXBikJxPg0Wur0X-B7-ec1tC7jToykAnAG9Dg,108
110
110
  sunholo/vertex/__init__.py,sha256=JvHcGFuv6R_nAhY2AdoqqhMpJ5ugeWPZ_svGhWrObBk,136
111
+ sunholo/vertex/extensions.py,sha256=LDeuCp8RcHHACdlYhGyGjMoG5v70132HWA_2u-tzcAo,4533
111
112
  sunholo/vertex/init.py,sha256=RLjQppTUwubWgwf2PoAke-EtcwlVkFPaPMYvUsMw1KQ,2029
112
- sunholo/vertex/memory_tools.py,sha256=Qo6-uV0_SlwBsCEYsPnrr1l_2UH_zLT_xPxiC9XxGQg,5278
113
+ sunholo/vertex/memory_tools.py,sha256=l2jNRFLjYpiNJULDZQq5b8fEEaqBQFPM4ehM9NhDHss,5718
113
114
  sunholo/vertex/safety.py,sha256=3meAX0HyGZYrH7rXPUAHxtI_3w_zoy_RX7Shtkoa660,1275
114
- sunholo-0.70.0.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
115
- sunholo-0.70.0.dist-info/METADATA,sha256=Jc55TzM3gNp1oMX2mF6sW-55-BjYesOKO_mVa9U15y4,6240
116
- sunholo-0.70.0.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
117
- sunholo-0.70.0.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
118
- sunholo-0.70.0.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
119
- sunholo-0.70.0.dist-info/RECORD,,
115
+ sunholo-0.70.2.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
116
+ sunholo-0.70.2.dist-info/METADATA,sha256=657GueOuXqqE3LzXDsN6xgnIbPV16zJX7B03nF5upX4,6240
117
+ sunholo-0.70.2.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
118
+ sunholo-0.70.2.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
119
+ sunholo-0.70.2.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
120
+ sunholo-0.70.2.dist-info/RECORD,,