Skip to content

Commit a1baec6

Browse files
authored
Merge pull request #83 from forcedotcom/add-llm_gateway_generate_text
add llm_gateway_generate_text
2 parents b3e84ee + f502e24 commit a1baec6

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
# Changelog
22

3+
## 1.0.1
4+
5+
### Added
6+
7+
- **`llm_gateway_generate_text()` UDF wrapper for AI-powered DataFrame transformations.**
8+
9+
New method on proxy providers to generate AI completions in DataFrame operations via a built-in UDF.
10+
11+
```python
12+
from datacustomcode import Client
13+
from pyspark.sql.functions import col
14+
15+
client = Client()
16+
17+
# Generate summaries in a DataFrame column
18+
df = df.withColumn(
19+
"summary",
20+
client._proxy.llm_gateway_generate_text(
21+
"Summarize {company}: revenue={revenue}, CEO={ceo}",
22+
{
23+
"company": col("company"),
24+
"revenue": col("revenue"),
25+
"ceo": col("ceo")
26+
},
27+
llmModelId="sfdc_ai__DefaultGPT4Omni",
28+
maxTokens=200
29+
)
30+
)
31+
```
32+
33+
**Local Development:** Returns placeholder string (doesn't execute)
34+
**Production:** Calls a built-in UDF
35+
36+
**Parameters:**
37+
- `template` (str): Prompt template with {placeholder} syntax
38+
- `values` (dict or Column): Dict mapping placeholders to Columns, or pre-built named_struct
39+
- `llmModelId` (str): Model identifier (required, e.g., "sfdc_ai__DefaultGPT4Omni")
40+
- `maxTokens` (int): Maximum tokens that will be spent on this query
41+
42+
343
## 1.0.0
444

545
### Breaking Changes

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ You should only need the following methods:
155155
* `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
156156

157157
For example:
158-
```
158+
```python
159159
from datacustomcode import Client
160160

161161
client = Client()
@@ -166,10 +166,37 @@ sdf = client.read_dlo('my_DLO')
166166
client.write_to_dlo('output_DLO')
167167
```
168168

169-
170169
> [!WARNING]
171170
> Currently we only support reading from DMOs and writing to DMOs or reading from DLOs and writing to DLOs, but they cannot mix.
172171
172+
### LLM Gateway
173+
174+
Generate AI completions in DataFrame transformations using the LLM gateway UDF.
175+
176+
```python
177+
from datacustomcode import Client
178+
from pyspark.sql.functions import col
179+
180+
client = Client()
181+
182+
# Use template with placeholders
183+
df = df.withColumn(
184+
"summary",
185+
client._proxy.llm_gateway_generate_text(
186+
"Summarize {company}: revenue={revenue}, CEO={ceo}",
187+
{
188+
"company": col("company"),
189+
"revenue": col("revenue"),
190+
"ceo": col("ceo")
191+
},
192+
llmModelId="sfdc_ai__DefaultGPT4Omni",
193+
maxTokens=200
194+
)
195+
)
196+
```
197+
198+
> [!WARNING]
199+
> This method returns a placeholder string in local development. It only makes a LLM call and spends tokens when deployed, where it calls the real LLM Gateway service via a built-in UDF.
173200
174201
## CLI
175202

src/datacustomcode/proxy/client/LocalProxyClientProvider.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ def __init__(self, **kwargs: object) -> None:
2727

2828
def call_llm_gateway(self, llmModelId: str, prompt: str, maxTokens: int) -> str:
2929
return f"Hello, thanks for using {llmModelId}. So many tokens: {maxTokens}"
30+
31+
def llm_gateway_generate_text(
32+
self, template, values, llmModelId: str, maxTokens: int
33+
):
34+
return f"Using Generate Text with {llmModelId} and maxTokens: {maxTokens}"

src/datacustomcode/proxy/client/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ def __init__(self):
2525

2626
@abstractmethod
2727
def call_llm_gateway(self, llmModelId: str, prompt: str, maxTokens: int) -> str: ...
28+
29+
@abstractmethod
30+
def llm_gateway_generate_text(
31+
self, template, values, llmModelId: str, maxTokens: int
32+
): ...

0 commit comments

Comments
 (0)