Skip to content
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
8 changes: 7 additions & 1 deletion pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type source struct {
Repo *types.Repo
}

func (s source) WithRemote(remote bool) *source {
s.Remote = remote
return &s
}

func (s *source) String() string {
if s.Path == "" && s.Name == "" {
return ""
Expand Down Expand Up @@ -436,7 +441,8 @@ func resolve(ctx context.Context, cache *cache.Client, prg *types.Program, base

func input(ctx context.Context, cache *cache.Client, base *source, name string) (*source, error) {
if strings.HasPrefix(name, "http://") || strings.HasPrefix(name, "https://") {
base.Remote = true
// copy and modify
base = base.WithRemote(true)
}

if !base.Remote {
Expand Down
32 changes: 32 additions & 0 deletions pkg/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package loader
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"

"github.com/gptscript-ai/gptscript/pkg/types"
Expand All @@ -19,6 +23,34 @@ func toString(obj any) string {
return string(s)
}

func TestLocalRemote(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer s.Close()
dir, err := os.MkdirTemp("", "gptscript-test")
require.NoError(t, err)

err = os.WriteFile(filepath.Join(dir, "chatbot.gpt"), []byte(fmt.Sprintf(`
Chat: true
Name: chatbot
Context: context.gpt
Tools: http://%s/swagger.json

THis is a tool, say hi
`, s.Listener.Addr().String())), 0644)
require.NoError(t, err)

err = os.WriteFile(filepath.Join(dir, "context.gpt"), []byte(`
#!sys.echo

Stuff
`), 0644)
require.NoError(t, err)

_, err = Program(context.Background(), filepath.Join(dir, "chatbot.gpt"), "")
require.NoError(t, err)
}

func TestIsOpenAPI(t *testing.T) {
datav2, err := os.ReadFile("testdata/openapi_v2.yaml")
require.NoError(t, err)
Expand Down