Skip to content

bug: respect "share context" from referenced tools #827

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

Merged
merged 1 commit into from
Aug 27, 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
23 changes: 23 additions & 0 deletions pkg/tests/runner2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,26 @@ echo This is the input: ${GPTSCRIPT_INPUT}
resp, err = r.Chat(context.Background(), resp.State, prg, nil, "input 2")
r.AssertStep(t, resp, err)
}

func TestContextShareBug(t *testing.T) {
r := tester.NewRunner(t)
prg, err := loader.ProgramFromSource(context.Background(), `
chat: true
tools: sharecontext

Say hi

---
name: sharecontext
share context: realcontext
---
name: realcontext

#!sys.echo

Yo dawg`, "")
require.NoError(t, err)

resp, err := r.Chat(context.Background(), nil, prg, nil, "input 1")
r.AssertStep(t, resp, err)
}
9 changes: 9 additions & 0 deletions pkg/tests/testdata/TestContextShareBug/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/TestContextShareBug/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": "\nYo dawg\nSay hi"
}
],
"usage": {}
},
{
"role": "user",
"content": [
{
"text": "input 1"
}
],
"usage": {}
}
],
"chat": true
}`
48 changes: 48 additions & 0 deletions pkg/tests/testdata/TestContextShareBug/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": "input 1",
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
"content": [
{
"text": "\nYo dawg\nSay hi"
}
],
"usage": {}
},
{
"role": "user",
"content": [
{
"text": "input 1"
}
],
"usage": {}
},
{
"role": "assistant",
"content": [
{
"text": "TEST RESULT CALL: 1"
}
],
"usage": {}
}
],
"chat": true
}
},
"result": "TEST RESULT CALL: 1"
},
"continuationToolID": "inline:"
}
}`
9 changes: 9 additions & 0 deletions pkg/types/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,15 @@ func (t Tool) GetContextTools(prg Program) ([]ToolReference, error) {
result.Add(contextRef)
}

exportOnlyTools, err := t.getCompletionToolRefs(prg, nil, ToolTypeDefault, ToolTypeContext)
if err != nil {
return nil, err
}

for _, contextRef := range exportOnlyTools {
result.AddAll(prg.ToolSet[contextRef.ToolID].getExportedContext(prg))
}

return result.List()
}

Expand Down