Skip to content

Commit 618d5d6

Browse files
chore: support params on input filters besides just input
1 parent f922de1 commit 618d5d6

File tree

8 files changed

+193
-3
lines changed

8 files changed

+193
-3
lines changed

pkg/runner/input.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ func (r *Runner) handleInput(callCtx engine.Context, monitor Monitor, env []stri
1515
}
1616

1717
for _, inputToolRef := range inputToolRefs {
18-
inputData, err := json.Marshal(map[string]any{
19-
"input": input,
20-
})
18+
data := map[string]any{}
19+
_ = json.Unmarshal([]byte(input), &data)
20+
data["input"] = input
21+
inputData, err := json.Marshal(data)
2122
if err != nil {
2223
return "", fmt.Errorf("failed to marshal input: %w", err)
2324
}
25+
2426
res, err := r.subCall(callCtx.Ctx, callCtx, monitor, env, inputToolRef.ToolID, string(inputData), "", engine.InputToolCategory)
2527
if err != nil {
2628
return "", err

pkg/tests/runner2_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,27 @@ Yo dawg`, "")
5555
resp, err := r.Chat(context.Background(), nil, prg, nil, "input 1")
5656
r.AssertStep(t, resp, err)
5757
}
58+
59+
func TestInputFilterMoreArgs(t *testing.T) {
60+
r := tester.NewRunner(t)
61+
prg, err := loader.ProgramFromSource(context.Background(), `
62+
chat: true
63+
inputfilters: stuff
64+
65+
Say hi
66+
67+
---
68+
name: stuff
69+
params: foo: bar
70+
params: input: baz
71+
72+
#!/bin/bash
73+
echo ${FOO}:${INPUT}
74+
`, "")
75+
require.NoError(t, err)
76+
77+
resp, err := r.Chat(context.Background(), nil, prg, nil, `{"foo":"123"}`)
78+
r.AssertStep(t, resp, err)
79+
resp, err = r.Chat(context.Background(), nil, prg, nil, `"foo":"123"}`)
80+
r.AssertStep(t, resp, err)
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"text": "TEST RESULT CALL: 1"
6+
}
7+
],
8+
"usage": {}
9+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"messages": [
5+
{
6+
"role": "system",
7+
"content": [
8+
{
9+
"text": "Say hi"
10+
}
11+
],
12+
"usage": {}
13+
},
14+
{
15+
"role": "user",
16+
"content": [
17+
{
18+
"text": "123:{\"foo\":\"123\"}\n"
19+
}
20+
],
21+
"usage": {}
22+
}
23+
],
24+
"chat": true
25+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"text": "TEST RESULT CALL: 2"
6+
}
7+
],
8+
"usage": {}
9+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"messages": [
5+
{
6+
"role": "system",
7+
"content": [
8+
{
9+
"text": "Say hi"
10+
}
11+
],
12+
"usage": {}
13+
},
14+
{
15+
"role": "user",
16+
"content": [
17+
{
18+
"text": ":\"foo\":\"123\"}\n"
19+
}
20+
],
21+
"usage": {}
22+
}
23+
],
24+
"chat": true
25+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
`{
2+
"done": false,
3+
"content": "TEST RESULT CALL: 1",
4+
"toolID": "inline:",
5+
"state": {
6+
"continuation": {
7+
"state": {
8+
"input": "123:{\"foo\":\"123\"}\n",
9+
"completion": {
10+
"model": "gpt-4o",
11+
"internalSystemPrompt": false,
12+
"messages": [
13+
{
14+
"role": "system",
15+
"content": [
16+
{
17+
"text": "Say hi"
18+
}
19+
],
20+
"usage": {}
21+
},
22+
{
23+
"role": "user",
24+
"content": [
25+
{
26+
"text": "123:{\"foo\":\"123\"}\n"
27+
}
28+
],
29+
"usage": {}
30+
},
31+
{
32+
"role": "assistant",
33+
"content": [
34+
{
35+
"text": "TEST RESULT CALL: 1"
36+
}
37+
],
38+
"usage": {}
39+
}
40+
],
41+
"chat": true
42+
}
43+
},
44+
"result": "TEST RESULT CALL: 1"
45+
},
46+
"continuationToolID": "inline:"
47+
}
48+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
`{
2+
"done": false,
3+
"content": "TEST RESULT CALL: 2",
4+
"toolID": "inline:",
5+
"state": {
6+
"continuation": {
7+
"state": {
8+
"input": ":\"foo\":\"123\"}\n",
9+
"completion": {
10+
"model": "gpt-4o",
11+
"internalSystemPrompt": false,
12+
"messages": [
13+
{
14+
"role": "system",
15+
"content": [
16+
{
17+
"text": "Say hi"
18+
}
19+
],
20+
"usage": {}
21+
},
22+
{
23+
"role": "user",
24+
"content": [
25+
{
26+
"text": ":\"foo\":\"123\"}\n"
27+
}
28+
],
29+
"usage": {}
30+
},
31+
{
32+
"role": "assistant",
33+
"content": [
34+
{
35+
"text": "TEST RESULT CALL: 2"
36+
}
37+
],
38+
"usage": {}
39+
}
40+
],
41+
"chat": true
42+
}
43+
},
44+
"result": "TEST RESULT CALL: 2"
45+
},
46+
"continuationToolID": "inline:"
47+
}
48+
}`

0 commit comments

Comments
 (0)