Skip to content

Commit da30bb0

Browse files
authored
Change expression syntax from {{ }} to ${ } (#87)
* Change expression syntax from `{{ }}` to `${ }` * Make the expression detection more robust * Update tests and examples
1 parent d42f070 commit da30bb0

File tree

110 files changed

+946
-889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+946
-889
lines changed

README.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -191,27 +191,27 @@ defs:
191191
read: ./data.yaml
192192
parser: yaml
193193
text:
194-
- "\n{{ CODE.source_code }}\n"
194+
- "\n${ CODE.source_code }\n"
195195
- model: watsonx/ibm/granite-34b-code-instruct
196196
input:
197197
- |
198198
Here is some info about the location of the function in the repo.
199199
repo:
200-
{{ CODE.repo_info.repo }}
201-
path: {{ CODE.repo_info.path }}
202-
Function_name: {{ CODE.repo_info.function_name }}
200+
${ CODE.repo_info.repo }
201+
path: ${ CODE.repo_info.path }
202+
Function_name: ${ CODE.repo_info.function_name }
203203
204204
205205
Explain the following code:
206206
```
207-
{{ CODE.source_code }}```
207+
${ CODE.source_code }```
208208
```
209209

210210
In this program we first define some variables using the `defs` construct. Here `CODE` is defined to be a new variable, holding the result of the `read` block that follows.
211211
A `read` block can be used to read from a file or stdin. In this case, we read the content of the file `./data.yaml`, parse it as YAML using the `parser` construct, then
212212
assign the result to variable `CODE`.
213213

214-
Next we define a `text`, where the first block is simply a string and writes out the source code. This is done by accessing the variable `CODE`. The syntax `{{ var }}` means accessing the value of a variable in the scope. Since `CODE` contains YAML data, we can also access fields such as `CODE.source_code`.
214+
Next we define a `text`, where the first block is simply a string and writes out the source code. This is done by accessing the variable `CODE`. The syntax `${ var }` means accessing the value of a variable in the scope. Since `CODE` contains YAML data, we can also access fields such as `CODE.source_code`.
215215

216216
The second block calls a granite model on WatsonX via LiteLLM. Here we explicitly provide an `input` field which means that we do not pass the entire text produced so far to the model, but only what is specified in this field. In this case, we specify our template by using the variable `CODE` as shown above.
217217

@@ -248,20 +248,20 @@ defs:
248248
TRUTH:
249249
read: ./ground_truth.txt
250250
text:
251-
- "\n{{ CODE.source_code }}\n"
251+
- "\n${ CODE.source_code }\n"
252252
- model: watsonx/ibm/granite-34b-code-instruct
253253
def: EXPLANATION
254254
input: |
255255
Here is some info about the location of the function in the repo.
256256
repo:
257-
{{ CODE.repo_info.repo }}
258-
path: {{ CODE.repo_info.path }}
259-
Function_name: {{ CODE.repo_info.function_name }}
257+
${ CODE.repo_info.repo }
258+
path: ${ CODE.repo_info.path }
259+
Function_name: ${ CODE.repo_info.function_name }
260260
261261
262262
Explain the following code:
263263
```
264-
{{ CODE.source_code }}```
264+
${ CODE.source_code }```
265265
- |
266266
267267
@@ -272,10 +272,10 @@ text:
272272
code: |
273273
import textdistance
274274
expl = """
275-
{{ EXPLANATION }}
275+
${ EXPLANATION }
276276
"""
277277
truth = """
278-
{{ TRUTH }}
278+
${ TRUTH }
279279
"""
280280
result = textdistance.levenshtein.normalized_similarity(expl, truth)
281281
@@ -328,31 +328,31 @@ text:
328328
|
329329
Here is some info about the location of the function in the repo.
330330
repo:
331-
{{ CODE.repo_info.repo }}
332-
path: {{ CODE.repo_info.path }}
333-
Function_name: {{ CODE.repo_info.function_name }}
331+
${ CODE.repo_info.repo }
332+
path: ${ CODE.repo_info.path }
333+
Function_name: ${ CODE.repo_info.function_name }
334334

335335

336336
Explain the following code:
337337
```
338-
{{ CODE.source_code }}```
338+
${ CODE.source_code }```
339339
- def: EVAL
340340
contribute: []
341341
lan: python
342342
code:
343343
|
344344
import textdistance
345345
expl = """
346-
{{ EXPLANATION }}
346+
${ EXPLANATION }
347347
"""
348348
truth = """
349-
{{ TRUTH }}
349+
${ TRUTH }
350350
"""
351351
result = textdistance.levenshtein.normalized_similarity(expl, truth)
352352
- data:
353-
input: "{{ CODE }}"
354-
output: "{{ EXPLANATION }}"
355-
metric: "{{ EVAL }}"
353+
input: ${ CODE }
354+
output: ${ EXPLANATION }
355+
metric: ${ EVAL }
356356
```
357357
358358
The data block takes various variables and combines their values into a JSON object with fields `input`, `output`, and `metric`. We mute the output of all the other blocks with `contribute` set to `[]`. The `contribute` construct can be used to specify how the result of a block is contributed to the overall result, and the background context.

docs/README.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -196,27 +196,27 @@ defs:
196196
read: ./data.yaml
197197
parser: yaml
198198
text:
199-
- "\n{{ CODE.source_code }}\n"
199+
- "\n${ CODE.source_code }\n"
200200
- model: watsonx/ibm/granite-34b-code-instruct
201201
input:
202202
- |
203203
Here is some info about the location of the function in the repo.
204204
repo:
205-
{{ CODE.repo_info.repo }}
206-
path: {{ CODE.repo_info.path }}
207-
Function_name: {{ CODE.repo_info.function_name }}
205+
${ CODE.repo_info.repo }
206+
path: ${ CODE.repo_info.path }
207+
Function_name: ${ CODE.repo_info.function_name }
208208
209209
210210
Explain the following code:
211211
```
212-
{{ CODE.source_code }}```
212+
${ CODE.source_code }```
213213
```
214214

215215
In this program we first define some variables using the `defs` construct. Here `CODE` is defined to be a new variable, holding the result of the `read` block that follows.
216216
A `read` block can be used to read from a file or stdin. In this case, we read the content of the file `./data.yaml`, parse it as YAML using the `parser` construct, then
217217
assign the result to variable `CODE`.
218218

219-
Next we define a `text`, where the first block is simply a string and writes out the source code. This is done by accessing the variable `CODE`. The syntax `{{ var }}` means accessing the value of a variable in the scope. Since `CODE` contains YAML data, we can also access fields such as `CODE.source_code`.
219+
Next we define a `text`, where the first block is simply a string and writes out the source code. This is done by accessing the variable `CODE`. The syntax `${ var }` means accessing the value of a variable in the scope. Since `CODE` contains YAML data, we can also access fields such as `CODE.source_code`.
220220

221221
The second block calls a granite model on WatsonX via LiteLLM. Here we explicitly provide an `input` field which means that we do not pass the entire text produced so far to the model, but only what is specified in this field. In this case, we specify our template by using the variable `CODE` as shown above.
222222

@@ -253,20 +253,20 @@ defs:
253253
TRUTH:
254254
read: ./ground_truth.txt
255255
text:
256-
- "\n{{ CODE.source_code }}\n"
256+
- "\n${ CODE.source_code }\n"
257257
- model: watsonx/ibm/granite-34b-code-instruct
258258
def: EXPLANATION
259259
input: |
260260
Here is some info about the location of the function in the repo.
261261
repo:
262-
{{ CODE.repo_info.repo }}
263-
path: {{ CODE.repo_info.path }}
264-
Function_name: {{ CODE.repo_info.function_name }}
262+
${ CODE.repo_info.repo }
263+
path: ${ CODE.repo_info.path }
264+
Function_name: ${ CODE.repo_info.function_name }
265265
266266
267267
Explain the following code:
268268
```
269-
{{ CODE.source_code }}```
269+
${ CODE.source_code }```
270270
- |
271271
272272
@@ -277,10 +277,10 @@ text:
277277
code: |
278278
import textdistance
279279
expl = """
280-
{{ EXPLANATION }}
280+
${ EXPLANATION }
281281
"""
282282
truth = """
283-
{{ TRUTH }}
283+
${ TRUTH }
284284
"""
285285
result = textdistance.levenshtein.normalized_similarity(expl, truth)
286286
@@ -333,31 +333,31 @@ text:
333333
|
334334
Here is some info about the location of the function in the repo.
335335
repo:
336-
{{ CODE.repo_info.repo }}
337-
path: {{ CODE.repo_info.path }}
338-
Function_name: {{ CODE.repo_info.function_name }}
336+
${ CODE.repo_info.repo }
337+
path: ${ CODE.repo_info.path }
338+
Function_name: ${ CODE.repo_info.function_name }
339339

340340

341341
Explain the following code:
342342
```
343-
{{ CODE.source_code }}```
343+
${ CODE.source_code }```
344344
- def: EVAL
345345
contribute: []
346346
lan: python
347347
code:
348348
|
349349
import textdistance
350350
expl = """
351-
{{ EXPLANATION }}
351+
${ EXPLANATION }
352352
"""
353353
truth = """
354-
{{ TRUTH }}
354+
${ TRUTH }
355355
"""
356356
result = textdistance.levenshtein.normalized_similarity(expl, truth)
357357
- data:
358-
input: "{{ CODE }}"
359-
output: "{{ EXPLANATION }}"
360-
metric: "{{ EVAL }}"
358+
input: ${ CODE }
359+
output: ${ EXPLANATION }
360+
metric: ${ EVAL }
361361
```
362362
363363
The data block takes various variables and combines their values into a JSON object with fields `input`, `output`, and `metric`. We mute the output of all the other blocks with `contribute` set to `[]`. The `contribute` construct can be used to specify how the result of a block is contributed to the overall result, and the background context.

0 commit comments

Comments
 (0)