Skip to content

Commit 549f5d1

Browse files
chore: change tool id to not have the line number in it
1 parent f297a1a commit 549f5d1

26 files changed

+115
-119
lines changed

pkg/loader/loader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
211211
tool.Source.Repo = base.Repo
212212

213213
// Probably a better way to come up with an ID
214-
tool.ID = tool.Source.String()
214+
tool.ID = tool.Source.Location + ":" + tool.Name
215215

216216
if i == 0 {
217217
mainTool = tool

pkg/loader/loader_test.go

+19-21
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package loader
33
import (
44
"context"
55
"encoding/json"
6-
"strings"
76
"testing"
87

9-
"github.com/gptscript-ai/gptscript/pkg/openai"
108
"github.com/hexops/autogold/v2"
119
"github.com/stretchr/testify/require"
1210
)
@@ -24,37 +22,37 @@ func TestHelloWorld(t *testing.T) {
2422
"https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt",
2523
"")
2624
require.NoError(t, err)
27-
autogold.Expect(strings.ReplaceAll(`{
25+
autogold.Expect(`{
2826
"name": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt",
29-
"entryToolId": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1",
27+
"entryToolId": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:",
3028
"toolSet": {
31-
"https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1": {
32-
"modelName": "MODEL",
29+
"https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:": {
30+
"modelName": "gpt-4o",
3331
"internalPrompt": null,
3432
"instructions": "Say hello world",
35-
"id": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1",
33+
"id": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:",
3634
"localTools": {
37-
"": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1"
35+
"": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:"
3836
},
3937
"source": {
4038
"location": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt",
4139
"lineNo": 1
4240
},
4341
"workingDir": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example"
4442
},
45-
"https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1": {
46-
"modelName": "MODEL",
43+
"https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:": {
44+
"modelName": "gpt-4o",
4745
"internalPrompt": null,
4846
"tools": [
4947
"../bob.gpt"
5048
],
5149
"instructions": "call bob",
52-
"id": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1",
50+
"id": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:",
5351
"toolMapping": {
54-
"../bob.gpt": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1"
52+
"../bob.gpt": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:"
5553
},
5654
"localTools": {
57-
"": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1"
55+
"": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:"
5856
},
5957
"source": {
6058
"location": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt",
@@ -63,18 +61,18 @@ func TestHelloWorld(t *testing.T) {
6361
"workingDir": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub"
6462
}
6563
}
66-
}`, "MODEL", openai.DefaultModel)).Equal(t, toString(prg))
64+
}`).Equal(t, toString(prg))
6765

6866
prg, err = Program(context.Background(), "https://get.gptscript.ai/echo.gpt", "")
6967
require.NoError(t, err)
7068

71-
autogold.Expect(strings.ReplaceAll(`{
69+
autogold.Expect(`{
7270
"name": "https://get.gptscript.ai/echo.gpt",
73-
"entryToolId": "https://get.gptscript.ai/echo.gpt:1",
71+
"entryToolId": "https://get.gptscript.ai/echo.gpt:",
7472
"toolSet": {
75-
"https://get.gptscript.ai/echo.gpt:1": {
73+
"https://get.gptscript.ai/echo.gpt:": {
7674
"description": "Returns back the input of the script",
77-
"modelName": "MODEL",
75+
"modelName": "gpt-4o",
7876
"internalPrompt": null,
7977
"arguments": {
8078
"properties": {
@@ -86,9 +84,9 @@ func TestHelloWorld(t *testing.T) {
8684
"type": "object"
8785
},
8886
"instructions": "echo \"${input}\"",
89-
"id": "https://get.gptscript.ai/echo.gpt:1",
87+
"id": "https://get.gptscript.ai/echo.gpt:",
9088
"localTools": {
91-
"": "https://get.gptscript.ai/echo.gpt:1"
89+
"": "https://get.gptscript.ai/echo.gpt:"
9290
},
9391
"source": {
9492
"location": "https://get.gptscript.ai/echo.gpt",
@@ -97,5 +95,5 @@ func TestHelloWorld(t *testing.T) {
9795
"workingDir": "https://get.gptscript.ai/"
9896
}
9997
}
100-
}`, "MODEL", openai.DefaultModel)).Equal(t, toString(prg))
98+
}`).Equal(t, toString(prg))
10199
}

pkg/tests/runner_test.go

+28-30
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import (
44
"context"
55
"encoding/json"
66
"os"
7-
"strings"
87
"testing"
98

10-
"github.com/gptscript-ai/gptscript/pkg/openai"
119
"github.com/gptscript-ai/gptscript/pkg/tests/tester"
1210
"github.com/gptscript-ai/gptscript/pkg/types"
1311
"github.com/hexops/autogold/v2"
@@ -220,21 +218,21 @@ func TestSubChat(t *testing.T) {
220218
resp, err := r.Chat(context.Background(), nil, prg, os.Environ(), "Hello")
221219
require.NoError(t, err)
222220

223-
autogold.Expect(strings.ReplaceAll(`{
221+
autogold.Expect(`{
224222
"done": false,
225223
"content": "Assistant 1",
226-
"toolID": "testdata/TestSubChat/test.gpt:6",
224+
"toolID": "testdata/TestSubChat/test.gpt:chatbot",
227225
"state": {
228226
"continuation": {
229227
"state": {
230228
"input": "Hello",
231229
"completion": {
232-
"Model": "MODEL",
230+
"Model": "gpt-4o",
233231
"InternalSystemPrompt": null,
234232
"Tools": [
235233
{
236234
"function": {
237-
"toolID": "testdata/TestSubChat/test.gpt:6",
235+
"toolID": "testdata/TestSubChat/test.gpt:chatbot",
238236
"name": "chatbot",
239237
"parameters": null
240238
}
@@ -293,19 +291,19 @@ func TestSubChat(t *testing.T) {
293291
},
294292
"calls": {
295293
"call_1": {
296-
"toolID": "testdata/TestSubChat/test.gpt:6"
294+
"toolID": "testdata/TestSubChat/test.gpt:chatbot"
297295
}
298296
}
299297
},
300298
"subCalls": [
301299
{
302-
"toolId": "testdata/TestSubChat/test.gpt:6",
300+
"toolId": "testdata/TestSubChat/test.gpt:chatbot",
303301
"callId": "call_1",
304302
"state": {
305303
"continuation": {
306304
"state": {
307305
"completion": {
308-
"Model": "MODEL",
306+
"Model": "gpt-4o",
309307
"InternalSystemPrompt": false,
310308
"Tools": null,
311309
"Messages": [
@@ -337,32 +335,32 @@ func TestSubChat(t *testing.T) {
337335
},
338336
"result": "Assistant 1"
339337
},
340-
"continuationToolID": "testdata/TestSubChat/test.gpt:6"
338+
"continuationToolID": "testdata/TestSubChat/test.gpt:chatbot"
341339
}
342340
}
343341
],
344342
"subCallID": "call_1"
345343
}
346-
}`, "MODEL", openai.DefaultModel)).Equal(t, toJSONString(t, resp))
344+
}`).Equal(t, toJSONString(t, resp))
347345

348346
resp, err = r.Chat(context.Background(), resp.State, prg, os.Environ(), "User 1")
349347
require.NoError(t, err)
350348

351-
autogold.Expect(strings.ReplaceAll(`{
349+
autogold.Expect(`{
352350
"done": false,
353351
"content": "Assistant 2",
354-
"toolID": "testdata/TestSubChat/test.gpt:6",
352+
"toolID": "testdata/TestSubChat/test.gpt:chatbot",
355353
"state": {
356354
"continuation": {
357355
"state": {
358356
"input": "Hello",
359357
"completion": {
360-
"Model": "MODEL",
358+
"Model": "gpt-4o",
361359
"InternalSystemPrompt": null,
362360
"Tools": [
363361
{
364362
"function": {
365-
"toolID": "testdata/TestSubChat/test.gpt:6",
363+
"toolID": "testdata/TestSubChat/test.gpt:chatbot",
366364
"name": "chatbot",
367365
"parameters": null
368366
}
@@ -421,19 +419,19 @@ func TestSubChat(t *testing.T) {
421419
},
422420
"calls": {
423421
"call_1": {
424-
"toolID": "testdata/TestSubChat/test.gpt:6"
422+
"toolID": "testdata/TestSubChat/test.gpt:chatbot"
425423
}
426424
}
427425
},
428426
"subCalls": [
429427
{
430-
"toolId": "testdata/TestSubChat/test.gpt:6",
428+
"toolId": "testdata/TestSubChat/test.gpt:chatbot",
431429
"callId": "call_1",
432430
"state": {
433431
"continuation": {
434432
"state": {
435433
"completion": {
436-
"Model": "MODEL",
434+
"Model": "gpt-4o",
437435
"InternalSystemPrompt": false,
438436
"Tools": null,
439437
"Messages": [
@@ -483,13 +481,13 @@ func TestSubChat(t *testing.T) {
483481
},
484482
"result": "Assistant 2"
485483
},
486-
"continuationToolID": "testdata/TestSubChat/test.gpt:6"
484+
"continuationToolID": "testdata/TestSubChat/test.gpt:chatbot"
487485
}
488486
}
489487
],
490488
"subCallID": "call_1"
491489
}
492-
}`, "MODEL", openai.DefaultModel)).Equal(t, toJSONString(t, resp))
490+
}`).Equal(t, toJSONString(t, resp))
493491
}
494492

495493
func TestChat(t *testing.T) {
@@ -506,16 +504,16 @@ func TestChat(t *testing.T) {
506504
resp, err := r.Chat(context.Background(), nil, prg, os.Environ(), "Hello")
507505
require.NoError(t, err)
508506

509-
autogold.Expect(strings.ReplaceAll(`{
507+
autogold.Expect(`{
510508
"done": false,
511509
"content": "Assistant 1",
512-
"toolID": "testdata/TestChat/test.gpt:1",
510+
"toolID": "testdata/TestChat/test.gpt:",
513511
"state": {
514512
"continuation": {
515513
"state": {
516514
"input": "Hello",
517515
"completion": {
518-
"Model": "MODEL",
516+
"Model": "gpt-4o",
519517
"InternalSystemPrompt": false,
520518
"Tools": null,
521519
"Messages": [
@@ -556,23 +554,23 @@ func TestChat(t *testing.T) {
556554
},
557555
"result": "Assistant 1"
558556
},
559-
"continuationToolID": "testdata/TestChat/test.gpt:1"
557+
"continuationToolID": "testdata/TestChat/test.gpt:"
560558
}
561-
}`, "MODEL", openai.DefaultModel)).Equal(t, toJSONString(t, resp))
559+
}`).Equal(t, toJSONString(t, resp))
562560

563561
resp, err = r.Chat(context.Background(), resp.State, prg, os.Environ(), "User 1")
564562
require.NoError(t, err)
565563

566-
autogold.Expect(strings.ReplaceAll(`{
564+
autogold.Expect(`{
567565
"done": false,
568566
"content": "Assistant 2",
569-
"toolID": "testdata/TestChat/test.gpt:1",
567+
"toolID": "testdata/TestChat/test.gpt:",
570568
"state": {
571569
"continuation": {
572570
"state": {
573571
"input": "Hello",
574572
"completion": {
575-
"Model": "MODEL",
573+
"Model": "gpt-4o",
576574
"InternalSystemPrompt": false,
577575
"Tools": null,
578576
"Messages": [
@@ -631,9 +629,9 @@ func TestChat(t *testing.T) {
631629
},
632630
"result": "Assistant 2"
633631
},
634-
"continuationToolID": "testdata/TestChat/test.gpt:1"
632+
"continuationToolID": "testdata/TestChat/test.gpt:"
635633
}
636-
}`, "MODEL", openai.DefaultModel)).Equal(t, toJSONString(t, resp))
634+
}`).Equal(t, toJSONString(t, resp))
637635
}
638636

639637
func TestChatRunNoError(t *testing.T) {

pkg/tests/testdata/TestCase/call1.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Tools": [
55
{
66
"function": {
7-
"toolID": "testdata/TestCase/test.gpt:6",
7+
"toolID": "testdata/TestCase/test.gpt:Bob",
88
"name": "Bob",
99
"description": "I'm Bob, a friendly guy.",
1010
"parameters": {

pkg/tests/testdata/TestCase2/call1.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Tools": [
55
{
66
"function": {
7-
"toolID": "testdata/TestCase2/test.gpt:6",
7+
"toolID": "testdata/TestCase2/test.gpt:bob",
88
"name": "Bob",
99
"description": "I'm Bob, a friendly guy.",
1010
"parameters": {

pkg/tests/testdata/TestContextSubChat/call1.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Tools": [
55
{
66
"function": {
7-
"toolID": "testdata/TestContextSubChat/test.gpt:13",
7+
"toolID": "testdata/TestContextSubChat/test.gpt:chatbot",
88
"name": "chatbot",
99
"parameters": null
1010
}

pkg/tests/testdata/TestContextSubChat/call4.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Tools": [
55
{
66
"function": {
7-
"toolID": "testdata/TestContextSubChat/test.gpt:13",
7+
"toolID": "testdata/TestContextSubChat/test.gpt:chatbot",
88
"name": "chatbot",
99
"parameters": null
1010
}

pkg/tests/testdata/TestContextSubChat/call6.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Tools": [
55
{
66
"function": {
7-
"toolID": "testdata/TestContextSubChat/test.gpt:13",
7+
"toolID": "testdata/TestContextSubChat/test.gpt:chatbot",
88
"name": "chatbot",
99
"parameters": null
1010
}

pkg/tests/testdata/TestContextSubChat/call9.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Tools": [
55
{
66
"function": {
7-
"toolID": "testdata/TestContextSubChat/test.gpt:13",
7+
"toolID": "testdata/TestContextSubChat/test.gpt:chatbot",
88
"name": "chatbot",
99
"parameters": null
1010
}

0 commit comments

Comments
 (0)