Skip to content

Commit 604882e

Browse files
committed
Merge branch 'main' into pdl-214
2 parents ccf0903 + dd446ab commit 604882e

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pip install 'prompt-declaration-language[examples]'
9191

9292
You can run PDL with LLM models in local using [Ollama](https://ollama.com), or other cloud service.
9393

94-
If you use WatsonX:
94+
If you use watsonx:
9595
```bash
9696
export WATSONX_URL="https://{region}.ml.cloud.ibm.com"
9797
export WATSONX_APIKEY="your-api-key"

docs/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ In order to run these examples, you need to create a free account
5353
on Replicate, get an API key and store it in the environment variable:
5454
- `REPLICATE_API_TOKEN`
5555

56-
In order to use foundation models hosted on [watsonx](https://www.ibm.com/watsonx) via LiteLLM, you need a WatsonX account (a free plan is available) and set up the following environment variables:
57-
- `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your WatsonX instance. The region can be found by clicking in the upper right corner of the watsonx dashboard (for example a valid region is `us-south` ot `eu-gb`).
56+
In order to use foundation models hosted on [watsonx](https://www.ibm.com/watsonx) via LiteLLM, you need a watsonx account (a free plan is available) and set up the following environment variables:
57+
- `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your watsonx instance. The region can be found by clicking in the upper right corner of the watsonx dashboard (for example a valid region is `us-south` ot `eu-gb`).
5858
- `WATSONX_APIKEY`, the API key (see information on [key creation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key))
5959
- `WATSONX_PROJECT_ID`, the project hosting the resources (see information about [project creation](https://www.ibm.com/docs/en/watsonx/saas?topic=projects-creating-project) and [finding project ID](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-project-id.html?context=wx)).
6060

@@ -83,8 +83,8 @@ The PDL repository has been configured so that every `*.pdl` file is associated
8383
```
8484

8585
The interpreter executes Python code specified in PDL code blocks. To sandbox the interpreter for safe execution,
86-
you can use the `--sandbox` flag which runs the interpreter in a docker container. Without this flag, the interpreter
87-
and all code is executed locally. To use the `--sandbox` flag, you need to have a docker daemon running, such as
86+
you can use the `--sandbox` flag which runs the interpreter in a Docker-compatible container. Without this flag, the interpreter
87+
and all code is executed locally. To use the `--sandbox` flag, you need to have a Docker daemon running, such as
8888
[Rancher Desktop](https://rancherdesktop.io).
8989

9090
The interpreter prints out a log by default in the file `log.txt`. This log contains the details of inputs and outputs to every block in the program. It is useful to examine this file when the program is behaving differently than expected. The log displays the exact prompts submitted to models by LiteLLM (after applying chat templates), which can be
@@ -150,7 +150,7 @@ Hello
150150

151151
where the second `Hello` was produced by Granite. In general, PDL provides blocks for calling models, Python code, and makes it easy to compose them together with control structures (sequencing, conditions, loops).
152152

153-
A similar example on WatsonX would look as follows:
153+
A similar example on watsonx would look as follows:
154154

155155
```yaml
156156
description: Hello world
@@ -163,7 +163,7 @@ text:
163163
- '!'
164164
```
165165

166-
Notice the syntactic differences. Model ids on WatsonX start with `watsonx`. The `decoding_method` can be set to `greedy`, rather than setting the temperature to `0`. Also, `stop_sequences` are indicated with the keyword `stop` instead as a list of strings.
166+
Notice the syntactic differences. Model ids on watsonx start with `watsonx`. The `decoding_method` can be set to `greedy`, rather than setting the temperature to `0`. Also, `stop_sequences` are indicated with the keyword `stop` instead as a list of strings.
167167

168168
A PDL program computes 2 data structures. The first is a JSON corresponding to the result of the overall program, obtained by aggregating the results of each block. This is what is printed by default when we run the interpreter. The second is a conversational background context, which is a list of role/content pairs, where we implicitly keep track of roles and content for the purpose of communicating with models that support chat APIs. The contents in the latter correspond to the results of each block. The conversational background context is what is used to make calls to LLMs via LiteLLM.
169169

examples/cldk/cldk-assistant.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ text:
1818
cldk = CLDK("java")
1919
cldk_state = cldk.analysis(
2020
project_path="${ project }", # Change this to the path of the project you want to analyze.
21-
# langguage="java", # The langguage of the project.
21+
# language="java", # The language of the project.
2222
# backend="codeanalyzer", # The backend to use for the analysis.
2323
# analysis_db="/tmp", # A temporary directory to store the analysis results.
2424
# sdg=True, # Generate the System Dependence Graph (SDG) for the project.

examples/fibonacci/fib.pdl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
1+
# Demonstrate using an LLM to write a program to compute Fibonacci numbers,
2+
# and invoke generated code with a random number
13
description: Fibonacci
4+
25
text:
6+
# Use IBM Granite to author a program that computes the Nth Fibonacci number
37
- def: CODE
48
model: replicate/ibm-granite/granite-3.0-8b-instruct
59
input: "Write a Python function to compute the Fibonacci sequence. Do not include a doc string.\n\n"
610
parameters:
11+
# Request no randomness when generating code
712
temperature: 0
8-
13+
14+
# Pick a random number 1..20
915
- "\nFind a random number between 1 and 20\n"
1016
- def: N
1117
lang: python
1218
code: |
1319
import random
1420
result = random.randint(1, 20)
21+
1522
- "\nNow computing fibonacci(${ N })\n"
23+
24+
# Extract the LLM response inside backticks as executable Python code, and set PDL variable EXTRACTED
1625
- def: EXTRACTED
1726
lang: python
1827
code: |
1928
s = """'${ CODE } '"""
2029
result = s.split("```")[1].replace("python", "")
30+
31+
# Run the extracted Fibonacci function using a random number
2132
- def: RESULT
2233
lang: python
2334
code: |
2435
${ EXTRACTED }
2536
result = fibonacci(${ N })
37+
# (Don't store the result in the PDL context; store it in a PDL variable called RESULT)
2638
contribute: []
2739
- 'The result is: ${ RESULT }'
40+
41+
# Invoke the LLM again to explain the PDL context
2842
- "\n\nExplain what the above code does and what the result means\n\n"
2943
- model: replicate/ibm-granite/granite-3.0-8b-instruct
3044

src/pdl/pdl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def main():
157157
parser.add_argument(
158158
"--sandbox",
159159
action=argparse.BooleanOptionalAction,
160-
help="run the interpreter in a container, a docker daemon must be running",
160+
help="run the interpreter in a container, a Docker-compatible daemon must be running",
161161
)
162162
parser.add_argument(
163163
"-f",
@@ -191,7 +191,7 @@ def main():
191191
parser.add_argument(
192192
"--schema",
193193
action="store_true",
194-
help="generate PDL Json Schema and exit",
194+
help="generate PDL JSON Schema and exit",
195195
default=False,
196196
)
197197
parser.add_argument(

0 commit comments

Comments
 (0)