Skip to content

Commit 912d1b4

Browse files
Don't set default prompt param anymore
1 parent 853c4c7 commit 912d1b4

File tree

5 files changed

+47
-44
lines changed

5 files changed

+47
-44
lines changed

pkg/builtin/builtin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/jaytaylor/html2text"
1818
)
1919

20-
var Tools = map[string]types.Tool{
20+
var tools = map[string]types.Tool{
2121
"sys.read": {
2222
Description: "Reads the contents of a file",
2323
Arguments: types.ObjectSchema(
@@ -94,7 +94,7 @@ func SysProgram() *types.Program {
9494

9595
func ListTools() (result []types.Tool) {
9696
var keys []string
97-
for k := range Tools {
97+
for k := range tools {
9898
keys = append(keys, k)
9999
}
100100

@@ -109,7 +109,7 @@ func ListTools() (result []types.Tool) {
109109

110110
func Builtin(name string) (types.Tool, bool) {
111111
name, dontFail := strings.CutSuffix(name, "?")
112-
t, ok := Tools[name]
112+
t, ok := tools[name]
113113
t.Name = name
114114
t.ID = name
115115
t.Instructions = "#!" + name
@@ -123,7 +123,7 @@ func Builtin(name string) (types.Tool, bool) {
123123
return s, err
124124
}
125125
}
126-
return t, ok
126+
return SetDefaults(t), ok
127127
}
128128

129129
func SysFind(ctx context.Context, env []string, input string) (string, error) {

pkg/builtin/defaults.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package builtin
2+
3+
import (
4+
"github.com/gptscript-ai/gptscript/pkg/openai"
5+
"github.com/gptscript-ai/gptscript/pkg/types"
6+
)
7+
8+
var (
9+
DefaultModel = openai.DefaultModel
10+
DefaultVisionModel = openai.DefaultVisionModel
11+
)
12+
13+
func SetDefaults(tool types.Tool) types.Tool {
14+
if tool.ModelName == "" {
15+
if tool.Vision {
16+
tool.ModelName = DefaultVisionModel
17+
} else {
18+
tool.ModelName = DefaultModel
19+
}
20+
}
21+
return tool
22+
}

pkg/engine/engine.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ You do not need to explain the steps taken, only provide the result to the given
2323
You are referred to as a tool.
2424
`
2525

26+
var DefaultToolSchema = types.JSONSchema{
27+
Property: types.Property{
28+
Type: "object",
29+
},
30+
Properties: map[string]types.Property{
31+
openai.DefaultPromptParameter: {
32+
Description: "Prompt to send to the tool or assistant. This may be instructions or question.",
33+
Type: "string",
34+
},
35+
},
36+
Required: []string{openai.DefaultPromptParameter},
37+
}
38+
2639
var completionID int64
2740

2841
func init() {
@@ -185,12 +198,16 @@ func (e *Engine) Start(ctx Context, input string) (*Return, error) {
185198
if err != nil {
186199
return nil, err
187200
}
201+
args := subTool.Arguments
202+
if args == nil && !subTool.IsCommand() {
203+
args = &DefaultToolSchema
204+
}
188205
completion.Tools = append(completion.Tools, types.CompletionTool{
189206
Type: types.CompletionToolTypeFunction,
190207
Function: types.CompletionFunctionDefinition{
191208
Name: subToolName,
192209
Description: subTool.Description,
193-
Parameters: subTool.Arguments,
210+
Parameters: args,
194211
},
195212
})
196213
}

pkg/loader/defaults.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

pkg/loader/loader.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ func loadProgram(data []byte, into *types.Program) (types.Tool, error) {
154154
for tk, tv := range v.ToolMapping {
155155
v.ToolMapping[tk] = tv + id
156156
}
157-
into.ToolSet[k+id] = v
157+
v.ID = k + id
158+
into.ToolSet[v.ID] = v
158159
}
159160

160161
return into.ToolSet[ext.EntryToolID+id], nil
@@ -314,7 +315,7 @@ func link(ctx context.Context, prg *types.Program, base *Source, tool types.Tool
314315
tool.Tools[i] = newToolName
315316
}
316317

317-
tool = SetDefaults(tool)
318+
tool = builtin.SetDefaults(tool)
318319
prg.ToolSet[tool.ID] = tool
319320

320321
return tool, nil

0 commit comments

Comments
 (0)