-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ai): add support for search endpoints and finetunes (#3771)
- Loading branch information
1 parent
0035f3f
commit e5b0260
Showing
15 changed files
with
1,004 additions
and
3 deletions.
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,2 +1,2 @@ | ||
configured_endpoints: 1483 | ||
configured_endpoints: 1490 | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-f9dc65d353b377858f3d63d594de47559ed3a9d562295719690867315b8ec2fe.yml |
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
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"` | ||
} |
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,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()) | ||
} | ||
} |
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,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 | ||
} |
Oops, something went wrong.