Skip to content

Commit 8754d2b

Browse files
fix ci build failures, ruff, black, isort, etc
1 parent fcfdc5d commit 8754d2b

12 files changed

Lines changed: 184 additions & 112 deletions

File tree

src/datacustomcode/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def llm_gateway_generate_text_col(
6666
Example:
6767
6868
>>> df.withColumn(
69-
... "Greeting__c",
69+
... "greeting__c",
7070
... llm_gateway_generate_text_col(
7171
... "In one sentence, greet {name} from {city}.",
72-
... {"name": col("Name__c"), "city": col("HomeCity__c")},
72+
... {"name": col("name__c"), "city": col("homecity__c")},
7373
... model_id="sfdc_ai__DefaultGPT4Omni",
7474
... max_tokens=100,
7575
... ),

src/datacustomcode/einstein_platform_config.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515

1616
from typing import (
1717
ClassVar,
18+
Generic,
1819
Optional,
1920
Type,
20-
cast,
21+
TypeVar,
2122
)
2223

2324
from datacustomcode.common_config import BaseObjectConfig
2425

26+
_T = TypeVar("_T")
2527

26-
class CredentialsObjectConfig(BaseObjectConfig):
28+
29+
class CredentialsObjectConfig(BaseObjectConfig, Generic[_T]):
2730
type_to_create: ClassVar[Type]
2831
credentials_profile: Optional[str] = None
2932
sf_cli_org: Optional[str] = None
3033

31-
def to_object(self):
34+
def to_object(self) -> _T:
3235
"""Create an object instance, automatically including credentials in options"""
3336

3437
options = self.options.copy()
@@ -38,4 +41,5 @@ def to_object(self):
3841
options["sf_cli_org"] = self.sf_cli_org
3942

4043
type_ = self.type_to_create.subclass_from_config_name(self.type_config_name)
41-
return cast("type_", type_(**options))
44+
instance: _T = type_(**options)
45+
return instance

src/datacustomcode/einstein_predictions_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_E = TypeVar("_E", bound=EinsteinPredictions)
2929

3030

31-
class EinsteinPredictionsObjectConfig(CredentialsObjectConfig, Generic[_E]):
31+
class EinsteinPredictionsObjectConfig(CredentialsObjectConfig[_E], Generic[_E]):
3232
type_to_create: ClassVar[Type[EinsteinPredictions]] = EinsteinPredictions # type: ignore[type-abstract]
3333

3434

src/datacustomcode/llm_gateway_config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
Type,
2020
TypeVar,
2121
Union,
22-
cast,
2322
)
2423

2524
from datacustomcode.common_config import (
@@ -35,7 +34,7 @@
3534
_S = TypeVar("_S", bound=SparkLLMGateway)
3635

3736

38-
class LLMGatewayObjectConfig(CredentialsObjectConfig, Generic[_E]):
37+
class LLMGatewayObjectConfig(CredentialsObjectConfig[_E], Generic[_E]):
3938
type_to_create: ClassVar[Type[LLMGateway]] = LLMGateway # type: ignore[type-abstract]
4039

4140

@@ -64,7 +63,7 @@ class SparkLLMGatewayObjectConfig(BaseObjectConfig, Generic[_S]):
6463

6564
def to_object(self) -> SparkLLMGateway:
6665
type_ = self.type_to_create.subclass_from_config_name(self.type_config_name)
67-
return cast("SparkLLMGateway", type_(**self.options))
66+
return type_(**self.options)
6867

6968

7069
class SparkLLMGatewayConfig(BaseConfig):

src/datacustomcode/templates/function/example/chunking_with_llm/entrypoint.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
- Requires Runtime parameter (for agentic capabilities)
88
- Type-safe with direct field access (no wrappers)
99
- Automatic validation and conversion
10-
"""
1110
12-
"""
13-
You can use your AI models configured in Salesforce to generate texts.
11+
You can use your AI models configured in Salesforce to generate texts.
12+
13+
For testing locally before deploying your code to Data Cloud
14+
(``datacustomcode run``), first configure an external client app before using
15+
LLM functionality, then configure the SDK with your client app credentials.
1416
15-
For testing locally before deploying your code to Data Cloud (datacustomcode run),
16-
first configure an external client app before using LLM functionality, then configure
17-
the SDK with your client app credentials.
18-
19-
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
17+
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
2018
"""
2119

2220
import logging

src/datacustomcode/templates/function/example/chunking_with_prediction/entrypoint.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
Type: Regression
1313
Input: Year_Built__c (numeric)
1414
Output: Predicted_SalePrice
15-
"""
1615
17-
"""
18-
You can use your AI models configured in Salesforce to make predictions.
16+
You can use your AI models configured in Salesforce to make predictions.
17+
18+
For testing locally before deploying your code to Data Cloud
19+
(``datacustomcode run``), first configure an external client app before using
20+
LLM functionality, then configure the SDK with your client app credentials.
1921
20-
For testing locally before deploying your code to Data Cloud (datacustomcode run),
21-
first configure an external client app before using LLM functionality, then configure
22-
the SDK with your client app credentials.
23-
24-
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
22+
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
2523
"""
2624

2725
import logging

src/datacustomcode/templates/function/payload/entrypoint.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ def function(request: dict, runtime: Runtime) -> dict:
8484
current_seq_no = 1 # Start sequence number from 1
8585

8686
"""
87-
You can use your AI models configured in Salesforce to generate texts or predict an outcome.
87+
You can use your AI models configured in Salesforce to generate texts
88+
or predict an outcome.
89+
90+
For testing locally before deploying your code to Data Cloud
91+
(``datacustomcode run``), first configure an external client app before
92+
using LLM functionality, then configure the SDK with your client app
93+
credentials.
8894
89-
For testing locally before deploying your code to Data Cloud (datacustomcode run),
90-
first configure an external client app before using LLM functionality, then configure
91-
the SDK with your client app credentials.
92-
9395
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
9496
9597
Example:

src/datacustomcode/templates/script/payload/entrypoint.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ def main():
1313
df_upper1 = df.withColumn("description__c", upper(col("description__c")))
1414

1515
"""
16-
You can use your AI models configured in Salesforce to generate column values.
17-
For testing locally before deploying your code to Data Cloud (datacustomcode run),
18-
first configure an external client app before using LLM functionality, then configure
19-
the SDK with your client app credentials.
20-
16+
You can use your AI models configured in Salesforce to generate column
17+
values. For testing locally before deploying your code to Data Cloud
18+
(``datacustomcode run``), first configure an external client app before
19+
using LLM functionality, then configure the SDK with your client app
20+
credentials.
21+
2122
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
2223
2324
Example:
2425
2526
>>> from datacustomcode.client import llm_gateway_generate_text_col
2627
df_generated = df.withColumn(
27-
... "Greeting__c",
28+
... "greeting__c",
2829
... llm_gateway_generate_text_col(
2930
... "In one sentence, greet {name} from {city}.",
30-
... {"name": col("Name__c"), "city": col("HomeCity__c")},
31+
... {"name": col("name__c"), "city": col("homecity__c")},
3132
... model_id="sfdc_ai__DefaultGPT4Omni",
3233
... max_tokens=100,
3334
... ),
@@ -38,7 +39,9 @@ def main():
3839
3940
Example:
4041
41-
>>> generated_text = client.llm_gateway_generate_text(prompt, model_id, max_tokens)
42+
>>> generated_text = client.llm_gateway_generate_text(
43+
... prompt, model_id, max_tokens
44+
... )
4245
"""
4346

4447
# Drop specific columns related to relationships

tests/test_function_utils.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
def sample_entrypoint():
3030
"""Create a temporary entrypoint file with a function."""
3131
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as temp_file:
32-
entrypoint_content = textwrap.dedent("""
32+
entrypoint_content = textwrap.dedent(
33+
"""
3334
from typing import List
3435
from pydantic import BaseModel
3536
@@ -45,7 +46,8 @@ class SampleResponse(BaseModel):
4546
4647
def function(request: SampleRequest) -> SampleResponse:
4748
return SampleResponse(result=f"Processed {request.message}")
48-
""")
49+
"""
50+
)
4951
temp_file.write(entrypoint_content)
5052
temp_file_path = temp_file.name
5153

@@ -59,10 +61,12 @@ def function(request: SampleRequest) -> SampleResponse:
5961
def entrypoint_no_annotations():
6062
"""Create an entrypoint with no type annotations."""
6163
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as temp_file:
62-
entrypoint_content = textwrap.dedent("""
64+
entrypoint_content = textwrap.dedent(
65+
"""
6366
def function(request):
6467
return {"result": "no annotations"}
65-
""")
68+
"""
69+
)
6670
temp_file.write(entrypoint_content)
6771
temp_file_path = temp_file.name
6872

@@ -142,7 +146,8 @@ def test_generate_test_json():
142146
output_simple = os.path.join(temp_dir, "test_simple.json")
143147

144148
with open(models_file, "w") as f:
145-
models_content = textwrap.dedent("""
149+
models_content = textwrap.dedent(
150+
"""
146151
from pydantic import BaseModel
147152
from typing import List
148153
@@ -162,16 +167,19 @@ class ComplexRequest(BaseModel):
162167
max_items: int = 100
163168
config: NestedConfig
164169
metadata: dict = {}
165-
""")
170+
"""
171+
)
166172
f.write(models_content)
167173

168174
with open(entrypoint_simple, "w") as f:
169-
entrypoint_content = textwrap.dedent("""
175+
entrypoint_content = textwrap.dedent(
176+
"""
170177
from test_models import SimpleRequest
171178
172179
def function(request: SimpleRequest):
173180
return {"result": "ok"}
174-
""")
181+
"""
182+
)
175183
f.write(entrypoint_content)
176184

177185
sys.path.insert(0, temp_dir)
@@ -195,12 +203,14 @@ def function(request: SimpleRequest):
195203
output_complex = os.path.join(temp_dir, "test_complex.json")
196204

197205
with open(entrypoint_complex, "w") as f:
198-
entrypoint_content = textwrap.dedent("""
206+
entrypoint_content = textwrap.dedent(
207+
"""
199208
from test_models import ComplexRequest
200209
201210
def function(request: ComplexRequest):
202211
return {"result": "ok"}
203-
""")
212+
"""
213+
)
204214
f.write(entrypoint_content)
205215

206216
function_utils.generate_test_json(entrypoint_complex, output_complex)

tests/test_run.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def test_config_file():
4848
def test_entrypoint_file():
4949
"""Create a temporary test entrypoint script with config.json."""
5050
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as temp:
51-
entrypoint_content = textwrap.dedent("""
51+
entrypoint_content = textwrap.dedent(
52+
"""
5253
# Test entrypoint
5354
import os
5455
import sys
@@ -71,7 +72,8 @@ def test_entrypoint_file():
7172
if config.writer_config else None
7273
)
7374
f.write(f"Writer type: {writer_type}\\n")
74-
""")
75+
"""
76+
)
7577
temp.write(entrypoint_content.encode("utf-8"))
7678
temp_name = temp.name
7779

@@ -163,14 +165,16 @@ def test_run_entrypoint_with_dependencies():
163165

164166
# Create a temp entrypoint that uses the dependency
165167
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as temp:
166-
entrypoint_content = textwrap.dedent("""
168+
entrypoint_content = textwrap.dedent(
169+
"""
167170
# Test entrypoint with dependency
168171
import test_dependency
169172
170173
# Store dependency value in a file to check later
171174
with open("dependency_output.txt", "w") as f:
172175
f.write(f"Dependency value: {test_dependency.TEST_CONSTANT}\\n")
173-
""")
176+
"""
177+
)
174178
temp.write(entrypoint_content.encode("utf-8"))
175179
entrypoint_file = temp.name
176180

@@ -239,7 +243,8 @@ class TestDataspaceScenarios:
239243
def test_run_entrypoint_with_default_dataspace(self):
240244
"""Test that run_entrypoint sets dataspace='default' correctly."""
241245
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as temp:
242-
entrypoint_content = textwrap.dedent("""
246+
entrypoint_content = textwrap.dedent(
247+
"""
243248
# Test entrypoint
244249
from datacustomcode.config import config
245250
with open("dataspace_output.txt", "w") as f:
@@ -255,7 +260,8 @@ def test_run_entrypoint_with_default_dataspace(self):
255260
)
256261
f.write(f"Reader dataspace: {rds}\\n")
257262
f.write(f"Writer dataspace: {wds}\\n")
258-
""")
263+
"""
264+
)
259265
temp.write(entrypoint_content.encode("utf-8"))
260266
entrypoint_file = temp.name
261267

@@ -290,7 +296,8 @@ def test_run_entrypoint_with_custom_dataspace(self):
290296
"""Test that run_entrypoint sets custom dataspace correctly."""
291297
custom_dataspace = "dataspace-1"
292298
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as temp:
293-
entrypoint_content = textwrap.dedent("""
299+
entrypoint_content = textwrap.dedent(
300+
"""
294301
# Test entrypoint
295302
from datacustomcode.config import config
296303
with open("dataspace_output.txt", "w") as f:
@@ -306,7 +313,8 @@ def test_run_entrypoint_with_custom_dataspace(self):
306313
)
307314
f.write(f"Reader dataspace: {rds}\\n")
308315
f.write(f"Writer dataspace: {wds}\\n")
309-
""")
316+
"""
317+
)
310318
temp.write(entrypoint_content.encode("utf-8"))
311319
entrypoint_file = temp.name
312320

0 commit comments

Comments
 (0)