Skip to content

fix: use default config in embedded SDK server #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}