Skip to content

Commit

Permalink
feat: OpenAPI spec update
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Feb 8, 2024
1 parent d7fdabd commit 5e5f9ae
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 348
configured_endpoints: 349
111 changes: 111 additions & 0 deletions ai.go
Original file line number Diff line number Diff line change
@@ -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)
}
47 changes: 47 additions & 0 deletions ai_test.go
Original file line number Diff line number Diff line change
@@ -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())
}
}
24 changes: 24 additions & 0 deletions aibaai.go
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions aihuggingface.go
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions aimeta.go
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions aimicrosoft.go
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions aimistral.go
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions aiopenai.go
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ Methods:
- <code title="get /zones">client.Zones.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#ZoneService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go">cloudflare</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#ZoneListParams">ZoneListParams</a>) ([]<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go">cloudflare</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#ZoneListResponse">ZoneListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /zones/{identifier}">client.Zones.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#ZoneService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, identifier <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go">cloudflare</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#ZoneDeleteResponse">ZoneDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# AI

Response Types:

- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go">cloudflare</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#AIRunModelResponse">AIRunModelResponse</a>

Methods:

- <code title="post /accounts/{account_identifier}/ai/run/{model_name}">client.AI.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#AIService.RunModel">RunModel</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, accountIdentifier <a href="https://pkg.go.dev/builtin#string">string</a>, modelName <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go">cloudflare</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#AIRunModelParams">AIRunModelParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go">cloudflare</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-sdk-go#AIRunModelResponse">AIRunModelResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

## Huggingface

## Baai

## OpenAI

## Microsoft

## Meta

## Mistral

# LoadBalancers

Response Types:
Expand Down
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Client struct {
Accounts *AccountService
IPs *IPService
Zones *ZoneService
AI *AIService
LoadBalancers *LoadBalancerService
Access *AccessService
DNSRecords *DNSRecordService
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit 5e5f9ae

Please sign in to comment.