Skip to content

Commit

Permalink
fix: use default config in embedded SDK server
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <donnie@acorn.io>
  • Loading branch information
thedadams committed Jul 22, 2024
1 parent f3194f7 commit 13c31fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/gptscript/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion pkg/sdkserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ 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) {
func EmbeddedStart(ctx context.Context, options ...Options) (string, error) {
opts := complete(options...)

listener, err := newListener(opts)
if err != nil {
return "", err
Expand Down Expand Up @@ -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
}

0 comments on commit 13c31fd

Please sign in to comment.