Skip to content

Commit 60f15a7

Browse files
authored
bug fix for LLM function calling (#178)
* bug fix for LLM function calling Signed-off-by: Mandana Vaziri <[email protected]>
1 parent a61c3af commit 60f15a7

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

src/pdl/pdl_llms.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ def generate_text(
162162
)
163163
msg = response.choices[0].message # pyright: ignore
164164
if msg.content is None:
165-
assert False, "TODO" # XXX TODO XXX
165+
return {
166+
"role": msg.role,
167+
"content": "",
168+
}, response.json() # pyright: ignore
166169
return {
167170
"role": msg.role,
168171
"content": msg.content,
@@ -190,6 +193,6 @@ def generate_text_stream(
190193
result.append(chunk.json()) # pyright: ignore
191194
msg = chunk.choices[0].delta # pyright: ignore
192195
if msg.content is None:
193-
break
196+
continue
194197
yield {"role": msg.role, "content": msg.content}
195198
return result

tests/data/line/hello16.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ text:
2020
- 'Question: Write a JSON object with 2 fields "bob" and "carol" set to "20" and "30" respectively.'
2121
parser: yaml
2222
parameters:
23-
decoding_method: greedy
23+
temperature: 0
2424
stop:
2525
- '}'
2626
include_stop_sequence: true

tests/data/line/hello3.pdl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
description: Hello world to call into a model
22
defs:
3-
model: watsonx/ibm/granite-34b-code-instruct
3+
model: watsonx/ibm/granite-20b-code-instruct
44
text:
55
- Hello,
66
- model: ${ model }
77
spec: int
88
parameters:
9-
decoding_method: greedy
9+
temperature: 0
1010
stop:
1111
- '!'
12-
include_stop_sequence: true
1312
mock_response: " World!"

tests/results/examples/react/demo.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Act: {"name": "Search", "arguments": {"topic": "Henry Hudson"}}
3535
Obs: Henry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States.
3636
In 1607 and 1608, Hudson made two attempts on behalf of English merchants to find a rumoured Northeast Passage to Cathay via a route above the Arctic Circle. In 1609, he landed in North America on behalf of the Dutch East India Company and explored the region around the modern New York metropolitan area. Looking for a Northwest Passage to Asia on his ship Halve Maen ("Half Moon"), he sailed up the Hudson River, which was later named after him, and thereby laid the foundation for Dutch colonization of the region. His contributions to the exploration of the New World were significant and lasting. His voyages helped to establish European contact with the native peoples of North America and contributed to the development of trade and commerce.
3737
On his final expedition, while still searching for the Northwest Passage, Hudson became the first European to see Hudson Strait and the immense Hudson Bay. In 1611, after wintering on the shore of James Bay, Hudson wanted to press on to the west, but most of his crew mutinied. The mutineers cast Hudson, his son, and six others adrift; what then happened to the Hudsons and their companions is unknown.
38+
39+
3840
Tho: Henry Hudson was born around 1565. To find out how many years ago that was, I need to subtract his birth year from the current year, which is 2024.
3941
Act: {"name": "Calc", "arguments": {"expr": "2024 - 1565"}}
4042
Obs: 459

tests/test_model.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
"text": [
77
"Hello,",
88
{
9-
"model": "watsonx/ibm/granite-34b-code-instruct",
9+
"model": "watsonx/meta-llama/llama-3-8b-instruct",
1010
"parameters": {
11-
"decoding_method": "greedy",
12-
"stop_sequences": ["!"],
13-
"include_stop_sequence": False,
11+
"temperature": 0,
12+
"stop": ["!"],
1413
"mock_response": " World",
1514
},
1615
},
@@ -34,9 +33,9 @@ def test_model():
3433
"def": "SOMEONE",
3534
"text": [
3635
{
37-
"model": "watsonx/ibm/granite-34b-code-instruct",
36+
"model": "watsonx/meta-llama/llama-3-8b-instruct",
3837
"parameters": {
39-
"decoding_method": "greedy",
38+
"temperature": 0,
4039
"stop": ["!"],
4140
"include_stop_sequence": False,
4241
"mock_response": " World",
@@ -54,8 +53,8 @@ def test_model():
5453
{
5554
"model": "watsonx/google/flan-t5-xl",
5655
"parameters": {
57-
"decoding_method": "greedy",
58-
"stop_sequences": ["."],
56+
"temperature": 0,
57+
"stop": ["."],
5958
"include_stop_sequence": True,
6059
"roles": {"user": {"pre_message": "", "post_message": ""}},
6160
"mock_response": 'World is a fictional character in the popular science fiction television series "The X-Files',
@@ -85,7 +84,7 @@ def test_model_chain():
8584
"def": "LOCATION",
8685
"text": [
8786
{
88-
"model": "watsonx/ibm/granite-34b-code-instruct",
87+
"model": "watsonx/meta-llama/llama-3-8b-instruct",
8988
"input": {
9089
"text": [
9190
"Question: What is the weather in London?\n",
@@ -98,8 +97,8 @@ def test_model_chain():
9897
]
9998
},
10099
"parameters": {
101-
"decoding_method": "greedy",
102-
"stop_sequences": ["Question"],
100+
"temperature": 0,
101+
"stop": ["Question"],
103102
"include_stop_sequence": False,
104103
"mock_response": "Armonk",
105104
},
@@ -122,9 +121,9 @@ def test_multi_shot():
122121
"text": [
123122
"Hello,\n",
124123
{
125-
"model": "watsonx/ibm/granite-34b-code-instruct",
124+
"model": "watsonx/meta-llama/llama-3-8b-instruct",
126125
"parameters": {
127-
"stop_sequences": ["."],
126+
"stop": ["."],
128127
"mock_response": '\nI have a question about the use of the word "in" in the sentence: "The cake was baked in the oven.',
129128
},
130129
},
@@ -144,12 +143,12 @@ def test_data_missing_parameters():
144143

145144
model_parameter = {
146145
"description": "Hello world with a variable",
147-
"defs": {"model": "watsonx/ibm/granite-34b-code-instruct"},
146+
"defs": {"model": "watsonx/meta-llama/llama-3-8b-instruct"},
148147
"text": [
149148
"Hello,",
150149
{
151150
"model": "${ model }",
152-
"parameters": {"stop_sequences": ["!"], "mock_response": " World!"},
151+
"parameters": {"stop": ["!"], "mock_response": " World!"},
153152
},
154153
],
155154
}
@@ -164,12 +163,12 @@ def test_model_parameter():
164163

165164
model_parameter1 = {
166165
"description": "Hello world with a variable",
167-
"defs": {"model": "granite-34b-code-instruct"},
166+
"defs": {"model": "watsonx/meta-llama/llama-3-8b-instruct"},
168167
"text": [
169168
"Hello,",
170169
{
171170
"model": "watsonx/ibm/${ model }",
172-
"parameters": {"stop_sequences": ["!"], "mock_response": " World!"},
171+
"parameters": {"stop": ["!"], "mock_response": " World!"},
173172
},
174173
],
175174
}
@@ -187,7 +186,7 @@ def test_model_parameter1():
187186
"text": [
188187
"Hello,",
189188
{
190-
"model": "watsonx/ibm/granite-34b-code-instruct-v2",
189+
"model": "watsonx/meta-llama/llama-3-8b-instruct",
191190
"platform": "litellm",
192191
"parameters": {"stop": ["!"], "mock_response": " World!"},
193192
},

tests/test_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
},
2626
"parser": "json",
2727
"parameters": {
28-
"stop_sequences": ["}"],
29-
"include_stop_sequence": True,
28+
"stop": ["}"],
3029
"mock_response": '{"bob": 20, "carol": 30}',
3130
},
3231
}

tests/test_var.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
{
1919
"model": "watsonx/ibm/granite-34b-code-instruct",
2020
"parameters": {
21-
"decoding_method": "greedy",
22-
"stop_sequences": ["!"],
23-
"include_stop_sequence": False,
21+
"temperature": 0,
22+
"stop": ["!"],
2423
"mock_response": " World",
2524
},
2625
}
@@ -51,9 +50,8 @@ def test_var():
5150
{
5251
"model": "watsonx/ibm/granite-34b-code-instruct",
5352
"parameters": {
54-
"decoding_method": "greedy",
55-
"stop_sequences": ["!"],
56-
"include_stop_sequence": False,
53+
"temperature": 0,
54+
"stop": ["!"],
5755
"mock_response": " World",
5856
},
5957
}

0 commit comments

Comments
 (0)