Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support params on input filters besides just input #861

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:"
}
}`