sunholo 0.90.5__py3-none-any.whl → 0.91.0__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/components/llm.py CHANGED
@@ -114,9 +114,18 @@ def llm_str_to_llm(llm_str, model=None, vector_name=None, config=None):
114
114
  elif llm_str == 'anthropic':
115
115
  from langchain_anthropic import ChatAnthropic
116
116
  if model is None:
117
- model = 'claude-3-opus-20240229'
117
+ model = 'claude-3-5-sonnet-20240620'
118
118
  log.info(f"No 'model' value in config file - selecting default {model}")
119
119
  return ChatAnthropic(model_name = model, temperature=0)
120
+ elif llm_str == 'anthropic-vertex':
121
+ from langchain_google_vertexai.model_garden import ChatAnthropicVertex
122
+ if model is None:
123
+ model = "claude-3-5-sonnet@20240620"
124
+ log.info(f"No 'model' value in config file - selecting default {model}")
125
+ gcp_config = config.vacConfig("gcp_config")
126
+ return ChatAnthropicVertex(model_name=model,
127
+ project=gcp_config.get('project_id'),
128
+ location=gcp_config.get('location'))
120
129
 
121
130
  if llm_str is None:
122
131
  raise NotImplementedError(f'No llm implemented for {llm_str}')
@@ -3,7 +3,7 @@ try:
3
3
  import pg8000
4
4
  import sqlalchemy
5
5
  from sqlalchemy.exc import DatabaseError, ProgrammingError
6
- from langchain_google_alloydb_pg import AlloyDBEngine
6
+ from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBVectorStore
7
7
  except ImportError:
8
8
  AlloyDBEngine = None
9
9
  pass
@@ -12,6 +12,7 @@ from .database import get_vector_size
12
12
  from .uuid import generate_uuid_from_object_id
13
13
  from ..custom_logging import log
14
14
  from ..utils import ConfigManager
15
+ from ..components import get_embeddings
15
16
 
16
17
  class AlloyDBClient:
17
18
  """
@@ -62,6 +63,7 @@ class AlloyDBClient:
62
63
  if not alloydb_config:
63
64
  raise ValueError("Must specify vac.alloydb_config")
64
65
  self.config = alloydb_config
66
+ self.vector_name = self.config.vector_name
65
67
  project_id = alloydb_config["project_id"]
66
68
  region = alloydb_config["region"]
67
69
  cluster_name = alloydb_config["cluster"]
@@ -87,6 +89,11 @@ class AlloyDBClient:
87
89
  log.info("Build with Langchain engine - will use default service account for auth")
88
90
  self.engine = self._create_engine()
89
91
  self.engine_type = "langchain"
92
+
93
+ if self.engine_type == "langchain":
94
+ self.vectorstore = self.get_vectorstore()
95
+ else:
96
+ self.vectorstore = None
90
97
 
91
98
  def _build_instance_uri(self, project_id, region, cluster_name, instance_name):
92
99
  return f"projects/{project_id}/locations/{region}/clusters/{cluster_name}/instances/{instance_name}"
@@ -134,6 +141,52 @@ class AlloyDBClient:
134
141
 
135
142
  return engine
136
143
 
144
+ def _get_embedder(self, vector_name):
145
+ return get_embeddings(vector_name)
146
+
147
+ def get_vectorstore(self):
148
+ if self.engine_type != "langchain":
149
+ raise ValueError("Not available using pg8000 engine")
150
+
151
+ if self.vector_name is None:
152
+ raise ValueError("No vectorname found - init with ConfigManager?")
153
+
154
+ vector_size = get_vector_size(self.vector_name)
155
+ table_name = f"{self.vector_name}_vectorstore_{vector_size}"
156
+
157
+ log.info(f"Initialised AlloyDBClient with AlloyDBVectorStore: {table_name}")
158
+ self.vectorstore = AlloyDBVectorStore.create_sync(
159
+ engine=self.engine,
160
+ table_name=table_name,
161
+ embedding_service=self._get_embedder(self.vector_name),
162
+ metadata_columns=["source", "docstore_doc_id"]
163
+ #metadata_columns=["source", "eventTime"]
164
+ )
165
+
166
+ return self.vectorstore
167
+
168
+ def _similarity_search(self, query, source_filter:str="", free_filter:str=None):
169
+
170
+ if free_filter is None:
171
+ source_filter_cmd = f"source %LIKE% {source_filter}" if source_filter else None
172
+ else:
173
+ source_filter_cmd = free_filter
174
+
175
+ log.info(f"Similarity search for {query} and {source_filter_cmd}")
176
+
177
+ return query, source_filter_cmd
178
+
179
+ def similarity_search(self, query, source_filter:str="", free_filter:str=None, k:int=5):
180
+
181
+ query, source_filter_cmd = self._similarity_search(query, source_filter, free_filter)
182
+
183
+ return self.vectorstore.similarity_search(query, filter=source_filter_cmd, k=k)
184
+
185
+ async def asimilarity_search(self, query, source_filter:str="", free_filter:str=None, k:int=5):
186
+ query, source_filter_cmd = self._similarity_search(query, source_filter, free_filter)
187
+
188
+ return await self.vectorstore.asimilarity_search(query, filter=source_filter_cmd, k=k)
189
+
137
190
  def execute_sql(self, sql_statement):
138
191
  if self.engine_type == "pg8000":
139
192
  return self._execute_sql_pg8000(sql_statement)
sunholo/langfuse/evals.py CHANGED
@@ -3,6 +3,7 @@ import json
3
3
 
4
4
  from ..pubsub import decode_pubsub_message
5
5
  from langfuse import Langfuse
6
+ import traceback
6
7
  from ..custom_logging import log
7
8
 
8
9
  # Example of how eval_funcs might be structured
@@ -71,7 +72,7 @@ def do_evals(trace_id, eval_funcs: list=[eval_length], **kwargs) -> dict:
71
72
  try:
72
73
  eval_result = eval_func(trace) # Assuming eval_func returns a dict with 'score' and 'reason'
73
74
  except Exception as e:
74
- eval_result = {"score": 0, "reason":f"ERROR: {str(e)}"}
75
+ eval_result = {"score": 0, "reason":f"ERROR: {str(e)} traceback: {traceback.format_exc()}"}
75
76
  eval_results.append(eval_result)
76
77
 
77
78
  eval_name = eval_func.__name__
@@ -178,6 +178,8 @@ class LlamaIndexVertexCorpusManager:
178
178
 
179
179
  def query_corpus(self, query:str, corpus_disply_name:str):
180
180
  corpus = self.find_corpus_from_list(corpus_disply_name)
181
+
182
+ log.info(f"Querying {corpus.name=} with {query=}")
181
183
 
182
184
  response:RetrieveContextsResponse = rag.retrieval_query(
183
185
  rag_resources=[
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.90.5
3
+ Version: 0.91.0
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.90.5.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.91.0.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -24,6 +24,7 @@ Requires-Dist: langchain >=0.2.12
24
24
  Requires-Dist: langchain-experimental >=0.0.61
25
25
  Requires-Dist: langchain-community >=0.2.11
26
26
  Provides-Extra: all
27
+ Requires-Dist: anthropic[vertex] ; extra == 'all'
27
28
  Requires-Dist: asyncpg ; extra == 'all'
28
29
  Requires-Dist: azure-identity ; extra == 'all'
29
30
  Requires-Dist: azure-storage-blob ; extra == 'all'
@@ -96,6 +97,7 @@ Requires-Dist: xlwings ; extra == 'excel'
96
97
  Requires-Dist: requests ; extra == 'excel'
97
98
  Requires-Dist: rich ; extra == 'excel'
98
99
  Provides-Extra: gcp
100
+ Requires-Dist: anthropic[vertex] ; extra == 'gcp'
99
101
  Requires-Dist: google-api-python-client ; extra == 'gcp'
100
102
  Requires-Dist: google-cloud-alloydb-connector[pg8000] ; extra == 'gcp'
101
103
  Requires-Dist: google-auth-httplib2 ; extra == 'gcp'
@@ -54,12 +54,12 @@ sunholo/cli/sun_rich.py,sha256=UpMqeJ0C8i0pkue1AHnnyyX0bFJ9zZeJ7HBR6yhuA8A,54
54
54
  sunholo/cli/swagger.py,sha256=absYKAU-7Yd2eiVNUY-g_WLl2zJfeRUNdWQ0oH8M_HM,1564
55
55
  sunholo/cli/vertex.py,sha256=8130YCarxHL1UC3aqblNmUwGZTXbkdL4Y_FOnZJsWiI,2056
56
56
  sunholo/components/__init__.py,sha256=IDoylb74zFKo6NIS3RQqUl0PDFBGVxM1dfUmO7OJ44U,176
57
- sunholo/components/llm.py,sha256=5wRVf7lIb7q1vRADNcdQp26L9l4vGHFIvjtUDurZN_s,11488
57
+ sunholo/components/llm.py,sha256=5QkYgMoqFeFVl71w0zrLN-aKMieSlMiL2gM4aB-6uk8,12023
58
58
  sunholo/components/retriever.py,sha256=bKIVT7_18Ut3OJd0E0jyiISPnD9qkHWVjcQPT4i1_G8,7720
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=H2BfucbMOm1nT6Pq6MS1Yw4ZIG02KKKTeOijX8B6DaU,14804
62
+ sunholo/database/alloydb_client.py,sha256=gMTV1rno3pZfPQy-I3YBE_MiXQePcu8Mcki_Kmq3Hj0,17019
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
@@ -94,12 +94,12 @@ sunholo/invoke/direct_vac_func.py,sha256=fuTJlH5PsqWhN_yVMaWisHCTZU1JEUz8I8yVbWs
94
94
  sunholo/invoke/invoke_vac_utils.py,sha256=sJc1edHTHMzMGXjji1N67c3iUaP7BmAL5nj82Qof63M,2053
95
95
  sunholo/langfuse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
96
  sunholo/langfuse/callback.py,sha256=jl0SZsFS53uMW9DGeM9SOL_EsRZsba0wwFGLqKzu9_U,1684
97
- sunholo/langfuse/evals.py,sha256=YTaqOxSoeVxjuynASWjia07z9Q4NusOi_gQUUWaCTY4,3359
97
+ sunholo/langfuse/evals.py,sha256=y1T6qUA-k41BD2_5warjd1CQN4N107zsDizg9j5jCW4,3412
98
98
  sunholo/langfuse/prompts.py,sha256=27BsVfihM6-h1jscbkGSO4HsATl-d4ZN6tcNCVztWoY,1300
99
99
  sunholo/llamaindex/__init__.py,sha256=DlY_cHWCsVEV1C5WBgDdHRgOMlJc8pDoCRukUJ8PT9w,88
100
100
  sunholo/llamaindex/get_files.py,sha256=6rhXCDqQ_lrIapISQ_OYQDjiSATXvS_9m3qq53-oIl0,781
101
101
  sunholo/llamaindex/import_files.py,sha256=Bnic5wz8c61af9Kwq8KSrNBbc4imYnzMtBCb2jzSImI,6224
102
- sunholo/llamaindex/llamaindex_class.py,sha256=wtMS97YMsfA2IWLTd5mzr73DV4_fi5I5GVD7AC4wVm0,17375
102
+ sunholo/llamaindex/llamaindex_class.py,sha256=PnpPoc7LpP7xvKIXYu-UvI4ehj67pGhE1EIWEQyimhQ,17435
103
103
  sunholo/llamaindex/user_history.py,sha256=ZtkecWuF9ORduyGB8kF8gP66bm9DdvCI-ZiK6Kt-cSE,2265
104
104
  sunholo/lookup/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
105
105
  sunholo/lookup/model_lookup.yaml,sha256=O7o-jP53MLA06C8pI-ILwERShO-xf6z_258wtpZBv6A,739
@@ -144,9 +144,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
144
144
  sunholo/vertex/memory_tools.py,sha256=q_phxgGX2TG2j2MXNULF2xGzQnQPENwjPN9nZ_A9Gh0,7526
145
145
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
146
146
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
147
- sunholo-0.90.5.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
148
- sunholo-0.90.5.dist-info/METADATA,sha256=M3cqytUbtKqTqBkEY-mVXCFGpDdbrX6v8jCAZm2eOsw,7706
149
- sunholo-0.90.5.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
150
- sunholo-0.90.5.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
151
- sunholo-0.90.5.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
152
- sunholo-0.90.5.dist-info/RECORD,,
147
+ sunholo-0.91.0.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
148
+ sunholo-0.91.0.dist-info/METADATA,sha256=88KfGdcucBZTtc-oEMicxB6actR75TcMt0ktdqvbJ_4,7806
149
+ sunholo-0.91.0.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
150
+ sunholo-0.91.0.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
151
+ sunholo-0.91.0.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
152
+ sunholo-0.91.0.dist-info/RECORD,,