Skip to content

Commit

Permalink
chore: support params on input filters besides just input
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Sep 26, 2024
1 parent f922de1 commit 618d5d6
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/runner/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ func (r *Runner) handleInput(callCtx engine.Context, monitor Monitor, env []stri
}

for _, inputToolRef := range inputToolRefs {
inputData, err := json.Marshal(map[string]any{
"input": input,
})
data := map[string]any{}
_ = json.Unmarshal([]byte(input), &data)
data["input"] = input
inputData, err := json.Marshal(data)
if err != nil {
return "", fmt.Errorf("failed to marshal input: %w", err)
}

res, err := r.subCall(callCtx.Ctx, callCtx, monitor, env, inputToolRef.ToolID, string(inputData), "", engine.InputToolCategory)
if err != nil {
return "", err
Expand Down
24 changes: 24 additions & 0 deletions pkg/tests/runner2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,27 @@ Yo dawg`, "")
resp, err := r.Chat(context.Background(), nil, prg, nil, "input 1")
r.AssertStep(t, resp, err)
}

func TestInputFilterMoreArgs(t *testing.T) {
r := tester.NewRunner(t)
prg, err := loader.ProgramFromSource(context.Background(), `
chat: true
inputfilters: stuff
Say hi
---
name: stuff
params: foo: bar
params: input: baz
#!/bin/bash
echo ${FOO}:${INPUT}
`, "")
require.NoError(t, err)

resp, err := r.Chat(context.Background(), nil, prg, nil, `{"foo":"123"}`)
r.AssertStep(t, resp, err)
resp, err = r.Chat(context.Background(), nil, prg, nil, `"foo":"123"}`)
r.AssertStep(t, resp, err)
}
9 changes: 9 additions & 0 deletions pkg/tests/testdata/TestInputFilterMoreArgs/call1-resp.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
`{
"role": "assistant",
"content": [
{
"text": "TEST RESULT CALL: 1"
}
],
"usage": {}
}`
25 changes: 25 additions & 0 deletions pkg/tests/testdata/TestInputFilterMoreArgs/call1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
"content": [
{
"text": "Say hi"
}
],
"usage": {}
},
{
"role": "user",
"content": [
{
"text": "123:{\"foo\":\"123\"}\n"
}
],
"usage": {}
}
],
"chat": true
}`
9 changes: 9 additions & 0 deletions pkg/tests/testdata/TestInputFilterMoreArgs/call2-resp.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
`{
"role": "assistant",
"content": [
{
"text": "TEST RESULT CALL: 2"
}
],
"usage": {}
}`
25 changes: 25 additions & 0 deletions pkg/tests/testdata/TestInputFilterMoreArgs/call2.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
"content": [
{
"text": "Say hi"
}
],
"usage": {}
},
{
"role": "user",
"content": [
{
"text": ":\"foo\":\"123\"}\n"
}
],
"usage": {}
}
],
"chat": true
}`
48 changes: 48 additions & 0 deletions pkg/tests/testdata/TestInputFilterMoreArgs/step1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
`{
"done": false,
"content": "TEST RESULT CALL: 1",
"toolID": "inline:",
"state": {
"continuation": {
"state": {
"input": "123:{\"foo\":\"123\"}\n",
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
"content": [
{
"text": "Say hi"
}
],
"usage": {}
},
{
"role": "user",
"content": [
{
"text": "123:{\"foo\":\"123\"}\n"
}
],
"usage": {}
},
{
"role": "assistant",
"content": [
{
"text": "TEST RESULT CALL: 1"
}
],
"usage": {}
}
],
"chat": true
}
},
"result": "TEST RESULT CALL: 1"
},
"continuationToolID": "inline:"
}
}`
48 changes: 48 additions & 0 deletions pkg/tests/testdata/TestInputFilterMoreArgs/step2.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
`{
"done": false,
"content": "TEST RESULT CALL: 2",
"toolID": "inline:",
"state": {
"continuation": {
"state": {
"input": ":\"foo\":\"123\"}\n",
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
"content": [
{
"text": "Say hi"
}
],
"usage": {}
},
{
"role": "user",
"content": [
{
"text": ":\"foo\":\"123\"}\n"
}
],
"usage": {}
},
{
"role": "assistant",
"content": [
{
"text": "TEST RESULT CALL: 2"
}
],
"usage": {}
}
],
"chat": true
}
},
"result": "TEST RESULT CALL: 2"
},
"continuationToolID": "inline:"
}
}`

0 comments on commit 618d5d6

Please sign in to comment.