Skip to content

Commit 79c4351

Browse files
committed
chore: support sending ToolDefs as JSON in sdkserver
This change allows the removal of the "to string" functions/methods in the SDKs. Signed-off-by: Donnie Adams <[email protected]>
1 parent 49fc1c9 commit 79c4351

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pkg/sdkserver/routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (s *server) listTools(w http.ResponseWriter, r *http.Request) {
8585
} else if reqObject.File != "" {
8686
prg, err = loader.Program(r.Context(), reqObject.File, reqObject.SubTool, loader.Options{Cache: s.client.Cache})
8787
} else {
88-
prg, err = loader.ProgramFromSource(r.Context(), reqObject.ToolDef.String(), reqObject.SubTool, loader.Options{Cache: s.client.Cache})
88+
prg, err = loader.ProgramFromSource(r.Context(), reqObject.ToolDefs.String(), reqObject.SubTool, loader.Options{Cache: s.client.Cache})
8989
}
9090
if err != nil {
9191
writeError(logger, w, http.StatusInternalServerError, fmt.Errorf("failed to load program: %w", err))
@@ -178,7 +178,7 @@ func (s *server) execHandler(w http.ResponseWriter, r *http.Request) {
178178

179179
logger.Debugf("executing tool: %+v", reqObject)
180180
var (
181-
def fmt.Stringer = &reqObject.ToolDef
181+
def fmt.Stringer = &reqObject.ToolDefs
182182
programLoader loaderFunc = loader.ProgramFromSource
183183
)
184184
if reqObject.Content != "" {

pkg/sdkserver/types.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sdkserver
22

33
import (
44
"maps"
5+
"strings"
56
"time"
67

78
"github.com/gptscript-ai/gptscript/pkg/cache"
@@ -25,12 +26,26 @@ const (
2526
Prompt runner.EventType = "prompt"
2627
)
2728

29+
type toolDefs []types.ToolDef
30+
31+
func (t toolDefs) String() string {
32+
s := new(strings.Builder)
33+
for i, tool := range t {
34+
s.WriteString(tool.String())
35+
if i != len(t)-1 {
36+
s.WriteString("\n\n---\n\n")
37+
}
38+
}
39+
40+
return s.String()
41+
}
42+
2843
type toolOrFileRequest struct {
29-
cache.Options `json:",inline"`
30-
types.ToolDef `json:",inline"`
3144
content `json:",inline"`
3245
file `json:",inline"`
46+
cache.Options `json:",inline"`
3347

48+
ToolDefs toolDefs `json:"toolDefs,inline"`
3449
SubTool string `json:"subTool"`
3550
Input string `json:"input"`
3651
ChatState string `json:"chatState"`

0 commit comments

Comments
 (0)