Skip to content

Commit 240db70

Browse files
add the llm gateway testing comment in readme
1 parent 8754d2b commit 240db70

5 files changed

Lines changed: 52 additions & 26 deletions

File tree

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,53 @@ Options:
305305
- `--function-invoke-opt TEXT`: Currently we support only `UnstructuredChunking` for functions.
306306

307307

308+
## Testing LLM Gateway
309+
310+
You can use AI models configured in Salesforce to generate responses while transforming your data. Below is a sample code example:
311+
312+
```
313+
from datacustomcode.client import Client, llm_gateway_generate_text_col
314+
315+
316+
def main():
317+
client = Client()
318+
df = client.read_dlo("Input__dll")
319+
df_generated = df.withColumn(
320+
"greeting__c",
321+
llm_gateway_generate_text_col(
322+
"In one sentence, greet {name} from {city}.",
323+
{"name": col("name__c"), "city": col("homecity__c")},
324+
model_id="sfdc_ai__DefaultGPT4Omni", # An AI model in your org
325+
max_tokens=100,
326+
),
327+
)
328+
329+
dlo_name = "Output_dll"
330+
client.write_to_dlo(dlo_name, df_upper1, write_mode=WriteMode.APPEND)
331+
332+
greeting = client.llm_gateway_generate_text("In one sentence, generate a greeting message", "sfdc_ai__DefaultGPT52")
333+
334+
if __name__ == "__main__":
335+
main()
336+
```
337+
338+
In order to test this code on your local machine before deploying it to Data Cloud, you must first set up an External Client App that allows access to the Agent API. Follow this guide to create the ECA https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app. You must use `http://localhost:1717/OauthRedirect` as the callback URL.
339+
340+
Once the ECA is set up, log in to your org using this ECA
341+
```
342+
sf org login web \
343+
--alias myorg \
344+
--instance-url https://{MY_DOMAIN_URL} \
345+
--client-id {CONSUMER_KEY} \
346+
--scopes "sfap_api api"
347+
```
348+
349+
then you can test your code using `myorg` alias
350+
```
351+
datacustomcode run ./payload/entrypoint.py --sf-cli-org myorg
352+
```
353+
354+
308355
## Docker usage
309356

310357
The SDK provides Docker-based development options that allow you to test your code in an environment that closely resembles Data Cloud's execution environment.

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99
- Automatic validation and conversion
1010
1111
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.
16-
17-
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
12+
See README.md for how to test locally before deploying to Data Cloud.
1813
"""
1914

2015
import logging

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
Output: Predicted_SalePrice
1515
1616
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.
21-
22-
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
17+
See README.md for how to test locally before deploying to Data Cloud.
2318
"""
2419

2520
import logging

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,8 @@ def function(request: dict, runtime: Runtime) -> dict:
8585

8686
"""
8787
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.
94-
95-
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
88+
or predict an outcome. See README.md for how to test locally before
89+
deploying to Data Cloud.
9690
9791
Example:
9892

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ def main():
1414

1515
"""
1616
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-
22-
https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api-get-started.html#create-a-salesforce-app
17+
values. See README.md for how to test locally before deploying to Data Cloud.
2318
2419
Example:
2520

0 commit comments

Comments
 (0)