Skip to content

Commit

Permalink
Change verifier signature
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jul 27, 2023
1 parent 908fa8f commit 2f8102f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions chain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type HTTPClient interface {
}

// VerifyURL is the function signature for verifying the API URL.
type VerifyURL func(url string) error
type VerifyURL func(url string) bool

// Compile time check to ensure API satisfies the Chain interface.
var _ schema.Chain = (*API)(nil)
Expand All @@ -57,7 +57,7 @@ type APIOptions struct {
Header map[string]string

// VerifyURL is a function used to verify the validity of the generated API URL before making the request.
// It returns an error if the URL is deemed invalid or if it fails any validation checks.
// It returns true if the URL is valid, false otherwise.
VerifyURL VerifyURL
}

Expand All @@ -73,7 +73,7 @@ func NewAPI(llm schema.Model, apiDoc string, optFns ...func(o *APIOptions)) (*AP
InputKey: "question",
OutputKey: "output",
HTTPClient: http.DefaultClient,
VerifyURL: func(url string) error { return nil },
VerifyURL: func(url string) bool { return true },
CallbackOptions: &schema.CallbackOptions{
Verbose: golc.Verbose,
},
Expand Down Expand Up @@ -122,8 +122,8 @@ func (c *API) Call(ctx context.Context, inputs schema.ChainValues, optFns ...fun
apiURL = fmt.Sprintf("https://%s", apiURL)
}

if vErr := c.opts.VerifyURL(apiURL); vErr != nil {
return nil, vErr
if ok := c.opts.VerifyURL(apiURL); !ok {
return nil, fmt.Errorf("invalid API URL: %s", apiURL)
}

httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, apiURL, nil)
Expand Down
6 changes: 3 additions & 3 deletions chain/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ func TestAPI(t *testing.T) {
Status: "200 OK",
StatusCode: http.StatusOK,
}
o.VerifyURL = func(url string) error {
return errors.New("invalid API URL")
o.VerifyURL = func(url string) bool {
return false
}
})
require.NoError(t, err)

_, err = golc.SimpleCall(context.Background(), api, "What is the Ultimate Answer?")
require.Error(t, err)
require.EqualError(t, errors.New("invalid API URL"), err.Error())
require.EqualError(t, errors.New("invalid API URL: https://galaxy.org"), err.Error())
})
}

Expand Down

0 comments on commit 2f8102f

Please sign in to comment.