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

feat(ai): add support for search endpoints and finetunes #3771

Merged
merged 1 commit into from
Jan 2, 2025
Merged
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 .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1483
configured_endpoints: 1490
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-f9dc65d353b377858f3d63d594de47559ed3a9d562295719690867315b8ec2fe.yml
10 changes: 8 additions & 2 deletions ai/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import (
// automatically. You should not instantiate this service directly, and instead use
// the [NewAIService] method instead.
type AIService struct {
Options []option.RequestOption
Models *ModelService
Options []option.RequestOption
Finetunes *FinetuneService
Authors *AuthorService
Tasks *TaskService
Models *ModelService
}

// NewAIService generates a new service that applies the given options to each
Expand All @@ -34,6 +37,9 @@ type AIService struct {
func NewAIService(opts ...option.RequestOption) (r *AIService) {
r = &AIService{}
r.Options = opts
r.Finetunes = NewFinetuneService(opts...)
r.Authors = NewAuthorService(opts...)
r.Tasks = NewTaskService(opts...)
r.Models = NewModelService(opts...)
return
}
Expand Down
67 changes: 67 additions & 0 deletions ai/author.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package ai

import (
"context"
"errors"
"fmt"
"net/http"

"github.com/cloudflare/cloudflare-go/v3/internal/param"
"github.com/cloudflare/cloudflare-go/v3/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v3/option"
"github.com/cloudflare/cloudflare-go/v3/packages/pagination"
)

// AuthorService 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 [NewAuthorService] method instead.
type AuthorService struct {
Options []option.RequestOption
}

// NewAuthorService 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 NewAuthorService(opts ...option.RequestOption) (r *AuthorService) {
r = &AuthorService{}
r.Options = opts
return
}

// Author Search
func (r *AuthorService) List(ctx context.Context, query AuthorListParams, opts ...option.RequestOption) (res *pagination.SinglePage[AuthorListResponse], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if query.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/ai/authors/search", query.AccountID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, nil, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}

// Author Search
func (r *AuthorService) ListAutoPaging(ctx context.Context, query AuthorListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[AuthorListResponse] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}

type AuthorListResponse = interface{}

type AuthorListParams struct {
AccountID param.Field[string] `path:"account_id,required"`
}
40 changes: 40 additions & 0 deletions ai/author_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package ai_test

import (
"context"
"errors"
"os"
"testing"

"github.com/cloudflare/cloudflare-go/v3"
"github.com/cloudflare/cloudflare-go/v3/ai"
"github.com/cloudflare/cloudflare-go/v3/internal/testutil"
"github.com/cloudflare/cloudflare-go/v3/option"
)

func TestAuthorList(t *testing.T) {
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("[email protected]"),
)
_, err := client.AI.Authors.List(context.TODO(), ai.AuthorListParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
})
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())
}
}
199 changes: 199 additions & 0 deletions ai/finetune.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package ai

import (
"context"
"errors"
"fmt"
"net/http"
"time"

"github.com/cloudflare/cloudflare-go/v3/internal/apijson"
"github.com/cloudflare/cloudflare-go/v3/internal/param"
"github.com/cloudflare/cloudflare-go/v3/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v3/option"
)

// FinetuneService 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 [NewFinetuneService] method instead.
type FinetuneService struct {
Options []option.RequestOption
Assets *FinetuneAssetService
Public *FinetunePublicService
}

// NewFinetuneService 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 NewFinetuneService(opts ...option.RequestOption) (r *FinetuneService) {
r = &FinetuneService{}
r.Options = opts
r.Assets = NewFinetuneAssetService(opts...)
r.Public = NewFinetunePublicService(opts...)
return
}

// Create a new Finetune
func (r *FinetuneService) New(ctx context.Context, params FinetuneNewParams, opts ...option.RequestOption) (res *FinetuneNewResponse, err error) {
var env FinetuneNewResponseEnvelope
opts = append(r.Options[:], opts...)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/ai/finetunes", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

// List Finetunes
func (r *FinetuneService) List(ctx context.Context, query FinetuneListParams, opts ...option.RequestOption) (res *FinetuneListResponse, err error) {
var env FinetuneListResponseEnvelope
opts = append(r.Options[:], opts...)
if query.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/ai/finetunes", query.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

type FinetuneNewResponse struct {
ID string `json:"id,required" format:"uuid"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
Model string `json:"model,required"`
ModifiedAt time.Time `json:"modified_at,required" format:"date-time"`
Name string `json:"name,required"`
Public bool `json:"public,required"`
Description string `json:"description"`
JSON finetuneNewResponseJSON `json:"-"`
}

// finetuneNewResponseJSON contains the JSON metadata for the struct
// [FinetuneNewResponse]
type finetuneNewResponseJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Model apijson.Field
ModifiedAt apijson.Field
Name apijson.Field
Public apijson.Field
Description apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *FinetuneNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r finetuneNewResponseJSON) RawJSON() string {
return r.raw
}

type FinetuneListResponse struct {
ID string `json:"id,required" format:"uuid"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
Model string `json:"model,required"`
ModifiedAt time.Time `json:"modified_at,required" format:"date-time"`
Name string `json:"name,required"`
Description string `json:"description"`
JSON finetuneListResponseJSON `json:"-"`
}

// finetuneListResponseJSON contains the JSON metadata for the struct
// [FinetuneListResponse]
type finetuneListResponseJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Model apijson.Field
ModifiedAt apijson.Field
Name apijson.Field
Description apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *FinetuneListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r finetuneListResponseJSON) RawJSON() string {
return r.raw
}

type FinetuneNewParams struct {
AccountID param.Field[string] `path:"account_id,required"`
Model param.Field[string] `json:"model,required"`
Name param.Field[string] `json:"name,required"`
Description param.Field[string] `json:"description"`
Public param.Field[bool] `json:"public"`
}

func (r FinetuneNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type FinetuneNewResponseEnvelope struct {
Result FinetuneNewResponse `json:"result,required"`
Success bool `json:"success,required"`
JSON finetuneNewResponseEnvelopeJSON `json:"-"`
}

// finetuneNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [FinetuneNewResponseEnvelope]
type finetuneNewResponseEnvelopeJSON struct {
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *FinetuneNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r finetuneNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

type FinetuneListParams struct {
AccountID param.Field[string] `path:"account_id,required"`
}

type FinetuneListResponseEnvelope struct {
Result FinetuneListResponse `json:"result,required"`
Success bool `json:"success,required"`
JSON finetuneListResponseEnvelopeJSON `json:"-"`
}

// finetuneListResponseEnvelopeJSON contains the JSON metadata for the struct
// [FinetuneListResponseEnvelope]
type finetuneListResponseEnvelopeJSON struct {
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *FinetuneListResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r finetuneListResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
Loading