Skip to content

Commit 574cf70

Browse files
authored
Deploy Ollama to run examples (#629)
* Deploy ollama on GH Actions and run against tests Signed-off-by: Jing Chen <[email protected]> * Set up nightly tests Signed-off-by: Jing Chen <[email protected]> * Update checks Signed-off-by: Jing Chen <[email protected]> * Address no disk space Signed-off-by: Jing Chen <[email protected]> * Rm failing test Signed-off-by: Jing Chen <[email protected]> --------- Signed-off-by: Jing Chen <[email protected]>
1 parent 2bf2aa0 commit 574cf70

27 files changed

+422
-22
lines changed

.github/workflows/run-examples.yml

+52-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- cron: '0 1 * * *'
77
workflow_dispatch:
88

9+
910
jobs:
1011
tests:
1112
name: Execution tests
@@ -16,6 +17,56 @@ jobs:
1617
python-version: ['3.11', '3.12', '3.13']
1718

1819
steps:
20+
21+
# Free up some disk space
22+
- name: Remove unnecessary files
23+
run: |
24+
sudo rm -rf /usr/share/dotnet
25+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
26+
27+
# Set up Ollama
28+
- name: Install Ollama and start server
29+
shell: bash
30+
run: |
31+
curl -fsSL https://ollama.com/install.sh | sudo -E sh
32+
33+
- name: Pull models in examples/
34+
shell: bash
35+
run: |
36+
ollama pull granite-code:8b
37+
ollama pull granite3-dense:8b
38+
ollama pull granite3.1-dense
39+
ollama pull granite3.2:2b
40+
ollama pull granite3.2
41+
ollama pull granite3.2:8b
42+
ollama pull mxbai-embed-large
43+
ollama list
44+
45+
- name: Check that all required models are available
46+
shell: bash
47+
run: |
48+
models=("granite-code" "granite3-dense" "granite3.1-dense" "mxbai-embed-large" "granite3.2:2b" "granite3.2" "granite3.2:8b")
49+
missing=0
50+
for model in "${models[@]}"; do
51+
if ! ollama list | awk 'NR>1 {print $1}' | grep -q "$model"; then
52+
echo "❌ Model $model (or substring) is missing!"
53+
missing=1
54+
fi
55+
done
56+
57+
if [ "$missing" -eq 1 ]; then
58+
exit 1
59+
else
60+
echo "✅ All expected models are available."
61+
fi
62+
63+
- name: Wait for Ollama server
64+
shell: bash
65+
run: |
66+
sleep 10
67+
time curl -i http://localhost:11434
68+
69+
# Run tests
1970
- uses: actions/checkout@v4
2071
- name: Set up Python ${{ matrix.python-version }}
2172
uses: actions/setup-python@v5
@@ -45,4 +96,4 @@ jobs:
4596
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
4697
WATSONX_URL: ${{ secrets.WATSONX_URL }}
4798
REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }}
48-
run: py.test -v --capture=tee-sys tests/test_examples_run.py
99+
run: py.test -v --capture=tee-sys -rfE -s tests/test_examples_run.py

examples/granite/multi_round_chat.pdl

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ text:
1818

1919
${ prompt }
2020
# Use replicate.com to run the Granite model on the context, outputting the result
21-
- model: replicate/ibm-granite/granite-3.1-8b-instruct
21+
- model: ollama/granite3.1-dense
2222
parameters:
2323
# Use no LLM model creativity (0 is the default)
2424
temperature: 0

examples/hello/hello-code-pdl.pdl

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ code: |
44
description: Hello world
55
text:
66
- "Hello\n"
7-
- model: replicate/ibm-granite/granite-3.1-8b-instruct
8-
7+
- model: ollama/granite-code:8b
8+
parameters:
9+
temperature: 0

examples/rag/tfidf_rag.pdl

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ text:
4141
- |-
4242

4343
Q: ${ TEST_PROMPT }
44-
A:
45-
- model: replicate/ibm-granite/granite-3.0-8b-instruct
44+
A:
45+
- model: ollama/granite3.2:8b
46+
parameters:
47+
temperature: 0

examples/tutorial/parser_regex.pdl

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
description: Hello world with parser using regex
22
text:
33
- model: ollama/granite-code:8b
4+
parameters:
5+
temperature: 0
46
input: "Hello,"
57
parameters:
68
# Tell the LLM to stop after generating an exclamation point.

pdl-live-react/demos/demo2.pdl

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
description: Model chaining
22
text:
33
- "write a hello world example, and explain to me how to run it"
4-
- model: ollama/granite3.2:8b
4+
- model: ollama/granite3.2
5+
parameters:
6+
temperature: 0
57
- "how about in Rust?"
6-
- model: ollama/granite3.2:8b
8+
- model: ollama/granite3.2
9+
parameters:
10+
temperature: 0
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11

22
What is APR?
3-
APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction.
3+
APR stands for Annual Percentage Rate. It's a measure of the cost of a loan, expressed as a yearly rate that includes not only interest but also other charges or fees that may be associated with the loan. This allows consumers to compare different loans and understand their true cost more easily. APR is calculated by taking into account the interest rate, points, mortgage insurance, and other costs over the life of the loan. It's important to note that APR doesn't necessarily reflect the actual interest rate you'll be charged; it's a standardized way to compare loans from different lenders.
44
Can you write a poem about APR?
5-
In the world of finance, APR is the key,
6-
A number that tells us what we'll pay, or earn, you see.
7-
It's the annual rate, both simple and clear,
8-
Including all fees, for loans and investments, near and far.
9-
10-
It's the cost of borrowing, or the return we gain,
11-
A figure that helps us make informed financial gain.
12-
So, when you're comparing loans, or investments to choose,
13-
Remember APR, and make the right move.
5+
In finance, there's a term so neat,
6+
APR, it helps us to compete.
7+
Not just interest, but all the fees,
8+
A yearly rate that sets loans free.
9+
10+
From mortgages to credit cards,
11+
It guides our choices, as per the charts.
12+
Points, insurance, and more,
13+
In this calculation, they're no chore.
14+
15+
A standardized tool for comparison,
16+
Helping us avoid financial frustration.
17+
Though it may not reflect the true rate,
18+
APR is a helpful trait.
19+
20+
So when you borrow, take a peek,
21+
At APR, and don't be meek.
22+
Understand its power, use it wisely,
23+
And watch your finances flourish with ease.
1424
Now explain APR to me like I'm 5 years old
15-
Sure! Imagine you have a piggy bank, and you want to borrow some money from your parents to buy a toy. Your parents will ask you to pay them back with some extra money, which is like interest. APR is the special number that tells you how much extra money you'll have to pay back, all in one year. It's like a special rule that helps you understand how much you'll owe your parents.
25+
Sure! Imagine you want to buy a toy that costs $100. You can either pay the full $100 right away or borrow it and pay back more over time.
26+
27+
APR is like a special number that tells you how much more you'll have to pay in total when you borrow money. It includes not just the extra money you pay for using someone else's cash (that's like interest), but also any other costs, like fees for taking the loan or insurance to protect the lender if you can't pay back.
28+
29+
So, if your APR is 10%, that means you'll have to pay an extra $10 on top of the $100 you're borrowing. That's a total of $110. It's like a little extra for using their money, and it helps everyone understand how much more things cost when we borrow instead of saving up.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Hello
2-
Hello! How can I assist you today?
2+
Greetings! How can I assist you today?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Hello
2+
Hi there! How can I help you today?
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Given the text after "Q:", generate a Python function after "A:".
2+
3+
Here are some examples, complete the last one:
4+
5+
Q: Write a python function to find the first repeated character in a given string.
6+
A: ```def first_repeated_char(str1):
7+
for index,c in enumerate(str1):
8+
if str1[:index+1].count(c) > 1:
9+
return c```
10+
11+
Q: Write a python function to interchange the first and last element in a given list.
12+
A: ```def swap_List(newList):
13+
size = len(newList)
14+
temp = newList[0]
15+
newList[0] = newList[size - 1]
16+
newList[size - 1] = temp
17+
return newList ```
18+
19+
Q: Write a function to find the index of the first occurrence of a given number in a sorted array.
20+
A: ```def find_first_occurrence(A, x):
21+
(left, right) = (0, len(A) - 1)
22+
result = -1
23+
while left <= right:
24+
mid = (left + right) // 2
25+
if x == A[mid]:
26+
result = mid
27+
right = mid - 1
28+
elif x < A[mid]:
29+
right = mid - 1
30+
else:
31+
left = mid + 1
32+
return result```
33+
34+
Q: Write a function to remove tuples from the given tuple.
35+
A: ```def remove_nested(test_tup):
36+
res = tuple()
37+
for count, ele in enumerate(test_tup):
38+
if not isinstance(ele, tuple):
39+
res = res + (ele, )
40+
return (res) ```
41+
42+
Q: Write a function to remove all whitespaces from a string.
43+
A: ```import re
44+
def remove_all_spaces(text):
45+
return (re.sub(r'\s+', '',text))```
46+
47+
Q: Write a python function to remove first and last occurrence of a given character from the string.
48+
A:Here is the Python function to remove the first and last occurrence of a given character from a string:
49+
50+
```python
51+
def remove_char_at_edges(s, char):
52+
# Remove first occurrence
53+
if s.startswith(char):
54+
s = s[s.index(char)+1:]
55+
56+
# Remove last occurrence
57+
if s.endswith(char):
58+
s = s[:len(s) - s[::-1].index(char)]
59+
60+
return s
61+
```
62+
63+
This function uses the `str.startswith` and `str.endswith` methods to check if the string starts or ends with the specified character, respectively. If it does, it removes that character using Python's slice notation. Note that this solution doesn't handle multiple occurrences at the edges of the string; it only removes one occurrence from each edge.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Given the text after "Q:", generate a Python function after "A:".
2+
3+
Here are some examples, complete the last one:
4+
5+
Q: Write a python function to find the first repeated character in a given string.
6+
A: ```def first_repeated_char(str1):
7+
for index,c in enumerate(str1):
8+
if str1[:index+1].count(c) > 1:
9+
return c```
10+
11+
Q: Write a python function to interchange the first and last element in a given list.
12+
A: ```def swap_List(newList):
13+
size = len(newList)
14+
temp = newList[0]
15+
newList[0] = newList[size - 1]
16+
newList[size - 1] = temp
17+
return newList ```
18+
19+
Q: Write a function to find the index of the first occurrence of a given number in a sorted array.
20+
A: ```def find_first_occurrence(A, x):
21+
(left, right) = (0, len(A) - 1)
22+
result = -1
23+
while left <= right:
24+
mid = (left + right) // 2
25+
if x == A[mid]:
26+
result = mid
27+
right = mid - 1
28+
elif x < A[mid]:
29+
right = mid - 1
30+
else:
31+
left = mid + 1
32+
return result```
33+
34+
Q: Write a function to remove tuples from the given tuple.
35+
A: ```def remove_nested(test_tup):
36+
res = tuple()
37+
for count, ele in enumerate(test_tup):
38+
if not isinstance(ele, tuple):
39+
res = res + (ele, )
40+
return (res) ```
41+
42+
Q: Write a function to remove all whitespaces from a string.
43+
A: ```import re
44+
def remove_all_spaces(text):
45+
return (re.sub(r'\s+', '',text))```
46+
47+
Q: Write a python function to remove first and last occurrence of a given character from the string.
48+
A:Here's the Python function that removes the first and last occurrence of a given character from a string:
49+
50+
```python
51+
def remove_first_last(s, char):
52+
new_string = list(s) # convert string to list for mutable operations
53+
stack = []
54+
55+
# Collect characters before the first occurrence of 'char'
56+
while char not in new_string:
57+
if new_string:
58+
stack.append(new_string.pop(0))
59+
60+
# Collect characters after the last occurrence of 'char'
61+
last_occurrence = s.rfind(char)
62+
for i in range(last_occurrence + 1, len(s)):
63+
if s[i] != char:
64+
stack.append(new_string.pop())
65+
66+
return ''.join(stack)
67+
```
68+
69+
This function works by first creating a mutable version of the string (as strings are immutable in Python). It then iterates through the list to collect characters before and after each occurrence of the given character, using a stack to store these characters. Finally, it rebuilds the string from this stack and returns it.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Given the text after "Q:", generate a Python function after "A:".
2+
3+
Here are some examples, complete the last one:
4+
5+
Q: Write a python function to find the first repeated character in a given string.
6+
A: ```def first_repeated_char(str1):
7+
for index,c in enumerate(str1):
8+
if str1[:index+1].count(c) > 1:
9+
return c```
10+
11+
Q: Write a python function to interchange the first and last element in a given list.
12+
A: ```def swap_List(newList):
13+
size = len(newList)
14+
temp = newList[0]
15+
newList[0] = newList[size - 1]
16+
newList[size - 1] = temp
17+
return newList ```
18+
19+
Q: Write a function to find the index of the first occurrence of a given number in a sorted array.
20+
A: ```def find_first_occurrence(A, x):
21+
(left, right) = (0, len(A) - 1)
22+
result = -1
23+
while left <= right:
24+
mid = (left + right) // 2
25+
if x == A[mid]:
26+
result = mid
27+
right = mid - 1
28+
elif x < A[mid]:
29+
right = mid - 1
30+
else:
31+
left = mid + 1
32+
return result```
33+
34+
Q: Write a function to remove tuples from the given tuple.
35+
A: ```def remove_nested(test_tup):
36+
res = tuple()
37+
for count, ele in enumerate(test_tup):
38+
if not isinstance(ele, tuple):
39+
res = res + (ele, )
40+
return (res) ```
41+
42+
Q: Write a function to remove all whitespaces from a string.
43+
A: ```import re
44+
def remove_all_spaces(text):
45+
return (re.sub(r'\s+', '',text))```
46+
47+
Q: Write a python function to remove first and last occurrence of a given character from the string.
48+
A:Here is the Python function to remove the first and last occurrence of a given character from a string:
49+
50+
```python
51+
def remove_char(s, char):
52+
result = []
53+
for c in s:
54+
if c != char or (c == char and (result and result[-1] != char)):
55+
result.append(c)
56+
return ''.join(result)
57+
```
58+
59+
This function iterates over each character in the string `s`. If the character is not equal to `char` or it's equal but not the first/last occurrence (checked by `result and result[-1] != char`), it appends the character to the `result` list. Finally, it joins all characters in the list into a single string and returns it.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bob's number is 1
2+
Carol's number is 2
3+
David's number is 3
4+
Ernest's number is 4
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'Bob': 1, 'Carol': 2, 'David': 3, 'Ernest': 4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bye!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
['1', '2', '3', '4']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "Hello"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "Hi there"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bob's number is 1
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123

0 commit comments

Comments
 (0)