sunholo 0.83.0__py3-none-any.whl → 0.83.1__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.
@@ -3,7 +3,7 @@ try:
3
3
  import pg8000
4
4
  import sqlalchemy
5
5
  from sqlalchemy.exc import DatabaseError, ProgrammingError
6
- from google.cloud.alloydb.connector import Connector
6
+ from langchain_google_alloydb_pg import AlloyDBEngine
7
7
  except ImportError:
8
8
  AlloyDBEngine = None
9
9
  pass
@@ -42,16 +42,14 @@ class AlloyDBClient:
42
42
  region: str=None,
43
43
  cluster_name:str=None,
44
44
  instance_name:str=None,
45
- user:str=None,
46
- password=None,
45
+ user:str=None,
47
46
  db="postgres"):
48
47
  """Initializes the AlloyDB client.
49
48
  - project_id (str): GCP project ID where the AlloyDB instance resides.
50
49
  - region (str): The region where the AlloyDB instance is located.
51
50
  - cluster_name (str): The name of the AlloyDB cluster.
52
51
  - instance_name (str): The name of the AlloyDB instance.
53
- - user (str): The database user name.
54
- - password (str): The database user's password.
52
+ - user (str): If user is None will use the default service email
55
53
  - db_name (str): The name of the database.
56
54
  """
57
55
  if config is None:
@@ -61,6 +59,7 @@ class AlloyDBClient:
61
59
  alloydb_config = config.vacConfig("alloydb_config")
62
60
  if not alloydb_config:
63
61
  raise ValueError("Must specify vac.alloydb_config")
62
+ self.config = alloydb_config
64
63
  project_id = alloydb_config["project_id"]
65
64
  region = alloydb_config["region"]
66
65
  cluster_name = alloydb_config["cluster"]
@@ -70,33 +69,34 @@ class AlloyDBClient:
70
69
  if ALLOYDB_DB is None and alloydb_config.get("database") is None:
71
70
  log.warning("Could not locate ALLOYDB_DB environment variable or 'alloydb_config.database'")
72
71
 
73
- self.database = alloydb_config.get("database") or ALLOYDB_DB,
74
- self.connector = Connector()
75
- self.inst_uri = self._build_instance_uri(project_id, region, cluster_name, instance_name)
76
- self.engine = self._create_engine(self.inst_uri, user, password, db)
77
-
78
- def _build_instance_uri(self, project_id, region, cluster_name, instance_name):
79
- return f"projects/{project_id}/locations/{region}/clusters/{cluster_name}/instances/{instance_name}"
80
-
81
- def _create_engine(self, inst_uri, user, password, db):
82
- def getconn() -> pg8000.dbapi.Connection:
83
- conn = self.connector.connect(
84
- inst_uri,
85
- "pg8000",
86
- user=user,
87
- password=password,
88
- db=db,
89
- enable_iam_auth=True,
90
- )
91
- return conn
92
-
93
- engine = sqlalchemy.create_engine(
94
- "postgresql+pg8000://",
95
- isolation_level="AUTOCOMMIT",
96
- creator=getconn
72
+ self.database = alloydb_config.get("database") or ALLOYDB_DB
73
+
74
+ if user and not user.endswith(".iam"):
75
+ raise ValueError("If you supply an IAM user it must end with .iam e.g. 'sa-cloudbuild@multivac-deploy.iam'")
76
+
77
+ self.user = user
78
+ self.engine = self._create_engine()
79
+
80
+ def _create_engine(self):
81
+ if not AlloyDBEngine:
82
+ log.error("Can't create AlloyDBEngine - install via `pip install sunholo[gcp,database]`")
83
+ raise ValueError("Can't import AlloyDBEngine")
84
+
85
+ log.info("Inititaing AlloyDB Langchain engine for database: {self.database}")
86
+
87
+ from google.cloud.alloydb.connector import IPTypes
88
+ engine = AlloyDBEngine.from_instance(
89
+ project_id=self.config["project_id"],
90
+ region=self.config["region"],
91
+ cluster=self.config["cluster"],
92
+ instance=self.config["instance"],
93
+ user=self.user,
94
+ database=self.database,
95
+ ip_type=self.config.get("ip_type") or IPTypes.PRIVATE
97
96
  )
98
- engine.dialect.description_encoding = None
99
- log.info(f"Created AlloyDB engine for {inst_uri} and user: {user}")
97
+
98
+ log.info(f"Created AlloyDB engine for {engine}")
99
+
100
100
  return engine
101
101
 
102
102
  def execute_sql(self, sql_statement):
@@ -153,7 +153,7 @@ class AlloyDBClient:
153
153
  return documents
154
154
 
155
155
  def get_sources_from_docstore(self, sources, vector_name, search_type="OR", just_source_name=False):
156
- """Fetches sources from the docstore asynchronously."""
156
+ """Fetches sources from the docstore."""
157
157
  if just_source_name:
158
158
  query = self._list_sources_from_docstore(sources, vector_name=vector_name, search_type=search_type)
159
159
  else:
@@ -163,7 +163,7 @@ class AlloyDBClient:
163
163
  return []
164
164
 
165
165
  documents = self.execute_sql(query)
166
-
166
+
167
167
  return documents
168
168
 
169
169
  def _get_sources_from_docstore(self, sources, vector_name, search_type="OR"):
@@ -133,8 +133,8 @@ def get_google_search_grounding(vector_name:str=None, config:ConfigManager=None)
133
133
  config = ConfigManager(vector_name)
134
134
 
135
135
  # can't have this and llamaindex memories?
136
- ground = config.vacConfig("grounding")
137
- if ground and ground.get("google_search"):
136
+ tools = config.vacConfig("tools")
137
+ if tools and tools.get("google_search"):
138
138
  gs_tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval())
139
139
  log.info(f"Got Search Tool: {gs_tool}")
140
140
  return gs_tool
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.83.0
3
+ Version: 0.83.1
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.83.0.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.83.1.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -59,7 +59,7 @@ sunholo/components/retriever.py,sha256=bKIVT7_18Ut3OJd0E0jyiISPnD9qkHWVjcQPT4i1_
59
59
  sunholo/components/vectorstore.py,sha256=xKk7micTRwZckaI7U6PxvFz_ZSjCH48xPTDYiDcv2tc,5913
60
60
  sunholo/database/__init__.py,sha256=bpB5Nk21kwqYj-qdVnvNgXjLsbflnH4g-San7OHMqR4,283
61
61
  sunholo/database/alloydb.py,sha256=YH8wNPS8gN-TDZEXQcVHxwd1NScHRfAxma3gK4R6KCk,11740
62
- sunholo/database/alloydb_client.py,sha256=7qO_WMTIDGK9KMZEtF00Ov7y73qTx8vSX76qObNGjgA,11611
62
+ sunholo/database/alloydb_client.py,sha256=3Jdye7vTfAVQhAmEd5FjxBQ0a_iENFmvzoOIP-pNz6I,11554
63
63
  sunholo/database/database.py,sha256=VqhZdkXUNdvWn8sUcUV3YNby1JDVf7IykPVXWBtxo9U,7361
64
64
  sunholo/database/lancedb.py,sha256=DyfZntiFKBlVPaFooNN1Z6Pl-LAs4nxWKKuq8GBqN58,715
65
65
  sunholo/database/static_dbs.py,sha256=8cvcMwUK6c32AS2e_WguKXWMkFf5iN3g9WHzsh0C07Q,442
@@ -131,12 +131,12 @@ sunholo/vertex/extensions_call.py,sha256=QeQbL3aAHlc4_-SynOzooZ_3xkQWAlcgNmFBSwL
131
131
  sunholo/vertex/extensions_class.py,sha256=2QGW28lNjoMEnaoVb3QcqEDwphclIsZthnpLUi5_Ivo,21033
132
132
  sunholo/vertex/genai_functions.py,sha256=2z6grM9H0Z79Yzx88l8mE1wXck3bRa0TWvnqZZ9ifDc,2051
133
133
  sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
134
- sunholo/vertex/memory_tools.py,sha256=pgSahVDh7GPEulu3nl-w0jb5lTClb4TCnVxPnMokNZY,7533
134
+ sunholo/vertex/memory_tools.py,sha256=q_phxgGX2TG2j2MXNULF2xGzQnQPENwjPN9nZ_A9Gh0,7526
135
135
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
136
136
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
137
- sunholo-0.83.0.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
138
- sunholo-0.83.0.dist-info/METADATA,sha256=SfRk-Y5FsBylKffBnHxxoURZxAHFfhl5SfC7JAnO-fg,7413
139
- sunholo-0.83.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
140
- sunholo-0.83.0.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
141
- sunholo-0.83.0.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
142
- sunholo-0.83.0.dist-info/RECORD,,
137
+ sunholo-0.83.1.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
138
+ sunholo-0.83.1.dist-info/METADATA,sha256=yihJkACY1C9pmb-C1dCKwI714WHSYVr_DkcCrPU_gCs,7413
139
+ sunholo-0.83.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
140
+ sunholo-0.83.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
141
+ sunholo-0.83.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
142
+ sunholo-0.83.1.dist-info/RECORD,,