cloudflare

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKeyEnvVar = "CLOUDFLARE_API_TOKEN"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudflareClient

type CloudflareClient struct {
	BaseAPI string

	APIToken       embeddings.Secret `json:"-" validate:"required"`
	APIKeyEnvVar   string
	AccountID      string `validate:"required_if=IsGateway false"`
	DefaultModel   embeddings.EmbeddingModel
	IsGateway      bool
	MaxBatchSize   int `validate:"gt=0,lte=100"`
	DefaultHeaders map[string]string
	Client         *http.Client
	Insecure       bool
	// contains filtered or unexported fields
}

func NewCloudflareClient

func NewCloudflareClient(opts ...Option) (*CloudflareClient, error)

func (*CloudflareClient) CreateEmbedding

type CloudflareEmbeddingFunction

type CloudflareEmbeddingFunction struct {
	// contains filtered or unexported fields
}

func NewCloudflareEmbeddingFunction

func NewCloudflareEmbeddingFunction(opts ...Option) (*CloudflareEmbeddingFunction, error)

func NewCloudflareEmbeddingFunctionFromConfig added in v0.3.0

func NewCloudflareEmbeddingFunctionFromConfig(cfg embeddings.EmbeddingFunctionConfig) (*CloudflareEmbeddingFunction, error)

NewCloudflareEmbeddingFunctionFromConfig creates a Cloudflare embedding function from a config map. Uses schema-compliant field names: api_key_env_var, model_name, account_id, is_gateway, gateway_endpoint, insecure.

func (*CloudflareEmbeddingFunction) DefaultSpace added in v0.3.0

func (*CloudflareEmbeddingFunction) EmbedDocuments

func (e *CloudflareEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]embeddings.Embedding, error)

func (*CloudflareEmbeddingFunction) EmbedQuery

func (*CloudflareEmbeddingFunction) GetConfig added in v0.3.0

func (*CloudflareEmbeddingFunction) Name added in v0.3.0

func (*CloudflareEmbeddingFunction) SupportedSpaces added in v0.3.0

func (e *CloudflareEmbeddingFunction) SupportedSpaces() []embeddings.DistanceMetric

type CreateEmbeddingRequest

type CreateEmbeddingRequest struct {
	Text []string `json:"text"`
}

func (*CreateEmbeddingRequest) JSON

func (c *CreateEmbeddingRequest) JSON() (string, error)

type CreateEmbeddingResponse

type CreateEmbeddingResponse struct {
	Success  bool   `json:"success"`
	Messages []any  `json:"messages"`
	Errors   []any  `json:"errors"`
	Result   Result `json:"result"`
}

type Option

type Option func(p *CloudflareClient) error

func WithAPIKeyFromEnvVar added in v0.3.0

func WithAPIKeyFromEnvVar(envVar string) Option

WithAPIKeyFromEnvVar sets the API key for the client from a specified environment variable

func WithAPIToken

func WithAPIToken(apiToken string) Option

func WithAccountID

func WithAccountID(accountID string) Option

func WithDefaultHeaders

func WithDefaultHeaders(headers map[string]string) Option

func WithDefaultModel

func WithDefaultModel(model embeddings.EmbeddingModel) Option

func WithEnvAPIToken

func WithEnvAPIToken() Option

func WithEnvAccountID

func WithEnvAccountID() Option

func WithEnvGatewayEndpoint

func WithEnvGatewayEndpoint() Option

func WithGatewayEndpoint

func WithGatewayEndpoint(endpoint string) Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithInsecure added in v0.3.0

func WithInsecure() Option

WithInsecure allows the client to connect to HTTP endpoints without TLS. This should only be used for local development or testing.

func WithMaxBatchSize

func WithMaxBatchSize(size int) Option

type Result

type Result struct {
	Shape []int       `json:"shape"`
	Data  [][]float32 `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL