langchain-timbr 2.1.3__py3-none-any.whl → 2.1.4__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.1.3'
32
- __version_tuple__ = version_tuple = (2, 1, 3)
31
+ __version__ = version = '2.1.4'
32
+ __version_tuple__ = version_tuple = (2, 1, 4)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -169,6 +169,7 @@ class ExecuteTimbrQueryChain(Chain):
169
169
  "verify_ssl": self._verify_ssl,
170
170
  "is_jwt": self._is_jwt,
171
171
  "jwt_tenant_id": self._jwt_tenant_id,
172
+ "additional_headers": {"results-limit": str(self._max_limit)},
172
173
  **self._conn_params,
173
174
  }
174
175
 
@@ -265,7 +266,8 @@ class ExecuteTimbrQueryChain(Chain):
265
266
  rows = run_query(
266
267
  sql,
267
268
  self._get_conn_params(),
268
- llm_prompt=prompt
269
+ llm_prompt=prompt,
270
+ use_query_limit=True,
269
271
  ) if is_sql_valid and is_sql_not_tried else []
270
272
 
271
273
  if iteration < self._no_results_max_retries:
@@ -23,6 +23,7 @@ class GenerateAnswerChain(Chain):
23
23
  is_jwt: Optional[bool] = False,
24
24
  jwt_tenant_id: Optional[str] = None,
25
25
  conn_params: Optional[dict] = None,
26
+ note: Optional[str] = '',
26
27
  debug: Optional[bool] = False,
27
28
  **kwargs,
28
29
  ):
@@ -33,6 +34,7 @@ class GenerateAnswerChain(Chain):
33
34
  :param verify_ssl: Whether to verify SSL certificates (default is True).
34
35
  :param is_jwt: Whether to use JWT authentication (default is False).
35
36
  :param jwt_tenant_id: JWT tenant ID for multi-tenant environments (required when is_jwt=True).
37
+ :param note: Optional additional note to extend our llm prompt
36
38
  :param conn_params: Extra Timbr connection parameters sent with every request (e.g., 'x-api-impersonate-user').
37
39
 
38
40
  ## Example
@@ -77,6 +79,7 @@ class GenerateAnswerChain(Chain):
77
79
  self._jwt_tenant_id = jwt_tenant_id
78
80
  self._debug = to_boolean(debug)
79
81
  self._conn_params = conn_params or {}
82
+ self._note = note
80
83
 
81
84
 
82
85
  @property
@@ -116,6 +119,7 @@ class GenerateAnswerChain(Chain):
116
119
  conn_params=self._get_conn_params(),
117
120
  results=rows,
118
121
  sql=sql,
122
+ note=self._note,
119
123
  debug=self._debug,
120
124
  )
121
125
 
@@ -160,6 +160,7 @@ class GenerateTimbrSqlChain(Chain):
160
160
  "verify_ssl": self._verify_ssl,
161
161
  "is_jwt": self._is_jwt,
162
162
  "jwt_tenant_id": self._jwt_tenant_id,
163
+ "additional_headers": {"results-limit": str(self._max_limit)},
163
164
  **self._conn_params,
164
165
  }
165
166
 
@@ -126,6 +126,7 @@ class TimbrSqlAgent(BaseSingleActionAgent):
126
126
  is_jwt=to_boolean(is_jwt),
127
127
  jwt_tenant_id=jwt_tenant_id,
128
128
  conn_params=conn_params,
129
+ note=note,
129
130
  debug=to_boolean(debug),
130
131
  ) if self._generate_answer else None
131
132
 
@@ -161,6 +161,7 @@ class ValidateTimbrSqlChain(Chain):
161
161
  "verify_ssl": self._verify_ssl,
162
162
  "is_jwt": self._is_jwt,
163
163
  "jwt_tenant_id": self._jwt_tenant_id,
164
+ "additional_headers": {"results-limit": str(self._max_limit)},
164
165
  **self._conn_params,
165
166
  }
166
167
 
@@ -115,6 +115,7 @@ class TimbrLlmConnector:
115
115
  "verify_ssl": self.verify_ssl,
116
116
  "is_jwt": self.is_jwt,
117
117
  "jwt_tenant_id": self.jwt_tenant_id,
118
+ "additional_headers": {"results-limit": str(self.max_limit)},
118
119
  **self.conn_params,
119
120
  }
120
121
 
@@ -545,8 +545,9 @@ def answer_question(
545
545
  conn_params: dict,
546
546
  results: str,
547
547
  sql: Optional[str] = None,
548
- debug: Optional[bool] = False,
549
548
  timeout: Optional[int] = None,
549
+ note: Optional[str] = '',
550
+ debug: Optional[bool] = False,
550
551
  ) -> dict[str, Any]:
551
552
  # Use config default timeout if none provided
552
553
  if timeout is None:
@@ -558,6 +559,7 @@ def answer_question(
558
559
  question=question,
559
560
  formatted_rows=results,
560
561
  additional_context=f"SQL QUERY:\n{sql}\n\n" if sql else "",
562
+ note=note,
561
563
  )
562
564
 
563
565
  apx_token_count = _calculate_token_count(llm, prompt)
@@ -70,7 +70,7 @@ def cache_with_version_check(func):
70
70
  return wrapper
71
71
 
72
72
 
73
- def run_query(sql: str, conn_params: dict, llm_prompt: Optional[str] = None) -> list[list]:
73
+ def run_query(sql: str, conn_params: dict, llm_prompt: Optional[str] = None, use_query_limit = False) -> list[list]:
74
74
  if not conn_params:
75
75
  raise("Please provide connection params.")
76
76
 
@@ -79,9 +79,22 @@ def run_query(sql: str, conn_params: dict, llm_prompt: Optional[str] = None) ->
79
79
  clean_prompt = llm_prompt.replace('\r\n', ' ').replace('\n', ' ').replace('?', '')
80
80
  query = f"-- LLM: {clean_prompt}\n{sql}"
81
81
 
82
+ query_conn_params = conn_params
83
+ if not use_query_limit:
84
+ # Remove results-limit
85
+ if 'additional_headers' in conn_params and 'results-limit' in conn_params['additional_headers']:
86
+ query_upper = query.strip().upper()
87
+ if query_upper.startswith('SHOW') or query_upper.startswith('DESC'):
88
+ query_conn_params = conn_params.copy()
89
+ query_conn_params['additional_headers'] = conn_params['additional_headers'].copy()
90
+ del query_conn_params['additional_headers']['results-limit']
91
+ # If no other additional_headers remain, delete the key entirely
92
+ if not query_conn_params['additional_headers']:
93
+ del query_conn_params['additional_headers']
94
+
82
95
  results = timbr_http_connector.run_query(
83
96
  query=query,
84
- **conn_params,
97
+ **query_conn_params,
85
98
  )
86
99
 
87
100
  return results
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-timbr
3
- Version: 2.1.3
3
+ Version: 2.1.4
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/
@@ -1,14 +1,14 @@
1
1
  langchain_timbr/__init__.py,sha256=gxd6Y6QDmYZtPlYVdXtPIy501hMOZXHjWh2qq4qzt_s,828
2
- langchain_timbr/_version.py,sha256=3XX6kpIyOtIVpdYtEgDoTVSW2L9cEQyXaBXhL9YIdM0,704
2
+ langchain_timbr/_version.py,sha256=TYs-mU9m9aJFweRpjovqttRQsYRnpbbHHMifXX9ryi4,704
3
3
  langchain_timbr/config.py,sha256=PEtvNgvnA9UseZJjKgup_O6xdG-VYk3N11nH8p8W1Kg,1410
4
- langchain_timbr/timbr_llm_connector.py,sha256=1jDicBZkW7CKB-PvQiQ1_AMXYm9JJHaoNaPqy54nhh8,13096
4
+ langchain_timbr/timbr_llm_connector.py,sha256=mdkWskpvmXZre5AzVFn6KfPnVH5YN5MIwfEoXWBLMgY,13170
5
5
  langchain_timbr/langchain/__init__.py,sha256=ejcsZKP9PK0j4WrrCCcvBXpDpP-TeRiVb21OIUJqix8,580
6
- langchain_timbr/langchain/execute_timbr_query_chain.py,sha256=g7VzCuywo7xlWIldjtGOV4dYsQB3KsO8VARCfKrZFHM,15461
7
- langchain_timbr/langchain/generate_answer_chain.py,sha256=euy8GcMOziMKpiJrmpiH-De-qKTaVV48TqTduDa5-PE,4711
8
- langchain_timbr/langchain/generate_timbr_sql_chain.py,sha256=6NPvidW8pwmaX3w7p7yNFwQTZ8Cnmb40ZznRQJ2dTFM,9023
6
+ langchain_timbr/langchain/execute_timbr_query_chain.py,sha256=pedMajyKDI2ZaoyVp1r64nHX015Wy-r96HoJrRlCh48,15579
7
+ langchain_timbr/langchain/generate_answer_chain.py,sha256=XsaQrgBFwoC9ne3jpnuHueUXL1PzNQ75ECC_HVA61Ks,4871
8
+ langchain_timbr/langchain/generate_timbr_sql_chain.py,sha256=3Z0ut78AFCNHKwLwOYH44hzJDIOA-zNF0x8Tjyrvzp4,9098
9
9
  langchain_timbr/langchain/identify_concept_chain.py,sha256=kuzg0jJQpFGIiaxtNhdQ5K4HXveLVwONFNsoipPCteE,7169
10
- langchain_timbr/langchain/timbr_sql_agent.py,sha256=7S7USe3wnwxdBduBycHYVbXnywnvog-Bg67Tk8-2X_s,19551
11
- langchain_timbr/langchain/validate_timbr_sql_chain.py,sha256=sxT72asK-Cms4ZTiThWv58PgEBY1p_9hnUQwU35kPIQ,9492
10
+ langchain_timbr/langchain/timbr_sql_agent.py,sha256=HntpalzCZ-PlHd7na5V0syCMqrREFUpppGM4eHstaZQ,19574
11
+ langchain_timbr/langchain/validate_timbr_sql_chain.py,sha256=OcE_7yfb9xpD-I4OS7RG1bY4-yi1UicjvGegOv_vkQU,9567
12
12
  langchain_timbr/langgraph/__init__.py,sha256=mKBFd0x01jWpRujUWe-suX3FFhenPoDxrvzs8I0mum0,457
13
13
  langchain_timbr/langgraph/execute_timbr_query_node.py,sha256=rPx_V3OOh-JTGOwrEopHmOmFuM-ngBZdswkW9oZ43hU,5536
14
14
  langchain_timbr/langgraph/generate_response_node.py,sha256=BLmsDZfbhncRpO7PEfDpy7CnPE7a55j8QV5jfg30heQ,2247
@@ -20,9 +20,9 @@ langchain_timbr/llm_wrapper/timbr_llm_wrapper.py,sha256=sDqDOz0qu8b4WWlagjNceswM
20
20
  langchain_timbr/utils/general.py,sha256=KkehHvIj8GoQ_0KVXLcUVeaYaTtkuzgXmYYx2TXJhI4,10253
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
- langchain_timbr/utils/timbr_llm_utils.py,sha256=c50-dEDh8GnAkDfcbNKdXuOWjbSa-mXpZzDVuNt4jTY,23053
24
- langchain_timbr/utils/timbr_utils.py,sha256=p21DwTGhF4iKTLDQBkeBaJDFcXt-Hpu1ij8xzQt00Ng,16958
25
- langchain_timbr-2.1.3.dist-info/METADATA,sha256=3etBzLd5lLYeXINYMxJwu6daB9feBxW1MReZaG_I6fU,12268
26
- langchain_timbr-2.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- langchain_timbr-2.1.3.dist-info/licenses/LICENSE,sha256=0ITGFk2alkC7-e--bRGtuzDrv62USIiVyV2Crf3_L_0,1065
28
- langchain_timbr-2.1.3.dist-info/RECORD,,
23
+ langchain_timbr/utils/timbr_llm_utils.py,sha256=_4Qz5SX5cXW1Rl_fSBcE9P3uPEaI8DBg3GpXA4uQGoI,23102
24
+ langchain_timbr/utils/timbr_utils.py,sha256=SvmQ0wYicODNhmo8c-5_KPDBAfrBVBkUfoO8sPItQhk,17759
25
+ langchain_timbr-2.1.4.dist-info/METADATA,sha256=Wtzy14BfbEujvuYozb4XcaUz6pp87zxjNNBbt9Z5wSQ,12268
26
+ langchain_timbr-2.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ langchain_timbr-2.1.4.dist-info/licenses/LICENSE,sha256=0ITGFk2alkC7-e--bRGtuzDrv62USIiVyV2Crf3_L_0,1065
28
+ langchain_timbr-2.1.4.dist-info/RECORD,,