langchain-timbr 2.0.2__py3-none-any.whl → 2.0.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.
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '2.0.2'
32
- __version_tuple__ = version_tuple = (2, 0, 2)
31
+ __version__ = version = '2.0.3'
32
+ __version_tuple__ = version_tuple = (2, 0, 3)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -14,6 +14,7 @@ class LlmTypes(Enum):
14
14
  AzureOpenAI = 'azure-openai-chat'
15
15
  Snowflake = 'snowflake-cortex'
16
16
  Databricks = 'chat-databricks'
17
+ VertexAI = 'chat-vertexai'
17
18
  Timbr = 'timbr'
18
19
 
19
20
 
@@ -54,10 +55,7 @@ class LlmWrapper(LLM):
54
55
  # Validation: Ensure we have the required parameters
55
56
  if not selected_llm_type:
56
57
  raise ValueError("llm_type must be provided either as parameter or in config (LLM_TYPE environment variable)")
57
-
58
- if not selected_api_key:
59
- raise ValueError("api_key must be provided either as parameter or in config (LLM_API_KEY environment variable)")
60
-
58
+
61
59
  self.client = self._connect_to_llm(
62
60
  selected_llm_type,
63
61
  selected_api_key,
@@ -80,8 +78,75 @@ class LlmWrapper(LLM):
80
78
  llm_params["temperature"] = config.llm_temperature
81
79
  return llm_params
82
80
 
83
-
84
- def _connect_to_llm(self, llm_type, api_key, model, **llm_params):
81
+ def _try_build_vertexai_credentials(self,params, api_key):
82
+ from google.oauth2 import service_account
83
+ from google.auth import default
84
+
85
+ # Try multiple authentication methods in order of preference
86
+ creds = None
87
+ scope = pop_param_value(params, ['vertex_scope', 'llm_scope', 'scope'], default=config.llm_scope)
88
+ scopes = [scope] if scope else ["https://www.googleapis.com/auth/cloud-platform"]
89
+
90
+ # Method 1: Service Account File (json_path)
91
+ json_path = pop_param_value(params, ['azure_json_path', 'llm_json_path', 'json_path'])
92
+ if json_path:
93
+ try:
94
+ creds = service_account.Credentials.from_service_account_file(
95
+ json_path,
96
+ scopes=scopes,
97
+ )
98
+ except Exception as e:
99
+ raise ValueError(f"Failed to load service account from file '{json_path}': {e}")
100
+
101
+ # Method 2: Service Account Info (as dictionary)
102
+ if not creds:
103
+ service_account_info = pop_param_value(params, ['service_account_info', 'vertex_service_account_info'])
104
+ if service_account_info:
105
+ try:
106
+ creds = service_account.Credentials.from_service_account_info(
107
+ service_account_info,
108
+ scopes=scopes,
109
+ )
110
+ except Exception as e:
111
+ raise ValueError(f"Failed to load service account from info: {e}")
112
+
113
+ # Method 3: Service Account Email + Private Key
114
+ if not creds:
115
+ service_account_email = pop_param_value(params, ['service_account_email', 'vertex_email', 'service_account'])
116
+ private_key = pop_param_value(params, ['private_key', 'vertex_private_key']) or api_key
117
+
118
+ if service_account_email and private_key:
119
+ try:
120
+ service_account_info = {
121
+ "type": "service_account",
122
+ "client_email": service_account_email,
123
+ "private_key": private_key,
124
+ "token_uri": "https://oauth2.googleapis.com/token",
125
+ }
126
+ creds = service_account.Credentials.from_service_account_info(
127
+ service_account_info,
128
+ scopes=scopes,
129
+ )
130
+ except Exception as e:
131
+ raise ValueError(f"Failed to create service account from email and private key: {e}")
132
+
133
+ # Method 4: Default Google Cloud Credentials (fallback)
134
+ if not creds:
135
+ try:
136
+ creds, _ = default(scopes=scopes)
137
+ except Exception as e:
138
+ raise ValueError(
139
+ "VertexAI authentication failed. Please provide one of:\n"
140
+ "1. 'json_path' - path to service account JSON file\n"
141
+ "2. 'service_account_info' - service account info as dictionary\n"
142
+ "3. 'service_account_email' + 'private_key' - service account credentials\n"
143
+ "4. Set up default Google Cloud credentials (gcloud auth application-default login)\n"
144
+ f"Error: {e}"
145
+ )
146
+
147
+ return creds
148
+
149
+ def _connect_to_llm(self, llm_type, api_key = None, model = None, **llm_params):
85
150
  if is_llm_type(llm_type, LlmTypes.OpenAI):
86
151
  from langchain_openai import ChatOpenAI as OpenAI
87
152
  llm_model = model or "gpt-4o-2024-11-20"
@@ -171,6 +236,21 @@ class LlmWrapper(LLM):
171
236
  endpoint=llm_model,
172
237
  workspace_client=w, # Using authenticated client
173
238
  **params,
239
+ )
240
+ elif is_llm_type(llm_type, LlmTypes.VertexAI):
241
+ from langchain_google_vertexai import ChatVertexAI
242
+ llm_model = model or "gemini-2.5-flash-lite"
243
+ params = self._add_temperature(LlmTypes.VertexAI.name, llm_model, **llm_params)
244
+
245
+ project = pop_param_value(params, ['vertex_project', 'llm_project', 'project'])
246
+ if project:
247
+ params['project'] = project
248
+
249
+ creds = self._try_build_vertexai_credentials(params, api_key)
250
+ return ChatVertexAI(
251
+ model_name=llm_model,
252
+ credentials=creds,
253
+ **params,
174
254
  )
175
255
  else:
176
256
  raise ValueError(f"Unsupported LLM type: {llm_type}")
@@ -179,6 +259,8 @@ class LlmWrapper(LLM):
179
259
  def get_model_list(self) -> list[str]:
180
260
  """Return the list of available models for the LLM."""
181
261
  models = []
262
+ llm_type_name = None
263
+
182
264
  try:
183
265
  if is_llm_type(self._llm_type, LlmTypes.OpenAI):
184
266
  from openai import OpenAI
@@ -237,10 +319,14 @@ class LlmWrapper(LLM):
237
319
  models = [ep.name for ep in w.serving_endpoints.list()]
238
320
 
239
321
  # elif self._is_llm_type(self._llm_type, LlmTypes.Timbr):
240
-
322
+ elif is_llm_type(self._llm_type, LlmTypes.VertexAI):
323
+ from google import genai
324
+ if self.client.credentials:
325
+ client = genai.Client(credentials=self.client.credentials, vertexai=True, project=self.client.project, location=self.client.location)
326
+ models = [m.name.split('/')[-1] for m in client.models.list()]
327
+
241
328
  except Exception:
242
329
  # If model list fetching throws an exception, return default value using get_supported_models
243
- llm_type_name = None
244
330
  if hasattr(self, '_llm_type'):
245
331
  # Try to extract the LLM type name from the _llm_type
246
332
  for llm_enum in LlmTypes:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-timbr
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: LangChain & LangGraph extensions that parse LLM prompts into Timbr semantic SQL and execute them.
5
5
  Project-URL: Homepage, https://github.com/WPSemantix/langchain-timbr
6
6
  Project-URL: Documentation, https://docs.timbr.ai/doc/docs/integration/langchain-sdk/
@@ -31,17 +31,18 @@ Requires-Dist: tiktoken==0.8.0
31
31
  Requires-Dist: transformers>=4.53
32
32
  Provides-Extra: all
33
33
  Requires-Dist: anthropic==0.42.0; extra == 'all'
34
- Requires-Dist: azure-identity==1.16.1; extra == 'all'
34
+ Requires-Dist: azure-identity>=1.16.1; extra == 'all'
35
35
  Requires-Dist: databricks-langchain==0.3.0; (python_version < '3.10') and extra == 'all'
36
36
  Requires-Dist: databricks-langchain==0.7.1; (python_version >= '3.10') and extra == 'all'
37
37
  Requires-Dist: databricks-sdk==0.64.0; extra == 'all'
38
38
  Requires-Dist: google-generativeai==0.8.4; extra == 'all'
39
39
  Requires-Dist: langchain-anthropic>=0.3.1; extra == 'all'
40
40
  Requires-Dist: langchain-google-genai>=2.0.9; extra == 'all'
41
+ Requires-Dist: langchain-google-vertexai>=2.0.28; extra == 'all'
41
42
  Requires-Dist: langchain-openai>=0.3.16; extra == 'all'
42
43
  Requires-Dist: langchain-tests>=0.3.20; extra == 'all'
43
44
  Requires-Dist: openai>=1.77.0; extra == 'all'
44
- Requires-Dist: pyarrow<19.0.0; extra == 'all'
45
+ Requires-Dist: pyarrow<20.0.0,>=19.0.1; extra == 'all'
45
46
  Requires-Dist: pytest==8.3.4; extra == 'all'
46
47
  Requires-Dist: snowflake-snowpark-python>=1.6.0; extra == 'all'
47
48
  Requires-Dist: snowflake>=0.8.0; extra == 'all'
@@ -50,7 +51,7 @@ Provides-Extra: anthropic
50
51
  Requires-Dist: anthropic==0.42.0; extra == 'anthropic'
51
52
  Requires-Dist: langchain-anthropic>=0.3.1; extra == 'anthropic'
52
53
  Provides-Extra: azure-openai
53
- Requires-Dist: azure-identity==1.16.1; extra == 'azure-openai'
54
+ Requires-Dist: azure-identity>=1.16.1; extra == 'azure-openai'
54
55
  Requires-Dist: langchain-openai>=0.3.16; extra == 'azure-openai'
55
56
  Requires-Dist: openai>=1.77.0; extra == 'azure-openai'
56
57
  Provides-Extra: databricks
@@ -59,7 +60,7 @@ Requires-Dist: databricks-langchain==0.7.1; (python_version >= '3.10') and extra
59
60
  Requires-Dist: databricks-sdk==0.64.0; extra == 'databricks'
60
61
  Provides-Extra: dev
61
62
  Requires-Dist: langchain-tests>=0.3.20; extra == 'dev'
62
- Requires-Dist: pyarrow<19.0.0; extra == 'dev'
63
+ Requires-Dist: pyarrow<20.0.0,>=19.0.1; extra == 'dev'
63
64
  Requires-Dist: pytest==8.3.4; extra == 'dev'
64
65
  Requires-Dist: uvicorn==0.34.0; extra == 'dev'
65
66
  Provides-Extra: google
@@ -71,6 +72,9 @@ Requires-Dist: openai>=1.77.0; extra == 'openai'
71
72
  Provides-Extra: snowflake
72
73
  Requires-Dist: snowflake-snowpark-python>=1.6.0; extra == 'snowflake'
73
74
  Requires-Dist: snowflake>=0.8.0; extra == 'snowflake'
75
+ Provides-Extra: vertex-ai
76
+ Requires-Dist: google-generativeai==0.8.4; extra == 'vertex-ai'
77
+ Requires-Dist: langchain-google-vertexai>=2.0.28; extra == 'vertex-ai'
74
78
  Description-Content-Type: text/markdown
75
79
 
76
80
  ![Timbr logo description](https://timbr.ai/wp-content/uploads/2025/01/logotimbrai230125.png)
@@ -89,8 +93,8 @@ Timbr LangChain LLM SDK is a Python SDK that extends LangChain and LangGraph wit
89
93
 
90
94
  ![Timbr LangGraph pipeline](https://docs.timbr.ai/doc/assets/images/timbr-langgraph-fcf8e2eb7e26dc9dfa8b56b62937281e.png)
91
95
 
92
-
93
96
  ## Dependencies
97
+
94
98
  - Access to a timbr-server
95
99
  - Python 3.9.13 or newer
96
100
 
@@ -103,13 +107,15 @@ python -m pip install langchain-timbr
103
107
  ```
104
108
 
105
109
  ### Install with selected LLM providers
106
- #### One of: openai, anthropic, google, azure_openai, snowflake, databricks (or 'all')
110
+
111
+ #### One of: openai, anthropic, google, azure_openai, snowflake, databricks, vertex_ai (or 'all')
107
112
 
108
113
  ```bash
109
114
  python -m pip install 'langchain-timbr[<your selected providers, separated by comma w/o space>]'
110
115
  ```
111
116
 
112
117
  ### Using pip from github
118
+
113
119
  ```bash
114
120
  pip install git+https://github.com/WPSemantix/langchain-timbr
115
121
  ```
@@ -1,5 +1,5 @@
1
1
  langchain_timbr/__init__.py,sha256=gxd6Y6QDmYZtPlYVdXtPIy501hMOZXHjWh2qq4qzt_s,828
2
- langchain_timbr/_version.py,sha256=UFd-y4dR-HVHWzUJlgmJ3T05hh9C4Q-la-D9QTIoZw0,704
2
+ langchain_timbr/_version.py,sha256=piVud-sBtnpf1MQjPI4VkcaUcsjojJEmPPb85g-VsVw,704
3
3
  langchain_timbr/config.py,sha256=PEtvNgvnA9UseZJjKgup_O6xdG-VYk3N11nH8p8W1Kg,1410
4
4
  langchain_timbr/timbr_llm_connector.py,sha256=1jDicBZkW7CKB-PvQiQ1_AMXYm9JJHaoNaPqy54nhh8,13096
5
5
  langchain_timbr/langchain/__init__.py,sha256=ejcsZKP9PK0j4WrrCCcvBXpDpP-TeRiVb21OIUJqix8,580
@@ -15,14 +15,14 @@ langchain_timbr/langgraph/generate_response_node.py,sha256=BLmsDZfbhncRpO7PEfDpy
15
15
  langchain_timbr/langgraph/generate_timbr_sql_node.py,sha256=wkau-NajblSVzNIro9IyqawULvz3XaCYSEdYW95vWco,4911
16
16
  langchain_timbr/langgraph/identify_concept_node.py,sha256=aiLDFEcz_vM4zZ_ULe1SvJKmI-e4Fb2SibZQaEPz_eY,3649
17
17
  langchain_timbr/langgraph/validate_timbr_query_node.py,sha256=-2fuieCz1hv6ua-17zfonme8LQ_OoPnoOBTdGSXkJgs,4793
18
- langchain_timbr/llm_wrapper/llm_wrapper.py,sha256=QoTKx_VKd2ToglX53Z49e71xoJUEH6-pRBVOzjURxCo,11320
18
+ langchain_timbr/llm_wrapper/llm_wrapper.py,sha256=xLBTy2E6mTDny5tSSxIeeMUffos1r3a2BkBAjn3zxO4,14935
19
19
  langchain_timbr/llm_wrapper/timbr_llm_wrapper.py,sha256=sDqDOz0qu8b4WWlagjNceswMVyvEJ8yBWZq2etBh-T0,1362
20
20
  langchain_timbr/utils/general.py,sha256=MtY-ZExKJrcBzV3EQNn6G1ESKpiQB2hJCp95BrUayUo,5707
21
21
  langchain_timbr/utils/prompt_service.py,sha256=QT7kiq72rQno77z1-tvGGD7HlH_wdTQAl_1teSoKEv4,11373
22
22
  langchain_timbr/utils/temperature_supported_models.json,sha256=d3UmBUpG38zDjjB42IoGpHTUaf0pHMBRSPY99ao1a3g,1832
23
23
  langchain_timbr/utils/timbr_llm_utils.py,sha256=7-nnTa1T9XOcgIb-aJP3Pgon_gOrCMnDPiIPiAT3UCg,23016
24
24
  langchain_timbr/utils/timbr_utils.py,sha256=p21DwTGhF4iKTLDQBkeBaJDFcXt-Hpu1ij8xzQt00Ng,16958
25
- langchain_timbr-2.0.2.dist-info/METADATA,sha256=VtT8woei5BJOA6rvMtpJublCk7nwDiQ4j0gfCww7n90,7771
26
- langchain_timbr-2.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- langchain_timbr-2.0.2.dist-info/licenses/LICENSE,sha256=0ITGFk2alkC7-e--bRGtuzDrv62USIiVyV2Crf3_L_0,1065
28
- langchain_timbr-2.0.2.dist-info/RECORD,,
25
+ langchain_timbr-2.0.3.dist-info/METADATA,sha256=l50ahPxMk0CgSVwdLEpQh-cs--hlyqj7nR2jvG2KOy4,8028
26
+ langchain_timbr-2.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ langchain_timbr-2.0.3.dist-info/licenses/LICENSE,sha256=0ITGFk2alkC7-e--bRGtuzDrv62USIiVyV2Crf3_L_0,1065
28
+ langchain_timbr-2.0.3.dist-info/RECORD,,