Skip to content

Commit

Permalink
Update examples to ollama_chat (#691)
Browse files Browse the repository at this point in the history
* Change examples to use ollama_chat

Signed-off-by: Jing Chen <[email protected]>

* Update error.pdl

Signed-off-by: Jing Chen <[email protected]>

* More updates

Signed-off-by: Jing Chen <[email protected]>

* Use granite3.2:2b

Signed-off-by: Jing Chen <[email protected]>

* Update pdl-live demo traces

Signed-off-by: Jing Chen <[email protected]>

* Update results

Signed-off-by: Jing Chen <[email protected]>

* Update res

Signed-off-by: Jing Chen <[email protected]>

---------

Signed-off-by: Jing Chen <[email protected]>
  • Loading branch information
jgchn authored Mar 6, 2025
1 parent cadd935 commit e66e0de
Show file tree
Hide file tree
Showing 67 changed files with 138 additions and 146 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/run-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,14 @@ jobs:
- name: Pull models in examples/
shell: bash
run: |
ollama pull granite-code:8b
ollama pull granite3-dense:8b
ollama pull granite3.1-dense
ollama pull granite3.2:2b
ollama pull granite3.2
ollama pull granite3.2:8b
ollama pull mxbai-embed-large
ollama list
- name: Check that all required models are available
shell: bash
run: |
models=("granite-code" "granite3-dense" "granite3.1-dense" "mxbai-embed-large" "granite3.2:2b" "granite3.2" "granite3.2:8b")
models=("mxbai-embed-large" "granite3.2:2b")
missing=0
for model in "${models[@]}"; do
if ! ollama list | awk 'NR>1 {print $1}' | grep -q "$model"; then
Expand Down
2 changes: 1 addition & 1 deletion examples/callback/repair_prompt.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lastOf:
Please repair the code!

- def: raw_output
model: ollama/granite-code:8b
model: ollama_chat/granite3.2:2b
parameters:
#stop_sequences: "\n\n"
temperature: 0
Expand Down
4 changes: 2 additions & 2 deletions examples/chatbot/chatbot.pdl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
description: chatbot
description: Chatbot
text:
# Allow the user to type any question, implicitly adding the question to the context.
- read:
message: "What is your query?\n"
- repeat:
text:
# Send context to Granite model hosted at replicate.com
- model: ollama_chat/granite3.2:8b
- model: ollama_chat/granite3.2:2b
# Allow the user to type 'yes', 'no', or anything else, storing
# the input into a variable named `eval`. The input is also implicitly
# added to the context.
Expand Down
2 changes: 1 addition & 1 deletion examples/code/code-eval.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ text:
- "\n${ CODE.source_code }\n"
# Use ollama to invoke a Granite model with a prompt. Output AND
# set the variable `EXPLANATION` to the output.
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
def: EXPLANATION
input: |
Here is some info about the location of the function in the repo.
Expand Down
2 changes: 1 addition & 1 deletion examples/code/code-json.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defs:
TRUTH:
read: ./ground_truth.txt
text:
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
def: EXPLANATION
contribute: []
input:
Expand Down
2 changes: 1 addition & 1 deletion examples/code/code.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ text:
# Output the `source_code:` of the YAML to the console
- "\n${ CODE.source_code }\n"
# Use ollama to invoke a Granite model with a prompt
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
input: |
Here is some info about the location of the function in the repo.
repo:
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/3-weather.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description: Using a weather API and LLM to make a small weather app
text:
- def: QUERY
text: "What is the weather in Madrid?\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
input: |
Extract the location from the question.
Question: What is the weather in London?
Expand All @@ -25,7 +25,7 @@ text:
def: WEATHER
parser: json
contribute: []
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
input: |
Explain the weather from the following JSON:
${ WEATHER }
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/4-translator.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: PDL program
text:
- "What is APR?\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
- repeat:
text:
- read:
Expand All @@ -11,5 +11,5 @@ text:
then:
text:
- "\n\nTranslate the above to ${ language }\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
until: ${ language == 'stop' }
4 changes: 2 additions & 2 deletions examples/fibonacci/fib.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ text:
# Use IBM Granite to author a program that computes the Nth Fibonacci number,
# storing the generated program into the variable `CODE`.
- def: CODE
model: ollama/granite-code:8b
model: ollama_chat/granite3.2:2b
input: "Write a Python function to compute the Fibonacci sequence. Do not include a doc string.\n\n"
parameters:
# Request no randomness when generating code
Expand Down Expand Up @@ -42,4 +42,4 @@ text:

# Invoke the LLM again to explain the PDL context
- "\n\nExplain what the above code does and what the result means\n\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
2 changes: 1 addition & 1 deletion examples/granite/multi_round_chat.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ text:

${ prompt }
# Use replicate.com to run the Granite model on the context, outputting the result
- model: ollama/granite3.1-dense
- model: ollama_chat/granite3.2:2b
parameters:
# Use no LLM model creativity (0 is the default)
temperature: 0
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello-code-pdl.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ code: |
description: Hello world
text:
- "Hello\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
temperature: 0
2 changes: 1 addition & 1 deletion examples/hello/hello-def-use.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description: Hello world with variable use
text:
- "Hello\n"
# Define GEN to be the result of a Granite LLM using ollama
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
# Tell the LLM to stop after generating an exclamation point.
stop: ['!']
Expand Down
4 changes: 2 additions & 2 deletions examples/hello/hello-model-chaining.pdl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
description: Hello world showing model chaining
text:
- "Hello\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
# "greedy" sampling tells the LLM to use the most likely token at each step
# decoding_method: greedy # Not used by Ollama
# Tell the LLM to stop after generating an exclamation point.
stop: ['!']
def: GEN
- "\nDid you say ${ GEN }?\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
# decoding_method: greedy
stop: ['.']
2 changes: 1 addition & 1 deletion examples/hello/hello-model-input.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Hello world with model input
text:
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
input: "Hello,"
parameters:
# Tell the LLM to stop after generating an exclamation point.
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello-parser-json.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defs:
parser: yaml
spec: { questions: [str], answers: [obj] }
text:
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
def: model_output
spec: {name: str, age: int}
input:
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello-parser-regex.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Hello world with parser using regex
text:
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
input: "Hello,"
parameters:
# Tell the LLM to stop after generating an exclamation point.
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello-roles-array.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ text:
- role: user
content: Write a Python function that implement merge sort.
contribute: []
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
input: ${ prompt }

2 changes: 1 addition & 1 deletion examples/hello/hello-type.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ text:
return:
lastOf:
- "\nTranslate the sentence '${ sentence }' to ${ language }.\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
stop: ["\n"]
- call: ${ translate }
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello.pdl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description: Hello world
text:
- "Hello\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
82 changes: 41 additions & 41 deletions examples/intrinsics/demo-hallucination.pdl
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
# Granite.runtime Intrinsics Demo with PDL

# Provide document(s) to Granite3-rag model with hallucination_tag
# Provide document(s) to Granite3-rag model with hallucination_tag
# Granite3-rag model: Base model granite3-dense:8b setup with Granite RAG LoRA (Low-Rank Adaption) on ollama

# The model responds to a query providing a hallucination score

text:
- role: system
contribute: [context]
text:
text:
data:
instruction: |
Respond to the user's latest question based solely on the information provided
in the documents. Ensure that your response is strictly aligned with the facts
in the provided documents. If the information needed to answer the question is
not available in the documents, inform the user that the question cannot be
answered based on the available data. Make sure that your response follows
Respond to the user's latest question based solely on the information provided
in the documents. Ensure that your response is strictly aligned with the facts
in the provided documents. If the information needed to answer the question is
not available in the documents, inform the user that the question cannot be
answered based on the available data. Make sure that your response follows
the attributes mentioned in the 'meta' field.
documents:
documents:
- doc_id: 1
text: |
Audrey Faith McGraw (born September 21, 1967) is an American singer
and record producer. She is one of the most successful country artists
of all time, having sold more than 40 million albums worldwide. Hill is
married to American singer Tim McGraw, with whom she has recorded several duets.
Hill's first two albums, Take Me as I Am (1993) and It Matters to Me (1995),
were major successes and placed a combined three number ones on Billboard's
country charts. Hill's debut album was Take Me as I Am (1993); sales were strong,
buoyed by the chart success of "Wild One". Hill became the first female country
singer in 30 years to hold Billboard's number one position for four consecutive
weeks when "Wild One" managed the feat in 1994. Her version of "Piece of My Heart",
also went to the top of the country charts in 1994. The album sold a total of
3 million copies. Other singles from the album include "Take Me as I Am". The recording
of Faith's second album was delayed by surgery to repair a ruptured blood vessel on
her vocal cords. It Matters to Me finally appeared in 1995 and was another
success, with the title track becoming her third number-one country single.
Several other top 10 singles followed, and more than 3 million copies of the
album were sold. The fifth single from the album, "I Can't Do That Anymore",
was written by country music artist Alan Jackson. Other singles from the album
include "You Can't Lose Me", "Someone Else's Dream", and "Let's Go to Vegas".
During this period, Hill appeared on the acclaimed PBS music program Austin City Limits.
In spring 1996, Hill began the Spontaneous Combustion Tour with country singer Tim McGraw.
At that time, Hill had recently become engaged to her former producer, Scott Hendricks,
and McGraw had recently broken an engagement. McGraw and Hill were quickly
attracted to each other and began an affair. After discovering that Hill was
pregnant with their first child, the couple married on October 6, 1996. The
couple have three daughters together: Gracie Katherine (born 1997), Maggie Elizabeth (born 1998)
and Audrey Caroline (born 2001). Since their marriage, Hill and McGraw have endeavored
never to be apart for more than three consecutive days. After the release of It Matters to Me,
Audrey Faith McGraw (born September 21, 1967) is an American singer
and record producer. She is one of the most successful country artists
of all time, having sold more than 40 million albums worldwide. Hill is
married to American singer Tim McGraw, with whom she has recorded several duets.
Hill's first two albums, Take Me as I Am (1993) and It Matters to Me (1995),
were major successes and placed a combined three number ones on Billboard's
country charts. Hill's debut album was Take Me as I Am (1993); sales were strong,
buoyed by the chart success of "Wild One". Hill became the first female country
singer in 30 years to hold Billboard's number one position for four consecutive
weeks when "Wild One" managed the feat in 1994. Her version of "Piece of My Heart",
also went to the top of the country charts in 1994. The album sold a total of
3 million copies. Other singles from the album include "Take Me as I Am". The recording
of Faith's second album was delayed by surgery to repair a ruptured blood vessel on
her vocal cords. It Matters to Me finally appeared in 1995 and was another
success, with the title track becoming her third number-one country single.
Several other top 10 singles followed, and more than 3 million copies of the
album were sold. The fifth single from the album, "I Can't Do That Anymore",
was written by country music artist Alan Jackson. Other singles from the album
include "You Can't Lose Me", "Someone Else's Dream", and "Let's Go to Vegas".
During this period, Hill appeared on the acclaimed PBS music program Austin City Limits.
In spring 1996, Hill began the Spontaneous Combustion Tour with country singer Tim McGraw.
At that time, Hill had recently become engaged to her former producer, Scott Hendricks,
and McGraw had recently broken an engagement. McGraw and Hill were quickly
attracted to each other and began an affair. After discovering that Hill was
pregnant with their first child, the couple married on October 6, 1996. The
couple have three daughters together: Gracie Katherine (born 1997), Maggie Elizabeth (born 1998)
and Audrey Caroline (born 2001). Since their marriage, Hill and McGraw have endeavored
never to be apart for more than three consecutive days. After the release of It Matters to Me,
Hill took a three-year break from recording to give herself a rest from four years of touring
and to begin a family with McGraw. During her break, she joined forces with her husband
for their first duet, "It's Your Love". The song stayed at number one for six weeks,
and won awards from both the Academy of Country Music and the Country Music Association.
Hill has remarked that sometimes when they perform the song together,
and to begin a family with McGraw. During her break, she joined forces with her husband
for their first duet, "It's Your Love". The song stayed at number one for six weeks,
and won awards from both the Academy of Country Music and the Country Music Association.
Hill has remarked that sometimes when they perform the song together,
"it [doesn't] feel like anybody else was really watching."
meta:
hallucination_tags: true
Expand All @@ -70,7 +70,7 @@ text:
- defs:
# Store the results of making the LLM invocation in a JSON variable named 'out'
out:
model: ollama/granite3-rag:8b
model: ollama_chat/granite3.2:2b
parameters:
temperature: 0
parser: json
Expand Down
4 changes: 2 additions & 2 deletions examples/rag/pdf_query.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ lastOf:
inp: ${ question }
encoder_model: "ollama/mxbai-embed-large"
limit: 3
collection_name: "pdl_rag_collection"
collection_name: "pdl_rag_collection"
database_name: "./pdl-rag-demo.db"
# debug:
# lang: python
# code: |
# print(f"MATCHING_PASSAGES='{MATCHING_PASSAGES}'")
# result = None
CONCLUSION:
model: ollama/granite-code:8b
model: ollama_chat/granite3.2:2b
input: >
Here is some information:
${ MATCHING_PASSAGES }
Expand Down
2 changes: 1 addition & 1 deletion examples/rag/tfidf_rag.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ text:

Q: ${ TEST_PROMPT }
A:
- model: ollama/granite3.2:8b
- model: ollama_chat/granite3.2:2b
parameters:
temperature: 0
2 changes: 1 addition & 1 deletion examples/sdk/hello.pdl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
text:
- "Hello\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
stop: ['!']
2 changes: 1 addition & 1 deletion examples/talk/1-hello.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Model call
text:
- "Hello\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
stop: ["!"]
# include_stop_sequence: true
Expand Down
4 changes: 2 additions & 2 deletions examples/talk/2-model-chaining.pdl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
description: Model chaining
text:
- "Hello\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
stop: ["!"]
- "\nDid you just say Hello?\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
parameters:
stop: ["!"]
4 changes: 2 additions & 2 deletions examples/talk/3-def-use.pdl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
description: Variable def and use, model input
text:
- "Hello\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
def: name
parameters:
stop: ["!"]
- "\n"
- model: ollama/granite-code:8b
- model: ollama_chat/granite3.2:2b
input: "Translate the word ${ name | trim } to French\n"
parameters:
stop: ["\n"]
Expand Down
Loading

0 comments on commit e66e0de

Please sign in to comment.