|
1 | 1 | package loader
|
2 | 2 |
|
3 |
| -import "testing" |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "testing" |
4 | 7 |
|
5 |
| -func TestLoader(*testing.T) { |
| 8 | + "github.com/hexops/autogold/v2" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +func toString(obj any) string { |
| 13 | + s, err := json.MarshalIndent(obj, "", " ") |
| 14 | + if err != nil { |
| 15 | + panic(err) |
| 16 | + } |
| 17 | + return string(s) |
| 18 | +} |
| 19 | + |
| 20 | +func TestHelloWorld(t *testing.T) { |
| 21 | + prg, err := Program(context.Background(), |
| 22 | + "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt", |
| 23 | + "") |
| 24 | + require.NoError(t, err) |
| 25 | + autogold.Expect(`{ |
| 26 | + "name": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt", |
| 27 | + "entryToolId": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1", |
| 28 | + "toolSet": { |
| 29 | + "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1": { |
| 30 | + "modelName": "gpt-4-turbo-preview", |
| 31 | + "internalPrompt": null, |
| 32 | + "instructions": "Say hello world", |
| 33 | + "id": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1", |
| 34 | + "localTools": { |
| 35 | + "": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1" |
| 36 | + }, |
| 37 | + "source": { |
| 38 | + "location": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt", |
| 39 | + "lineNo": 1 |
| 40 | + }, |
| 41 | + "workingDir": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example" |
| 42 | + }, |
| 43 | + "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1": { |
| 44 | + "modelName": "gpt-4-turbo-preview", |
| 45 | + "internalPrompt": null, |
| 46 | + "tools": [ |
| 47 | + "../bob.gpt" |
| 48 | + ], |
| 49 | + "instructions": "call bob", |
| 50 | + "id": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1", |
| 51 | + "toolMapping": { |
| 52 | + "../bob.gpt": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:1" |
| 53 | + }, |
| 54 | + "localTools": { |
| 55 | + "": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:1" |
| 56 | + }, |
| 57 | + "source": { |
| 58 | + "location": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt", |
| 59 | + "lineNo": 1 |
| 60 | + }, |
| 61 | + "workingDir": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub" |
| 62 | + } |
| 63 | + } |
| 64 | +}`).Equal(t, toString(prg)) |
| 65 | + |
| 66 | + prg, err = Program(context.Background(), "https://get.gptscript.ai/echo.gpt", "") |
| 67 | + require.NoError(t, err) |
| 68 | + |
| 69 | + autogold.Expect(`{ |
| 70 | + "name": "https://get.gptscript.ai/echo.gpt", |
| 71 | + "entryToolId": "https://get.gptscript.ai/echo.gpt:1", |
| 72 | + "toolSet": { |
| 73 | + "https://get.gptscript.ai/echo.gpt:1": { |
| 74 | + "description": "Returns back the input of the script", |
| 75 | + "modelName": "gpt-4-turbo-preview", |
| 76 | + "internalPrompt": null, |
| 77 | + "arguments": { |
| 78 | + "type": "object", |
| 79 | + "properties": { |
| 80 | + "input": { |
| 81 | + "description": " Any string", |
| 82 | + "type": "string" |
| 83 | + } |
| 84 | + } |
| 85 | + }, |
| 86 | + "instructions": "echo \"${input}\"", |
| 87 | + "id": "https://get.gptscript.ai/echo.gpt:1", |
| 88 | + "localTools": { |
| 89 | + "": "https://get.gptscript.ai/echo.gpt:1" |
| 90 | + }, |
| 91 | + "source": { |
| 92 | + "location": "https://get.gptscript.ai/echo.gpt", |
| 93 | + "lineNo": 1 |
| 94 | + }, |
| 95 | + "workingDir": "https://get.gptscript.ai/" |
| 96 | + } |
| 97 | + } |
| 98 | +}`).Equal(t, toString(prg)) |
6 | 99 | }
|
0 commit comments