Skip to content

Commit 6e92ee7

Browse files
Merge pull request #637 from ibuildthecloud/main
chore: improve reliability with bad tool names
2 parents 5885bf0 + 5d9dfb4 commit 6e92ee7

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/gptscript-ai/broadcaster v0.0.0-20240625175512-c43682019b86
1818
github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf0379
1919
github.com/gptscript-ai/cmd v0.0.0-20240625175447-4250b42feb7d
20-
github.com/gptscript-ai/tui v0.0.0-20240702222655-901e7ec1faf5
20+
github.com/gptscript-ai/tui v0.0.0-20240716053605-ecddbcf60eac
2121
github.com/hexops/autogold/v2 v2.2.1
2222
github.com/hexops/valast v1.4.4
2323
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
@@ -63,7 +63,7 @@ require (
6363
github.com/google/go-cmp v0.6.0 // indirect
6464
github.com/gookit/color v1.5.4 // indirect
6565
github.com/gorilla/css v1.0.0 // indirect
66-
github.com/gptscript-ai/go-gptscript v0.9.1 // indirect
66+
github.com/gptscript-ai/go-gptscript v0.9.3-0.20240715172623-8176fb20c5cb // indirect
6767
github.com/hashicorp/errwrap v1.0.0 // indirect
6868
github.com/hashicorp/go-multierror v1.1.1 // indirect
6969
github.com/hexops/autogold v1.3.1 // indirect

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf037
171171
github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf0379/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo=
172172
github.com/gptscript-ai/cmd v0.0.0-20240625175447-4250b42feb7d h1:sKf7T7twhGXs6AVbvD9pKDVewykkwSAPwEpmIEQIR/4=
173173
github.com/gptscript-ai/cmd v0.0.0-20240625175447-4250b42feb7d/go.mod h1:DJAo1xTht1LDkNYFNydVjTHd576TC7MlpsVRl3oloVw=
174-
github.com/gptscript-ai/go-gptscript v0.9.1 h1:O9oSmYvzQ2GZkPfDhXpiMGdtO9BMCVGeWLdJH88AJzg=
175-
github.com/gptscript-ai/go-gptscript v0.9.1/go.mod h1:Dh6vYRAiVcyC3ElZIGzTvNF1FxtYwA07BHfSiFKQY7s=
176-
github.com/gptscript-ai/tui v0.0.0-20240702222655-901e7ec1faf5 h1:qCNJVFDHT2p0cuLo920DmUQoUngAuXGgqldYNwmC/R0=
177-
github.com/gptscript-ai/tui v0.0.0-20240702222655-901e7ec1faf5/go.mod h1:mYzM8AwIiAdImy2g0BsdTPPuSbsONTMw5GIHDc/2o7g=
174+
github.com/gptscript-ai/go-gptscript v0.9.3-0.20240715172623-8176fb20c5cb h1:xeSbO4mLYnoTg7diNW0tpxY/0yDSSdgjohMzwE4Za6k=
175+
github.com/gptscript-ai/go-gptscript v0.9.3-0.20240715172623-8176fb20c5cb/go.mod h1:Dh6vYRAiVcyC3ElZIGzTvNF1FxtYwA07BHfSiFKQY7s=
176+
github.com/gptscript-ai/tui v0.0.0-20240716053605-ecddbcf60eac h1:zZ993dp2mx/63JD4THwMeBcn3C8SogcLeQRJUZsMSM4=
177+
github.com/gptscript-ai/tui v0.0.0-20240716053605-ecddbcf60eac/go.mod h1:Ex2xQMzTMfb5UgLz9rctATPps8DnfPeJQh8o/AiQCoE=
178178
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
179179
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
180180
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=

pkg/engine/engine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func (e *Engine) complete(ctx context.Context, state *State) (*Return, error) {
389389
if content.ToolCall != nil {
390390
var toolID string
391391
for _, tool := range state.Completion.Tools {
392-
if tool.Function.Name == content.ToolCall.Function.Name {
392+
if strings.EqualFold(tool.Function.Name, content.ToolCall.Function.Name) {
393393
toolID = tool.Function.ToolID
394394
}
395395
}

pkg/openai/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ func appendMessage(msg types.CompletionMessage, response openai.ChatCompletionSt
450450
if tc.ToolCall.Function.Name != tool.Function.Name {
451451
tc.ToolCall.Function.Name += tool.Function.Name
452452
}
453-
// OpenAI like to sometimes add this prefix for no good reason
453+
// OpenAI like to sometimes add these prefix because it's confused
454454
tc.ToolCall.Function.Name = strings.TrimPrefix(tc.ToolCall.Function.Name, "namespace.")
455+
tc.ToolCall.Function.Name = strings.TrimPrefix(tc.ToolCall.Function.Name, "@")
455456
tc.ToolCall.Function.Arguments += tool.Function.Arguments
456457

457458
msg.Content[idx] = tc

0 commit comments

Comments
 (0)