sunholo 0.70.1__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}')
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
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.70.1
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.1.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
@@ -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
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.1.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
115
- sunholo-0.70.1.dist-info/METADATA,sha256=jQEMxget9tVvjMFDj7eaY1H-ctXIOLxoqxEFXU0Fcl0,6240
116
- sunholo-0.70.1.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
117
- sunholo-0.70.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
118
- sunholo-0.70.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
119
- sunholo-0.70.1.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,,