sunholo 0.76.2__py3-none-any.whl → 0.76.3__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.
@@ -0,0 +1,55 @@
1
+ # needs to be in minimal to check gcp
2
+ import os
3
+
4
+ import google.auth
5
+ from google.auth.transport import requests
6
+ from ..utils.gcp import is_running_on_gcp
7
+
8
+
9
+ from ..logging import log
10
+
11
+ def get_default_email():
12
+ if not refresh_credentials():
13
+ log.error("Could not refresh the credentials properly.")
14
+ return None
15
+ # https://stackoverflow.com/questions/64234214/how-to-generate-a-blob-signed-url-in-google-cloud-run
16
+
17
+ gcs_credentials, project_id = get_default_creds()
18
+
19
+ service_account_email = getattr(gcs_credentials, 'service_account_email', None)
20
+ # If you use a service account credential, you can use the embedded email
21
+ if not service_account_email:
22
+ service_account_email = os.getenv('GCS_MAIL_USER')
23
+ if not service_account_email:
24
+ log.error("Could not create the credentials for signed requests - no credentials.service_account_email or GCS_MAIL_USER with roles/iam.serviceAccountTokenCreator")
25
+
26
+ return None
27
+
28
+ log.info(f"Found default email: {service_account_email=} for {project_id=}")
29
+ return service_account_email
30
+
31
+ def get_default_creds():
32
+ gcs_credentials = None
33
+ project_id = None
34
+ gcs_credentials, project_id = google.auth.default()
35
+
36
+ return gcs_credentials, project_id
37
+
38
+ def refresh_credentials():
39
+ if not is_running_on_gcp():
40
+ log.debug("Not running on Google Cloud so no credentials available for GCS.")
41
+ return False
42
+
43
+ gcs_credentials, project_id = get_default_creds()
44
+
45
+ if not gcs_credentials.token or gcs_credentials.expired or not gcs_credentials.valid:
46
+ try:
47
+ gcs_credentials.refresh(requests.Request())
48
+
49
+ return True
50
+
51
+ except Exception as e:
52
+ log.error(f"Failed to refresh gcs credentials: {e}")
53
+
54
+ return False
55
+
sunholo/cli/vertex.py CHANGED
@@ -3,8 +3,8 @@ from ..vertex import VertexAIExtensions
3
3
  from .sun_rich import console
4
4
 
5
5
  def deploy_extension(args):
6
- vex = VertexAIExtensions()
7
- console.rule(f"Creating Vertex extension '{args.display_name}'")
6
+ vex = VertexAIExtensions(args.project)
7
+ console.rule(f"Creating Vertex extension '{args.display_name}' within '{args.project}'")
8
8
 
9
9
  vex.create_extension(
10
10
  args.display_name,
@@ -3,8 +3,6 @@ from urllib.parse import quote
3
3
  from datetime import datetime, timedelta
4
4
 
5
5
  # needs to be in minimal to check gcp
6
- import google.auth
7
- from google.auth.transport import requests
8
6
  from google.auth.exceptions import RefreshError
9
7
 
10
8
  try:
@@ -14,6 +12,7 @@ except ImportError:
14
12
 
15
13
  from ..logging import log
16
14
  from ..utils.gcp import is_running_on_gcp
15
+ from ..auth.refresh import refresh_credentials, get_default_creds, get_default_email
17
16
  from io import BytesIO
18
17
  try:
19
18
  from PIL import Image
@@ -77,47 +76,22 @@ def get_bytes_from_gcs(gs_uri):
77
76
 
78
77
  if is_running_on_gcp():
79
78
  # Perform a refresh request to get the access token of the current credentials (Else, it's None)
80
- gcs_credentials, project_id = google.auth.default()
79
+ gcs_credentials, project_id = get_default_creds()
81
80
  # Prepare global variables for client reuse
82
81
  if storage:
83
82
  gcs_client = storage.Client()
84
83
 
85
- def refresh_credentials():
86
- if not is_running_on_gcp():
87
- log.debug("Not running on Google Cloud so no credentials available for GCS.")
88
- return False
89
- if not gcs_credentials.token or gcs_credentials.expired or not gcs_credentials.valid:
90
- try:
91
- gcs_credentials.refresh(requests.Request())
92
- except Exception as e:
93
- log.error(f"Failed to refresh gcs credentials: {e}")
94
- return False
95
- return True
96
-
97
- refresh_credentials()
98
-
99
84
  def get_bucket(bucket_name):
100
85
  if bucket_name not in gcs_bucket_cache:
101
86
  gcs_bucket_cache[bucket_name] = gcs_client.get_bucket(bucket_name)
102
87
  return gcs_bucket_cache[bucket_name]
103
88
 
104
89
  def sign_gcs_url(bucket_name:str, object_name:str, expiry_secs = 86400):
105
- if not refresh_credentials():
106
- log.error("Could not refresh the credentials properly.")
107
- return None
108
- # https://stackoverflow.com/questions/64234214/how-to-generate-a-blob-signed-url-in-google-cloud-run
90
+
91
+ service_account_email = get_default_email()
109
92
 
110
93
  expires = datetime.now() + timedelta(seconds=expiry_secs)
111
94
 
112
- service_account_email = getattr(gcs_credentials, 'service_account_email', None)
113
- # If you use a service account credential, you can use the embedded email
114
- if not service_account_email:
115
- service_account_email = os.getenv('GCS_MAIL_USER')
116
- if service_account_email is None:
117
- log.error("For local testing must set a GCS_MAIL_USER to sign GCS URLs")
118
- log.error("Could not create the credentials for signed requests - no credentials.service_account_email or GCS_MAIL_USER with roles/iam.serviceAccountTokenCreator")
119
- return None
120
-
121
95
  try:
122
96
  bucket = get_bucket(bucket_name)
123
97
  blob = bucket.blob(object_name)
@@ -50,7 +50,7 @@ class VertexAIExtensions:
50
50
  operation_params = operation_params)
51
51
  ```
52
52
  """
53
- def __init__(self):
53
+ def __init__(self, project_id=None):
54
54
  if extensions is None:
55
55
  raise ImportError("VertexAIExtensions needs vertexai.previewextensions to be installed. Install via `pip install sunholo[gcp]`")
56
56
 
@@ -70,6 +70,7 @@ class VertexAIExtensions:
70
70
  self.manifest = {}
71
71
  self.created_extensions = []
72
72
  self.bucket_name = os.getenv('EXTENSIONS_BUCKET')
73
+ init_vertex(location=self.location, project_id=project_id)
73
74
 
74
75
  def list_extensions(self, project_id:str=None):
75
76
  project_id = project_id or get_gcp_project()
@@ -113,7 +114,7 @@ class VertexAIExtensions:
113
114
  raise ValueError('Please specify env var EXTENSIONS_BUCKET for location to upload openapi spec')
114
115
 
115
116
 
116
- self.openapi_file_gcs = self.upload_to_gcs(filename, bucket_name=self.bucket_name)
117
+ self.openapi_file_gcs = self.upload_to_gcs(filename)
117
118
 
118
119
  def load_tool_use_examples(self, filename: str):
119
120
  import yaml
@@ -211,7 +212,7 @@ class VertexAIExtensions:
211
212
  log.info(f"Setting extension bucket name to {bucket_name}")
212
213
  self.bucket_name = bucket_name
213
214
 
214
- listed_extensions = self.list_extensions()
215
+ listed_extensions = self.list_extensions(project_id)
215
216
  log.info(f"Listing extensions:\n {listed_extensions}")
216
217
  for ext in listed_extensions:
217
218
  if ext.get('display_name') == display_name:
@@ -248,7 +249,7 @@ class VertexAIExtensions:
248
249
  return extension.resource_name
249
250
 
250
251
  def execute_extension(self, operation_id: str, operation_params: dict, extension_id: str=None, project_id: str=None):
251
- init_vertex(location=self.location)
252
+ init_vertex(location=self.location, project_id=project_id)
252
253
 
253
254
  if not extension_id:
254
255
  extension_name = self.created_extension.resource_name
sunholo/vertex/init.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from ..logging import log
2
2
  from ..utils.gcp_project import get_gcp_project
3
+ from ..auth.refresh import get_default_email
3
4
  import os
4
5
 
5
6
  def init_genai():
@@ -19,7 +20,7 @@ def init_genai():
19
20
 
20
21
  genai.configure(api_key=GOOGLE_API_KEY)
21
22
 
22
- def init_vertex(gcp_config=None, location="eu"):
23
+ def init_vertex(gcp_config=None, location="eu", project_id=None):
23
24
  """
24
25
  Initializes the Vertex AI environment using the provided Google Cloud Platform configuration.
25
26
 
@@ -62,6 +63,10 @@ def init_vertex(gcp_config=None, location="eu"):
62
63
  project_id = gcp_config.get('project_id')
63
64
  location = gcp_config.get('location') or location
64
65
  else:
65
- project_id = get_gcp_project()
66
+ project_id = project_id or get_gcp_project()
67
+
68
+ log.info(f"Auth with email: {get_default_email()} in {project_id}")
66
69
 
67
70
  vertexai.init(project=project_id, location=location)
71
+
72
+
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.76.2
3
+ Version: 0.76.3
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.76.2.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.76.3.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -19,6 +19,7 @@ sunholo/archive/__init__.py,sha256=qNHWm5rGPVOlxZBZCpA1wTYPbalizRT7f8X4rs2t290,3
19
19
  sunholo/archive/archive.py,sha256=C-UhG5x-XtZ8VheQp92IYJqgD0V3NFQjniqlit94t18,1197
20
20
  sunholo/auth/__init__.py,sha256=Y4Wpd6m0d3R7U7Ser51drO0Eg7VrfSS2VphZxRgtih8,70
21
21
  sunholo/auth/gcloud.py,sha256=PdbwkuTdRi4RKBmgG9uwsReegqC4VG15_tw5uzmA7Fs,298
22
+ sunholo/auth/refresh.py,sha256=uOdT7oQRVl0YsUP__NXj6PdUdLyXFSv2ylwF283esuw,1831
22
23
  sunholo/auth/run.py,sha256=SG53ToQJ8hyjdN4634osfvDEUv5gJU6dlHe4nGwMMYU,2612
23
24
  sunholo/azure/__init__.py,sha256=S1WQ5jndzNgzhSBh9UpX_yw7hRVm3hCzkAWNxUdK4dA,48
24
25
  sunholo/azure/event_grid.py,sha256=Gky7D5a-xxMzbcst_wOFfcI8AH5qOzWbKbt5iqOTr6U,2606
@@ -48,7 +49,7 @@ sunholo/cli/merge_texts.py,sha256=U9vdMwKmcPoc6iPOWX5MKSxn49dNGbNzVLw8ui5PhEU,18
48
49
  sunholo/cli/run_proxy.py,sha256=OeR12ZfnasbJ-smBZQznmGufoDa4iNjUN9FCFo5JxSc,11520
49
50
  sunholo/cli/sun_rich.py,sha256=UpMqeJ0C8i0pkue1AHnnyyX0bFJ9zZeJ7HBR6yhuA8A,54
50
51
  sunholo/cli/swagger.py,sha256=absYKAU-7Yd2eiVNUY-g_WLl2zJfeRUNdWQ0oH8M_HM,1564
51
- sunholo/cli/vertex.py,sha256=SJkYBvzf2zyFLdYD8iBJhsrt-iSmw4pUtSflAG053Iw,2065
52
+ sunholo/cli/vertex.py,sha256=yN1ezeiweV1UIBZYvDYgtyMS0dXH374rYMxVVHid9UY,2101
52
53
  sunholo/components/__init__.py,sha256=IDoylb74zFKo6NIS3RQqUl0PDFBGVxM1dfUmO7OJ44U,176
53
54
  sunholo/components/llm.py,sha256=T4we3tGmqUj4tPwxQr9M6AXv_BALqZV_dRSvINan-oU,10374
54
55
  sunholo/components/retriever.py,sha256=BFUw_6turT3CQJZWv_uXylmH5fHdb0gKfKJrQ_j6MGY,6533
@@ -74,7 +75,7 @@ sunholo/embedder/__init__.py,sha256=sI4N_CqgEVcrMDxXgxKp1FsfsB4FpjoXgPGkl4N_u4I,
74
75
  sunholo/embedder/embed_chunk.py,sha256=d_dIzeNF630Q0Ar-u1hxos60s0tLIImJccAvuo_LTIw,6814
75
76
  sunholo/gcs/__init__.py,sha256=SZvbsMFDko40sIRHTHppA37IijvJTae54vrhooEF5-4,90
76
77
  sunholo/gcs/add_file.py,sha256=vWRjxuHBQkrPNrr9tRSFGT0N_nVIw120mqDEHiaHwuQ,7115
77
- sunholo/gcs/download_url.py,sha256=Kg9EdPnc---YSUTAZEdzJeITjDtQSLMYwb4uiU9LhIQ,6440
78
+ sunholo/gcs/download_url.py,sha256=iCIPESi2viQ-TcCINpbJXxUt7XJFFpF0KiVgSA6zFis,5228
78
79
  sunholo/gcs/metadata.py,sha256=C9sMPsHsq1ETetdQCqB3EBs3Kws8b8QHS9L7ei_v5aw,891
79
80
  sunholo/invoke/__init__.py,sha256=Dxivd9cU92X4v2JAZet4f7L2RJ5l_30rt9t2NiD-iLA,55
80
81
  sunholo/invoke/invoke_vac_utils.py,sha256=0JkCZDBEkRImzuB-nf70dF75t0WKtgA9G4TdaQJUB08,5240
@@ -119,13 +120,13 @@ sunholo/utils/timedelta.py,sha256=BbLabEx7_rbErj_YbNM0MBcaFN76DC4PTe4zD2ucezg,49
119
120
  sunholo/utils/user_ids.py,sha256=SQd5_H7FE7vcTZp9AQuQDWBXd4FEEd7TeVMQe1H4Ny8,292
120
121
  sunholo/utils/version.py,sha256=P1QAJQdZfT2cMqdTSmXmcxrD2PssMPEGM-WI6083Fck,237
121
122
  sunholo/vertex/__init__.py,sha256=XH7FUKxdIgN9H2iDcWxL3sRnVHC3297G24RqEn4Ob0Y,240
122
- sunholo/vertex/extensions_class.py,sha256=14DyrCvoLanICL11QR0Lzf7lwFcIRQRLNuF6pw9E0l0,17715
123
- sunholo/vertex/init.py,sha256=-w7b9GKsyJnAJpYHYz6_zBUtmeJeLXlEkgOfwoe4DEI,2715
123
+ sunholo/vertex/extensions_class.py,sha256=cVpr0AbbBQV9WWZ9_X7S52aXclXNxvHywHDoBjDTxl8,17802
124
+ sunholo/vertex/init.py,sha256=aLdNjrX3bUPfnWRhKUg5KUxSu0Qnq2YvuFNsgml4QEY,2866
124
125
  sunholo/vertex/memory_tools.py,sha256=pomHrDKqvY8MZxfUqoEwhdlpCvSGP6KmFJMVKOimXjs,6842
125
126
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
126
- sunholo-0.76.2.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
127
- sunholo-0.76.2.dist-info/METADATA,sha256=PBcc_hvS8Nce_I-MY_lfpMo6VxhE5PIZ42vsv21COiM,7136
128
- sunholo-0.76.2.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
129
- sunholo-0.76.2.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
130
- sunholo-0.76.2.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
131
- sunholo-0.76.2.dist-info/RECORD,,
127
+ sunholo-0.76.3.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
128
+ sunholo-0.76.3.dist-info/METADATA,sha256=SHLQ84yDXYXlm3Mb1sCqMUZtwXxzsd2UzgEwrd-fU_4,7136
129
+ sunholo-0.76.3.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
130
+ sunholo-0.76.3.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
131
+ sunholo-0.76.3.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
132
+ sunholo-0.76.3.dist-info/RECORD,,