From 5e5f9aee70121cabe96ffc76f5946293fa4de965 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Thu, 8 Feb 2024 23:41:47 +0000 Subject: [PATCH] feat: OpenAPI spec update --- .stats.yml | 2 +- ai.go | 111 +++++++++++++++++++++++++++++++++++++++++++++++ ai_test.go | 47 ++++++++++++++++++++ aibaai.go | 24 ++++++++++ aihuggingface.go | 25 +++++++++++ aimeta.go | 24 ++++++++++ aimicrosoft.go | 25 +++++++++++ aimistral.go | 24 ++++++++++ aiopenai.go | 24 ++++++++++ api.md | 22 ++++++++++ client.go | 2 + 11 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 ai.go create mode 100644 ai_test.go create mode 100644 aibaai.go create mode 100644 aihuggingface.go create mode 100644 aimeta.go create mode 100644 aimicrosoft.go create mode 100644 aimistral.go create mode 100644 aiopenai.go diff --git a/.stats.yml b/.stats.yml index a9a7b646af..8b9dc57d2d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 348 +configured_endpoints: 349 diff --git a/ai.go b/ai.go new file mode 100644 index 0000000000..59cd04dc62 --- /dev/null +++ b/ai.go @@ -0,0 +1,111 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare + +import ( + "context" + "fmt" + "net/http" + + "github.com/cloudflare/cloudflare-sdk-go/internal/apijson" + "github.com/cloudflare/cloudflare-sdk-go/internal/param" + "github.com/cloudflare/cloudflare-sdk-go/internal/requestconfig" + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +// AIService contains methods and other services that help with interacting with +// the cloudflare API. Note, unlike clients, this service does not read variables +// from the environment automatically. You should not instantiate this service +// directly, and instead use the [NewAIService] method instead. +type AIService struct { + Options []option.RequestOption + Huggingface *AIHuggingfaceService + Baai *AIBaaiService + OpenAI *AIOpenAIService + Microsoft *AIMicrosoftService + Meta *AIMetaService + Mistral *AIMistralService +} + +// NewAIService generates a new service that applies the given options to each +// request. These options are applied after the parent client's options (if there +// is one), and before any request-specific options. +func NewAIService(opts ...option.RequestOption) (r *AIService) { + r = &AIService{} + r.Options = opts + r.Huggingface = NewAIHuggingfaceService(opts...) + r.Baai = NewAIBaaiService(opts...) + r.OpenAI = NewAIOpenAIService(opts...) + r.Microsoft = NewAIMicrosoftService(opts...) + r.Meta = NewAIMetaService(opts...) + r.Mistral = NewAIMistralService(opts...) + return +} + +// This endpoint provides users with the capability to run specific AI models +// on-demand. +// +// By submitting the required input data, users can receive real-time predictions +// or results generated by the chosen AI model. The endpoint supports various AI +// model types, ensuring flexibility and adaptability for diverse use cases. +func (r *AIService) RunModel(ctx context.Context, accountIdentifier string, modelName string, body AIRunModelParams, opts ...option.RequestOption) (res *AIRunModelResponse, err error) { + opts = append(r.Options[:], opts...) + var env AIRunModelResponseEnvelope + path := fmt.Sprintf("accounts/%s/ai/run/%s", accountIdentifier, modelName) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +type AIRunModelResponse = interface{} + +type AIRunModelParams struct { + Body param.Field[interface{}] `json:"body,required"` +} + +func (r AIRunModelParams) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r.Body) +} + +type AIRunModelResponseEnvelope struct { + Errors []AIRunModelResponseEnvelopeErrors `json:"errors,required"` + Messages []string `json:"messages,required"` + Result AIRunModelResponse `json:"result,required"` + Success bool `json:"success,required"` + JSON aiRunModelResponseEnvelopeJSON `json:"-"` +} + +// aiRunModelResponseEnvelopeJSON contains the JSON metadata for the struct +// [AIRunModelResponseEnvelope] +type aiRunModelResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *AIRunModelResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +type AIRunModelResponseEnvelopeErrors struct { + Message string `json:"message,required"` + JSON aiRunModelResponseEnvelopeErrorsJSON `json:"-"` +} + +// aiRunModelResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [AIRunModelResponseEnvelopeErrors] +type aiRunModelResponseEnvelopeErrorsJSON struct { + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *AIRunModelResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} diff --git a/ai_test.go b/ai_test.go new file mode 100644 index 0000000000..138b9325b9 --- /dev/null +++ b/ai_test.go @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/cloudflare/cloudflare-sdk-go" + "github.com/cloudflare/cloudflare-sdk-go/internal/testutil" + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +func TestAIRunModel(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := cloudflare.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), + option.WithAPIEmail("dev@cloudflare.com"), + option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), + option.WithUserServiceKey("My User Service Key"), + ) + _, err := client.AI.RunModel( + context.TODO(), + "023e105f4ecef8ad9ca31a8372d0c353", + "string", + cloudflare.AIRunModelParams{ + Body: cloudflare.F[any](map[string]interface{}{}), + }, + ) + if err != nil { + var apierr *cloudflare.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/aibaai.go b/aibaai.go new file mode 100644 index 0000000000..e0348a845b --- /dev/null +++ b/aibaai.go @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare + +import ( + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +// AIBaaiService contains methods and other services that help with interacting +// with the cloudflare API. Note, unlike clients, this service does not read +// variables from the environment automatically. You should not instantiate this +// service directly, and instead use the [NewAIBaaiService] method instead. +type AIBaaiService struct { + Options []option.RequestOption +} + +// NewAIBaaiService generates a new service that applies the given options to each +// request. These options are applied after the parent client's options (if there +// is one), and before any request-specific options. +func NewAIBaaiService(opts ...option.RequestOption) (r *AIBaaiService) { + r = &AIBaaiService{} + r.Options = opts + return +} diff --git a/aihuggingface.go b/aihuggingface.go new file mode 100644 index 0000000000..48ead4e019 --- /dev/null +++ b/aihuggingface.go @@ -0,0 +1,25 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare + +import ( + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +// AIHuggingfaceService contains methods and other services that help with +// interacting with the cloudflare API. Note, unlike clients, this service does not +// read variables from the environment automatically. You should not instantiate +// this service directly, and instead use the [NewAIHuggingfaceService] method +// instead. +type AIHuggingfaceService struct { + Options []option.RequestOption +} + +// NewAIHuggingfaceService generates a new service that applies the given options +// to each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewAIHuggingfaceService(opts ...option.RequestOption) (r *AIHuggingfaceService) { + r = &AIHuggingfaceService{} + r.Options = opts + return +} diff --git a/aimeta.go b/aimeta.go new file mode 100644 index 0000000000..a196450777 --- /dev/null +++ b/aimeta.go @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare + +import ( + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +// AIMetaService contains methods and other services that help with interacting +// with the cloudflare API. Note, unlike clients, this service does not read +// variables from the environment automatically. You should not instantiate this +// service directly, and instead use the [NewAIMetaService] method instead. +type AIMetaService struct { + Options []option.RequestOption +} + +// NewAIMetaService generates a new service that applies the given options to each +// request. These options are applied after the parent client's options (if there +// is one), and before any request-specific options. +func NewAIMetaService(opts ...option.RequestOption) (r *AIMetaService) { + r = &AIMetaService{} + r.Options = opts + return +} diff --git a/aimicrosoft.go b/aimicrosoft.go new file mode 100644 index 0000000000..51e3480c42 --- /dev/null +++ b/aimicrosoft.go @@ -0,0 +1,25 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare + +import ( + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +// AIMicrosoftService contains methods and other services that help with +// interacting with the cloudflare API. Note, unlike clients, this service does not +// read variables from the environment automatically. You should not instantiate +// this service directly, and instead use the [NewAIMicrosoftService] method +// instead. +type AIMicrosoftService struct { + Options []option.RequestOption +} + +// NewAIMicrosoftService generates a new service that applies the given options to +// each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewAIMicrosoftService(opts ...option.RequestOption) (r *AIMicrosoftService) { + r = &AIMicrosoftService{} + r.Options = opts + return +} diff --git a/aimistral.go b/aimistral.go new file mode 100644 index 0000000000..1120a69ef1 --- /dev/null +++ b/aimistral.go @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare + +import ( + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +// AIMistralService contains methods and other services that help with interacting +// with the cloudflare API. Note, unlike clients, this service does not read +// variables from the environment automatically. You should not instantiate this +// service directly, and instead use the [NewAIMistralService] method instead. +type AIMistralService struct { + Options []option.RequestOption +} + +// NewAIMistralService generates a new service that applies the given options to +// each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewAIMistralService(opts ...option.RequestOption) (r *AIMistralService) { + r = &AIMistralService{} + r.Options = opts + return +} diff --git a/aiopenai.go b/aiopenai.go new file mode 100644 index 0000000000..38484bca94 --- /dev/null +++ b/aiopenai.go @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package cloudflare + +import ( + "github.com/cloudflare/cloudflare-sdk-go/option" +) + +// AIOpenAIService contains methods and other services that help with interacting +// with the cloudflare API. Note, unlike clients, this service does not read +// variables from the environment automatically. You should not instantiate this +// service directly, and instead use the [NewAIOpenAIService] method instead. +type AIOpenAIService struct { + Options []option.RequestOption +} + +// NewAIOpenAIService generates a new service that applies the given options to +// each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewAIOpenAIService(opts ...option.RequestOption) (r *AIOpenAIService) { + r = &AIOpenAIService{} + r.Options = opts + return +} diff --git a/api.md b/api.md index 2f21e4bf79..80b18adebc 100644 --- a/api.md +++ b/api.md @@ -40,6 +40,28 @@ Methods: - client.Zones.List(ctx context.Context, query cloudflare.ZoneListParams) ([]cloudflare.ZoneListResponse, error) - client.Zones.Delete(ctx context.Context, identifier string) (cloudflare.ZoneDeleteResponse, error) +# AI + +Response Types: + +- cloudflare.AIRunModelResponse + +Methods: + +- client.AI.RunModel(ctx context.Context, accountIdentifier string, modelName string, body cloudflare.AIRunModelParams) (cloudflare.AIRunModelResponse, error) + +## Huggingface + +## Baai + +## OpenAI + +## Microsoft + +## Meta + +## Mistral + # LoadBalancers Response Types: diff --git a/client.go b/client.go index b03f9ba105..4ef2dc7c8b 100644 --- a/client.go +++ b/client.go @@ -16,6 +16,7 @@ type Client struct { Accounts *AccountService IPs *IPService Zones *ZoneService + AI *AIService LoadBalancers *LoadBalancerService Access *AccessService DNSRecords *DNSRecordService @@ -84,6 +85,7 @@ func NewClient(opts ...option.RequestOption) (r *Client) { r.Accounts = NewAccountService(opts...) r.IPs = NewIPService(opts...) r.Zones = NewZoneService(opts...) + r.AI = NewAIService(opts...) r.LoadBalancers = NewLoadBalancerService(opts...) r.Access = NewAccessService(opts...) r.DNSRecords = NewDNSRecordService(opts...)