salesforce-data-customcode 6.0.2.dev1__py3-none-any.whl → 6.0.3.dev1__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.
datacustomcode/client.py CHANGED
@@ -59,7 +59,6 @@ def llm_gateway_generate_text_col(
59
59
  template: str,
60
60
  values: Union[Dict[str, "Column"], "Column"],
61
61
  model_id: Optional[str] = None,
62
- max_tokens: Optional[int] = None,
63
62
  ) -> "Column":
64
63
  """Build a Spark Column that runs the LLM Gateway per row.
65
64
 
@@ -71,7 +70,6 @@ def llm_gateway_generate_text_col(
71
70
  ... "In one sentence, greet {name} from {city}.",
72
71
  ... {"name": col("name__c"), "city": col("homecity__c")},
73
72
  ... model_id="sfdc_ai__DefaultGPT4Omni",
74
- ... max_tokens=100,
75
73
  ... ),
76
74
  ... )
77
75
 
@@ -81,15 +79,12 @@ def llm_gateway_generate_text_col(
81
79
  values: Either a mapping from placeholder name to Spark ``Column``, or
82
80
  a single ``Column`` whose value is already a struct.
83
81
  model_id: LLM model id. Defaults to ``sfdc_ai__DefaultGPT4Omni``.
84
- max_tokens: Maximum tokens to generate. Defaults to 200.
85
82
 
86
83
  Returns:
87
84
  A Spark ``Column`` that, when evaluated, produces the generated text.
88
85
  """
89
86
  gateway = Client()._get_spark_llm_gateway()
90
- return gateway.llm_gateway_generate_text_col(
91
- template, values, model_id=model_id, max_tokens=max_tokens
92
- )
87
+ return gateway.llm_gateway_generate_text_col(template, values, model_id=model_id)
93
88
 
94
89
 
95
90
  class DataCloudObjectType(Enum):
@@ -150,9 +145,7 @@ class Client:
150
145
  finder: Find a file path
151
146
  reader: A custom reader to use for reading Data Cloud objects.
152
147
  writer: A custom writer to use for writing Data Cloud objects.
153
- spark_llm_gateway: Optional custom :class:`SparkLLMGateway`. When
154
- omitted, the gateway is lazily resolved from
155
- ``spark_llm_gateway_config``.
148
+ spark_llm_gateway: Optional custom :class:`SparkLLMGateway`.
156
149
 
157
150
  Example:
158
151
  >>> client = Client()
@@ -292,7 +285,6 @@ class Client:
292
285
  self,
293
286
  prompt: str,
294
287
  model_id: Optional[str] = None,
295
- max_tokens: Optional[int] = None,
296
288
  ) -> str:
297
289
  """Issue a one-shot LLM Gateway call. This is the scalar counterpart to
298
290
  :func:`llm_gateway_generate_text_col`: it runs **once** — not per row.
@@ -310,15 +302,13 @@ class Client:
310
302
  ``{field}`` substitution is performed on this string.
311
303
  model_id: LLM model id to target. Defaults to
312
304
  ``sfdc_ai__DefaultGPT4Omni`` when ``None``.
313
- max_tokens: Hard upper bound on the number of tokens the model
314
- may generate. Defaults to 200 when ``None``.
315
305
 
316
306
  Returns:
317
307
  The generated text as a plain Python ``str``; empty when the
318
308
  gateway response carries no generated text.
319
309
  """
320
310
  return self._get_spark_llm_gateway().llm_gateway_generate_text(
321
- prompt, model_id=model_id, max_tokens=max_tokens
311
+ prompt, model_id=model_id
322
312
  )
323
313
 
324
314
  def _get_spark_llm_gateway(self) -> SparkLLMGateway:
@@ -15,6 +15,7 @@
15
15
 
16
16
  from datacustomcode.llm_gateway.base import LLMGateway
17
17
  from datacustomcode.llm_gateway.default import DefaultLLMGateway
18
+ from datacustomcode.llm_gateway.errors import LLMGatewayCallError
18
19
  from datacustomcode.llm_gateway.spark_base import SparkLLMGateway
19
20
  from datacustomcode.llm_gateway.spark_default import DefaultSparkLLMGateway
20
21
 
@@ -22,5 +23,6 @@ __all__ = [
22
23
  "DefaultLLMGateway",
23
24
  "DefaultSparkLLMGateway",
24
25
  "LLMGateway",
26
+ "LLMGatewayCallError",
25
27
  "SparkLLMGateway",
26
28
  ]
@@ -34,8 +34,6 @@ class DefaultLLMGateway(EinsteinPlatformClient, LLMGateway):
34
34
 
35
35
  payload: Dict[str, Any] = {"prompt": request.prompt}
36
36
 
37
- if request.max_tokens is not None:
38
- payload["max_tokens"] = request.max_tokens
39
37
  if request.localization:
40
38
  payload["localization"] = request.localization
41
39
  if request.tags:
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2025, Salesforce, Inc.
2
+ # SPDX-License-Identifier: Apache-2
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Exceptions raised by LLM Gateway implementations."""
16
+
17
+ from __future__ import annotations
18
+
19
+ from typing import Optional
20
+
21
+
22
+ class LLMGatewayCallError(RuntimeError):
23
+ """Raised when an LLM Gateway call returns an error."""
24
+
25
+ def __init__(
26
+ self,
27
+ message: str,
28
+ *,
29
+ status: Optional[object] = None,
30
+ error_code: Optional[str] = None,
31
+ error_message: Optional[str] = None,
32
+ ) -> None:
33
+ super().__init__(message)
34
+ self.status = status
35
+ self.error_code = error_code
36
+ self.error_message = error_message
@@ -40,7 +40,6 @@ class SparkLLMGateway(ABC, UserExtendableNamedConfigMixin):
40
40
  self,
41
41
  prompt: str,
42
42
  model_id: Optional[str] = None,
43
- max_tokens: Optional[int] = None,
44
43
  ) -> str:
45
44
  """Issue a one-shot LLM Gateway call and return the generated text."""
46
45
 
@@ -50,6 +49,5 @@ class SparkLLMGateway(ABC, UserExtendableNamedConfigMixin):
50
49
  template: str,
51
50
  values: Union[Dict[str, "Column"], "Column"],
52
51
  model_id: Optional[str] = None,
53
- max_tokens: Optional[int] = None,
54
52
  ) -> "Column":
55
53
  """Build a Spark ``Column`` that invokes the LLM Gateway per row."""
@@ -31,7 +31,6 @@ if TYPE_CHECKING:
31
31
 
32
32
 
33
33
  _DEFAULT_LLM_MODEL_ID = "sfdc_ai__DefaultGPT4Omni"
34
- _DEFAULT_LLM_MAX_TOKENS = 200
35
34
 
36
35
 
37
36
  class DefaultSparkLLMGateway(SparkLLMGateway):
@@ -52,16 +51,14 @@ class DefaultSparkLLMGateway(SparkLLMGateway):
52
51
  self,
53
52
  prompt: str,
54
53
  model_id: Optional[str] = None,
55
- max_tokens: Optional[int] = None,
56
54
  ) -> str:
57
- return _invoke_llm_gateway(self._llm_gateway, prompt, model_id, max_tokens)
55
+ return _invoke_llm_gateway(self._llm_gateway, prompt, model_id)
58
56
 
59
57
  def llm_gateway_generate_text_col(
60
58
  self,
61
59
  template: str,
62
60
  values: Union[Dict[str, "Column"], "Column"],
63
61
  model_id: Optional[str] = None,
64
- max_tokens: Optional[int] = None,
65
62
  ) -> "Column":
66
63
 
67
64
  from pyspark.sql.functions import struct, udf
@@ -83,7 +80,7 @@ class DefaultSparkLLMGateway(SparkLLMGateway):
83
80
  else dict(values_row)
84
81
  )
85
82
  prompt = template.format(**subs)
86
- return _invoke_llm_gateway(gateway, prompt, model_id, max_tokens)
83
+ return _invoke_llm_gateway(gateway, prompt, model_id)
87
84
 
88
85
  return udf(_generate, StringType())(values_col)
89
86
 
@@ -104,8 +101,8 @@ def _invoke_llm_gateway(
104
101
  gateway: "LLMGateway",
105
102
  prompt: str,
106
103
  model_id: Optional[str],
107
- max_tokens: Optional[int],
108
104
  ) -> str:
105
+ from datacustomcode.llm_gateway.errors import LLMGatewayCallError
109
106
  from datacustomcode.llm_gateway.types.generate_text_request_builder import (
110
107
  GenerateTextRequestBuilder,
111
108
  )
@@ -114,6 +111,15 @@ def _invoke_llm_gateway(
114
111
  GenerateTextRequestBuilder()
115
112
  .set_prompt(prompt)
116
113
  .set_model(model_id or _DEFAULT_LLM_MODEL_ID)
117
- .set_max_tokens(max_tokens or _DEFAULT_LLM_MAX_TOKENS)
118
114
  )
119
- return gateway.generate_text(builder.build()).text
115
+ response = gateway.generate_text(builder.build())
116
+ if response.is_error:
117
+ raise LLMGatewayCallError(
118
+ f"LLM Gateway call failed: status_code={response.status_code}, "
119
+ f"error_code={response.error_code!r}, "
120
+ f"message={response.data!r}",
121
+ status=response.status_code,
122
+ error_code=response.error_code or None,
123
+ error_message=str(response.data) if response.data else None,
124
+ )
125
+ return response.text
@@ -40,13 +40,6 @@ class GenerateTextRequest(BaseModel):
40
40
  )
41
41
  model_name: str = Field(..., min_length=1, description="Name of the model to use")
42
42
  prompt: str = Field(..., description="Input prompt")
43
- max_tokens: Optional[int] = Field(
44
- default=None,
45
- ge=1,
46
- description=(
47
- "Maximum number of tokens to generate. If None, server default applies."
48
- ),
49
- )
50
43
  localization: Optional[Dict[str, Any]] = Field(
51
44
  default=None, description="Localization settings"
52
45
  )
@@ -26,7 +26,6 @@ class GenerateTextRequestBuilder:
26
26
  def __init__(self) -> None:
27
27
  self._prompt = ""
28
28
  self._model_name = ""
29
- self._max_tokens: Optional[int] = None
30
29
  self._localization: Optional[Dict[str, Any]] = None
31
30
  self._tags: Optional[Dict[str, Any]] = None
32
31
 
@@ -38,10 +37,6 @@ class GenerateTextRequestBuilder:
38
37
  self._model_name = model_name
39
38
  return self
40
39
 
41
- def set_max_tokens(self, max_tokens: int) -> "GenerateTextRequestBuilder":
42
- self._max_tokens = max_tokens
43
- return self
44
-
45
40
  def set_localization(
46
41
  self,
47
42
  localization: Optional[Dict[str, Any]] = None,
@@ -80,7 +75,6 @@ class GenerateTextRequestBuilder:
80
75
  request = GenerateTextRequest(
81
76
  prompt=self._prompt,
82
77
  model_name=self._model_name,
83
- max_tokens=self._max_tokens,
84
78
  localization=self._localization,
85
79
  tags=self._tags,
86
80
  )
@@ -25,7 +25,6 @@ def main():
25
25
  ... "In one sentence, greet {name} from {city}.",
26
26
  ... {"name": col("name__c"), "city": col("homecity__c")},
27
27
  ... model_id="sfdc_ai__DefaultGPT4Omni",
28
- ... max_tokens=100,
29
28
  ... ),
30
29
  ... )
31
30
 
@@ -35,7 +34,7 @@ def main():
35
34
  Example:
36
35
 
37
36
  >>> generated_text = client.llm_gateway_generate_text(
38
- ... prompt, model_id, max_tokens
37
+ ... prompt, model_id
39
38
  ... )
40
39
  """
41
40
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: salesforce-data-customcode
3
- Version: 6.0.2.dev1
3
+ Version: 6.0.3.dev1
4
4
  Summary: Data Cloud Custom Code SDK
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE.txt
@@ -347,7 +347,6 @@ def main():
347
347
  "In one sentence, greet {name} from {city}.",
348
348
  {"name": col("name__c"), "city": col("homecity__c")},
349
349
  model_id="sfdc_ai__DefaultGPT4Omni", # An AI model in your org
350
- max_tokens=100,
351
350
  ),
352
351
  )
353
352
 
@@ -1,7 +1,7 @@
1
1
  datacustomcode/__init__.py,sha256=qx-X3U9lU_791ZbAxhGqQeyDw6eqTi9-E9AbYnwJfxU,2071
2
2
  datacustomcode/auth.py,sha256=fpSjhIBdv9trC8yq2vuljAix_Euu-4Ah7HDCGhYjOxI,8309
3
3
  datacustomcode/cli.py,sha256=ObqhOasZSZ8ZNFP6pywV3FpsUOz45_KaZdMNT4BHOKs,13069
4
- datacustomcode/client.py,sha256=prAufc2_KAKdy0XX-nYhuD22a93GqQCsQuql9ru-8dY,13294
4
+ datacustomcode/client.py,sha256=NzPtJkHszRh0GqKUkobPyDUCDauUIaeI-zrac9VR7l8,12813
5
5
  datacustomcode/cmd.py,sha256=ZMs46aydJw2EaU26JgCtZmnqESQFHvvaJz10hnjZTBk,3537
6
6
  datacustomcode/common_config.py,sha256=SAUnxj3kqmOeWwPmFoYq4tuxokMgURVm4QwcGi-avL4,1928
7
7
  datacustomcode/config.py,sha256=2Pk61ieQsEWSxKDxlS66_rliKE8iX0j-9LweEm0aaGo,4072
@@ -37,14 +37,15 @@ datacustomcode/io/writer/__init__.py,sha256=gamfOD1VnAtEslRBpqh-yKiVjkG_wYWYdSat
37
37
  datacustomcode/io/writer/base.py,sha256=RHafJ-Xmh_TnYcN4QfSh0VdIZeIevKmz9sf05adMgxA,1540
38
38
  datacustomcode/io/writer/csv.py,sha256=asty5teBpNQ1fMGHZ7wA3suLhq0sk0lVQPN5x7TOSRk,1555
39
39
  datacustomcode/io/writer/print.py,sha256=0g2sP_1Wb95UIyEELWJt3dqM18Iv_CWhDW3mDxcIhns,5105
40
- datacustomcode/llm_gateway/__init__.py,sha256=ZYEMvQlnWzdSdBwYrhBQGmlfBBqsfmhAy4KViyCBFVA,995
40
+ datacustomcode/llm_gateway/__init__.py,sha256=rcoGpSkv36tZuAOcTxKkhNpM0qV03qgmer_ej07Vmfc,1088
41
41
  datacustomcode/llm_gateway/base.py,sha256=CTUhZiZ0JFlmWj6kQpTR4_-mUvqkBKl_Fkdvv9VwxY8,1262
42
- datacustomcode/llm_gateway/default.py,sha256=HVUc5NihNAQMVgRAJ8w2CBDX4mRLl8FRkpCJWv9FAOU,1952
43
- datacustomcode/llm_gateway/spark_base.py,sha256=h9fBrhBSSthCMBi6DjryxMKp_WSLdoMDg6a3FgO4oKI,1637
44
- datacustomcode/llm_gateway/spark_default.py,sha256=2-u9Oy936kj35wv8_qBSc-xtqnC7WNkgprhcuroP7U8,3524
42
+ datacustomcode/llm_gateway/default.py,sha256=QiwrDaUvrh00I-fYYhmogTtqC5r0fmm-JrXxNQLvTc0,1854
43
+ datacustomcode/llm_gateway/errors.py,sha256=ABjztpJwAYMBlmFX808CHHtu4nD6zA4ECelzNJQkJg0,1197
44
+ datacustomcode/llm_gateway/spark_base.py,sha256=apM3FYDPNz3JTgEdlf-7jeryzTYmSzjJsCIt95ZEpvg,1553
45
+ datacustomcode/llm_gateway/spark_default.py,sha256=ctBzkP1vDxgrmoIC6PvfmwxmlPVotkcADK3-M5qyFKI,3794
45
46
  datacustomcode/llm_gateway/types/__init__.py,sha256=gamfOD1VnAtEslRBpqh-yKiVjkG_wYWYdSatGIfsN-w,621
46
- datacustomcode/llm_gateway/types/generate_text_request.py,sha256=pHFp9r12xT_GlFm873kQEfrHCdoJI5sJGrCRVqqN3vg,1647
47
- datacustomcode/llm_gateway/types/generate_text_request_builder.py,sha256=P2lBwyjGQvqf8G9PR4pNeN02AeYri1XCOvlBeRqAJNw,2791
47
+ datacustomcode/llm_gateway/types/generate_text_request.py,sha256=ChxOCzp7St1EYgwl4tWiwfrPyVci4zPyBhnEjWc1Vfs,1448
48
+ datacustomcode/llm_gateway/types/generate_text_request_builder.py,sha256=R4hCgatMPSfWYqaOmeC1IMQj753iDgu7wU992c4tkmk,2565
48
49
  datacustomcode/llm_gateway/types/generate_text_response.py,sha256=NSvj6nvzR4cZ0cVs2-PE9Ct3ZY-xL4MQYknJMd_xdDI,1912
49
50
  datacustomcode/llm_gateway/types/generate_text_response_builder.py,sha256=6MV6JZuTyHUId3Slw9k7m0KBgjj-5S9HI4qtd94Jl2A,1272
50
51
  datacustomcode/llm_gateway_config.py,sha256=ECm9CFqOFOaLHwenvVFAjiRSzG9Eg9fY4pb8nHbQ34c,3312
@@ -85,13 +86,13 @@ datacustomcode/templates/script/examples/employee_hierarchy/employee_data.csv,sh
85
86
  datacustomcode/templates/script/examples/employee_hierarchy/entrypoint.py,sha256=Mfm3iQtEHTQRW6cmZTwRKdTh3IeGWR-teXrd6x-YLSY,2223
86
87
  datacustomcode/templates/script/jupyterlab.sh,sha256=IHR3YQ8d_busuyvesByhJgzCKULIFPI-Hqogs0NPhCs,2432
87
88
  datacustomcode/templates/script/payload/config.json,sha256=0d2mEMt4NHIeOUTsgiPMuRKdOLIQxmh-Wq-IfEqU-gc,28
88
- datacustomcode/templates/script/payload/entrypoint.py,sha256=HFrTe7--w5X78Sh4DVkoGGR6-zeqxemqp80RM20Rr4k,1642
89
+ datacustomcode/templates/script/payload/entrypoint.py,sha256=Ox2guNka3r0GW2jzKsmH7AP70j1-1Qqr_jhtH5dkPOM,1590
89
90
  datacustomcode/templates/script/requirements-dev.txt,sha256=OWwuy1awesqOZOS3Zizmdd6BDnSePpGFN5bq5IrALvc,176
90
91
  datacustomcode/templates/script/requirements.txt,sha256=qJbqzs5z0Hrx590U3T7dHq_m8UQEx2TdhgrJSz-QHIQ,40
91
92
  datacustomcode/token_provider.py,sha256=KPj_ca6mcBmhXHaPmZjAI4it8QvOWdwKJL8yfqxfYwU,5446
92
93
  datacustomcode/version.py,sha256=9LlbVrzwBvut1L308QbwNBgxdQk5CrghH39JARVSxms,989
93
- salesforce_data_customcode-6.0.2.dev1.dist-info/METADATA,sha256=8lK5D1Zf3TelM0vlib8QBQLtdmixh79g4ce2Owuh8QQ,21748
94
- salesforce_data_customcode-6.0.2.dev1.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
95
- salesforce_data_customcode-6.0.2.dev1.dist-info/entry_points.txt,sha256=WpQ94UB7UuRCYGOLtJV3vAgm1tl7iVf43VYRWIuNu5Y,74
96
- salesforce_data_customcode-6.0.2.dev1.dist-info/licenses/LICENSE.txt,sha256=iOi8EmQpfkFhMENi7VYtkl2EqS14pEOccoXHiW2dyPU,11443
97
- salesforce_data_customcode-6.0.2.dev1.dist-info/RECORD,,
94
+ salesforce_data_customcode-6.0.3.dev1.dist-info/METADATA,sha256=wmHyC6LrpV7uYwKuMBQEwfrztUX9gLb7v7YRwsYYGAg,21724
95
+ salesforce_data_customcode-6.0.3.dev1.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
96
+ salesforce_data_customcode-6.0.3.dev1.dist-info/entry_points.txt,sha256=WpQ94UB7UuRCYGOLtJV3vAgm1tl7iVf43VYRWIuNu5Y,74
97
+ salesforce_data_customcode-6.0.3.dev1.dist-info/licenses/LICENSE.txt,sha256=iOi8EmQpfkFhMENi7VYtkl2EqS14pEOccoXHiW2dyPU,11443
98
+ salesforce_data_customcode-6.0.3.dev1.dist-info/RECORD,,