diff --git a/pkg/gptscript/gptscript.go b/pkg/gptscript/gptscript.go index d25915b1..462ee8b5 100644 --- a/pkg/gptscript/gptscript.go +++ b/pkg/gptscript/gptscript.go @@ -51,7 +51,7 @@ type Options struct { Env []string } -func complete(opts ...Options) Options { +func Complete(opts ...Options) Options { var result Options for _, opt := range opts { result.Cache = cache.Complete(result.Cache, opt.Cache) @@ -80,7 +80,7 @@ func complete(opts ...Options) Options { } func New(ctx context.Context, o ...Options) (*GPTScript, error) { - opts := complete(o...) + opts := Complete(o...) registry := llm.NewRegistry() cacheClient, err := cache.New(opts.Cache) diff --git a/pkg/sdkserver/server.go b/pkg/sdkserver/server.go index d0ca5a5f..2318bb67 100644 --- a/pkg/sdkserver/server.go +++ b/pkg/sdkserver/server.go @@ -56,6 +56,8 @@ func Run(ctx context.Context, opts Options) error { // EmbeddedStart allows running the server as an embedded process that may use Stdin for input. // It returns the address the server is listening on. func EmbeddedStart(ctx context.Context, opts Options) (string, error) { + opts = complete(opts) + listener, err := newListener(opts) if err != nil { return "", err @@ -138,3 +140,19 @@ func run(ctx context.Context, listener net.Listener, opts Options) error { <-done return nil } + +func complete(opts ...Options) Options { + var result Options + + for _, opt := range opts { + result.Options = gptscript.Complete(result.Options, opt.Options) + result.ListenAddress = types.FirstSet(opt.ListenAddress, result.ListenAddress) + result.Debug = types.FirstSet(opt.Debug, result.Debug) + } + + if result.ListenAddress == "" { + result.ListenAddress = "127.0.0.1:0" + } + + return result +}