sunholo 0.101.6__py3-none-any.whl → 0.101.8__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/genai/images.py CHANGED
@@ -2,20 +2,21 @@ import re
2
2
  from ..utils.mime import guess_mime_type
3
3
  from ..gcs import get_bytes_from_gcs
4
4
  from ..custom_logging import log
5
- import io
6
5
  import os
6
+ import tempfile
7
7
  try:
8
8
  import google.generativeai as genai
9
9
  except ImportError:
10
10
  genai = None
11
11
 
12
- def extract_gs_images_and_genai_upload(content:str):
12
+ def extract_gs_images_and_genai_upload(content: str):
13
13
  # Regular expression to find gs:// URLs
14
14
  pattern = r'gs://[^ ]+\.(?:png|jpg|jpeg|pdf)'
15
15
 
16
16
  gs_matches = re.findall(pattern, content)
17
17
  unique_gs_matches = set(gs_matches)
18
18
  output_gs_images = []
19
+
19
20
  for gs_uri in unique_gs_matches:
20
21
  mime_type = guess_mime_type(gs_uri)
21
22
  if mime_type is None:
@@ -25,14 +26,23 @@ def extract_gs_images_and_genai_upload(content:str):
25
26
  image_bytes = get_bytes_from_gcs(gs_uri)
26
27
  if image_bytes is None:
27
28
  continue
28
- image_file = io.BytesIO(image_bytes)
29
- image_file.name = os.path.basename(gs_uri) # Assign a name, as some APIs require it
30
-
31
- try:
32
- uploaded_file = genai.upload_file(image_file)
33
- output_gs_images.append(uploaded_file)
34
-
35
- except Exception as e:
36
- log.error(f"Error adding {gs_uri} to base64: {str(e)}")
29
+
30
+ # Get the basename from the gs_uri to use as the file name
31
+ file_name = os.path.basename(gs_uri)
32
+
33
+ # Create a temporary directory and write the file with the basename
34
+ with tempfile.TemporaryDirectory() as temp_dir:
35
+ temp_file_path = os.path.join(temp_dir, file_name)
36
+
37
+ # Write the BytesIO object to the file
38
+ with open(temp_file_path, 'wb') as temp_file:
39
+ temp_file.write(image_bytes)
40
+
41
+ # Pass the temporary file's path to the upload function
42
+ try:
43
+ uploaded_file = genai.upload_file(temp_file_path)
44
+ output_gs_images.append(uploaded_file)
45
+ except Exception as e:
46
+ log.error(f"Error adding {gs_uri} to base64: {str(e)}")
37
47
 
38
- return output_gs_images
48
+ return output_gs_images
@@ -368,8 +368,8 @@ class GenAIFunctionProcessor:
368
368
  if not isinstance(string, str):
369
369
  return string
370
370
 
371
- clean = string.encode('utf-8').decode('unicode_escape')
372
- log.info(f"Cleaning:\n{string}\n > to >\n{clean}")
371
+ clean = string.encode('utf-8', errors='replace').decode('unicode_escape')
372
+ log.info(f"Cleaning:\n{string[:100]}\n > to >\n{clean[:100]}")
373
373
 
374
374
  return clean
375
375
 
sunholo/utils/mime.py CHANGED
@@ -60,4 +60,5 @@ def guess_mime_type(file_path: str) -> str:
60
60
  "jsx": "text/jsx",
61
61
  }
62
62
 
63
- return extension_to_type.get(ext, "")
63
+ return extension_to_type.get(ext, "")
64
+
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.101.6
3
+ Version: 0.101.8
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.101.6.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.101.8.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -86,9 +86,9 @@ sunholo/gcs/download_url.py,sha256=Ul81n1rklr8WogPsuxWWD1Nr8RHU451LzHPMJNhAKzw,6
86
86
  sunholo/gcs/extract_and_sign.py,sha256=paRrTCvCN5vkQwCB7OSkxWi-pfOgOtZ0bwdXE08c3Ps,1546
87
87
  sunholo/gcs/metadata.py,sha256=oQLcXi4brsZ74aegWyC1JZmhlaEV270HS5_UWtAYYWE,898
88
88
  sunholo/genai/__init__.py,sha256=dBl6IA3-Fx6-Vx81r0XqxHlUq6WeW1iDX188dpChu8s,115
89
- sunholo/genai/images.py,sha256=WaeO705mK0BOz1k7OwsGslw7qF1WiyE_zsueYt07vV8,1191
89
+ sunholo/genai/images.py,sha256=eW5V2h2JdNqLkaw_u-pJSzu7edHzvrCWPLirolQXX5s,1617
90
90
  sunholo/genai/init.py,sha256=yG8E67TduFCTQPELo83OJuWfjwTnGZsyACospahyEaY,687
91
- sunholo/genai/process_funcs_cls.py,sha256=B5PAKWyCAjc1hc5SBV-x3aNPPOtuZOs09HHLtuh9luM,28769
91
+ sunholo/genai/process_funcs_cls.py,sha256=r8WF0kF5nYhC3qBb9p8X5101taq3lvfhEqs3EPg5QJY,28799
92
92
  sunholo/genai/safety.py,sha256=mkFDO_BeEgiKjQd9o2I4UxB6XI7a9U-oOFjZ8LGRUC4,1238
93
93
  sunholo/invoke/__init__.py,sha256=o1RhwBGOtVK0MIdD55fAIMCkJsxTksi8GD5uoqVKI-8,184
94
94
  sunholo/invoke/async_class.py,sha256=G8vD2H94fpBc37mSJSQODEKJ67P2mPQEHabtDaLOvxE,8033
@@ -134,7 +134,7 @@ sunholo/utils/config_class.py,sha256=aNhxhEHIxRvqQNq_9wFJt1yM9U1ypahCVZ3NzPWuay4
134
134
  sunholo/utils/config_schema.py,sha256=Wv-ncitzljOhgbDaq9qnFqH5LCuxNv59dTGDWgd1qdk,4189
135
135
  sunholo/utils/gcp.py,sha256=uueODEpA-P6O15-t0hmcGC9dONLO_hLfzSsSoQnkUss,4854
136
136
  sunholo/utils/gcp_project.py,sha256=Fa0IhCX12bZ1ctF_PKN8PNYd7hihEUfb90kilBfUDjg,1411
137
- sunholo/utils/mime.py,sha256=hTtSilPDK9oJe8yJqTcPGNV4fIUyaL43Ql8ZncB1DlU,1867
137
+ sunholo/utils/mime.py,sha256=IBir-PcIkwM6GCWsohOkCXqdQWO6PxIgvmXOtaeu71U,1869
138
138
  sunholo/utils/parsers.py,sha256=wES0fRn3GONoymRXOXt-z62HCoOiUvvFXa-MfKfjCls,6421
139
139
  sunholo/utils/timedelta.py,sha256=BbLabEx7_rbErj_YbNM0MBcaFN76DC4PTe4zD2ucezg,493
140
140
  sunholo/utils/user_ids.py,sha256=SQd5_H7FE7vcTZp9AQuQDWBXd4FEEd7TeVMQe1H4Ny8,292
@@ -147,9 +147,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
147
147
  sunholo/vertex/memory_tools.py,sha256=tBZxqVZ4InTmdBvLlOYwoSEWu4-kGquc-gxDwZCC4FA,7667
148
148
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
149
149
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
150
- sunholo-0.101.6.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
151
- sunholo-0.101.6.dist-info/METADATA,sha256=7LMxd_27pGx2NVLL0ivo0PKmwp685rW8c_Uyny4F9ZM,8312
152
- sunholo-0.101.6.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
153
- sunholo-0.101.6.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
154
- sunholo-0.101.6.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
155
- sunholo-0.101.6.dist-info/RECORD,,
150
+ sunholo-0.101.8.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
151
+ sunholo-0.101.8.dist-info/METADATA,sha256=ebKNiCxn5C0tp2_i76J48-qN7Uf7R83EvJDY6aLJOPI,8312
152
+ sunholo-0.101.8.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
153
+ sunholo-0.101.8.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
154
+ sunholo-0.101.8.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
155
+ sunholo-0.101.8.dist-info/RECORD,,