-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7fdabd
commit 5e5f9ae
Showing
11 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
configured_endpoints: 348 | ||
configured_endpoints: 349 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters