Skip to content
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

🌿 Fern Regeneration -- September 13, 2024 #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .mock/fern.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"organization" : "vellum",
"version" : "0.41.2"
"version" : "0.41.9"
}
16 changes: 9 additions & 7 deletions adhoc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ func (c *Client) AdhocExecutePromptStream(
return streamer.Stream(
ctx,
&core.StreamParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
},
)
}
150 changes: 84 additions & 66 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ func (c *Client) ExecutePrompt(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -206,13 +208,15 @@ func (c *Client) ExecutePromptStream(
return streamer.Stream(
ctx,
&core.StreamParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
},
)
}
Expand Down Expand Up @@ -273,14 +277,16 @@ func (c *Client) ExecuteWorkflow(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -344,13 +350,15 @@ func (c *Client) ExecuteWorkflowStream(
return streamer.Stream(
ctx,
&core.StreamParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
},
)
}
Expand Down Expand Up @@ -421,14 +429,16 @@ func (c *Client) Generate(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -502,13 +512,15 @@ func (c *Client) GenerateStream(
return streamer.Stream(
ctx,
&core.StreamParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
},
)
}
Expand Down Expand Up @@ -569,14 +581,16 @@ func (c *Client) Search(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
Expand Down Expand Up @@ -639,13 +653,15 @@ func (c *Client) SubmitCompletionActuals(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
ErrorDecoder: errorDecoder,
},
); err != nil {
return err
Expand Down Expand Up @@ -677,12 +693,14 @@ func (c *Client) SubmitWorkflowExecutionActuals(
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
URL: endpointURL,
Method: http.MethodPost,
MaxAttempts: options.MaxAttempts,
Headers: headers,
BodyProperties: options.BodyProperties,
QueryParameters: options.QueryParameters,
Client: options.HTTPClient,
Request: request,
},
); err != nil {
return err
Expand Down
62 changes: 48 additions & 14 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"reflect"
"strings"
)

const (
Expand Down Expand Up @@ -137,6 +138,8 @@ type CallParams struct {
Method string
MaxAttempts uint
Headers http.Header
BodyProperties map[string]interface{}
QueryParameters url.Values
Client HTTPClient
Request interface{}
Response interface{}
Expand All @@ -146,7 +149,15 @@ type CallParams struct {

// Call issues an API call according to the given call parameters.
func (c *Caller) Call(ctx context.Context, params *CallParams) error {
req, err := newRequest(ctx, params.URL, params.Method, params.Headers, params.Request)
url := buildURL(params.URL, params.QueryParameters)
req, err := newRequest(
ctx,
url,
params.Method,
params.Headers,
params.Request,
params.BodyProperties,
)
if err != nil {
return err
}
Expand Down Expand Up @@ -213,6 +224,23 @@ func (c *Caller) Call(ctx context.Context, params *CallParams) error {
return nil
}

// buildURL constructs the final URL by appending the given query parameters (if any).
func buildURL(
url string,
queryParameters url.Values,
) string {
if len(queryParameters) == 0 {
return url
}
if strings.ContainsRune(url, '?') {
url += "&"
} else {
url += "?"
}
url += queryParameters.Encode()
return url
}

// newRequest returns a new *http.Request with all of the fields
// required to issue the call.
func newRequest(
Expand All @@ -221,8 +249,9 @@ func newRequest(
method string,
endpointHeaders http.Header,
request interface{},
bodyProperties map[string]interface{},
) (*http.Request, error) {
requestBody, err := newRequestBody(request)
requestBody, err := newRequestBody(request, bodyProperties)
if err != nil {
return nil, err
}
Expand All @@ -239,20 +268,25 @@ func newRequest(
}

// newRequestBody returns a new io.Reader that represents the HTTP request body.
func newRequestBody(request interface{}) (io.Reader, error) {
var requestBody io.Reader
if !isNil(request) {
if body, ok := request.(io.Reader); ok {
requestBody = body
} else {
requestBytes, err := json.Marshal(request)
if err != nil {
return nil, err
}
requestBody = bytes.NewReader(requestBytes)
func newRequestBody(request interface{}, bodyProperties map[string]interface{}) (io.Reader, error) {
if isNil(request) {
if len(bodyProperties) == 0 {
return nil, nil
}
requestBytes, err := json.Marshal(bodyProperties)
if err != nil {
return nil, err
}
return bytes.NewReader(requestBytes), nil
}
if body, ok := request.(io.Reader); ok {
return body, nil
}
requestBytes, err := MarshalJSONWithExtraProperties(request, bodyProperties)
if err != nil {
return nil, err
}
return requestBody, nil
return bytes.NewReader(requestBytes), nil
}

// decodeError decodes the error from the given HTTP response. Note that
Expand Down
Loading
Loading