clients

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// AIGuardModeHeader controls how AI Guard enforces its decision.
	//   - "shadow": AI Guard evaluates but never blocks the request.
	//   - "enforce": AI Guard may block the request (HTTP 422) on DENY/ABORT.
	AIGuardModeHeader = "x-ai-guard-mode"

	AiGuardModeShadow = "shadow" // shadow value for AIGuardModeHeader

	// AIGuardServiceEnvHeader identifies the environment of the calling service
	// (e.g. "staging", "prod") and is forwarded to AI Guard for attribution and logging.
	AIGuardServiceEnvHeader = "x-ai-guard-service-env"

	// AIGuardServiceNameHeader identifies the calling service name and is forwarded
	// to AI Guard for attribution, analytics, and allowlist/denylist logic.
	AIGuardServiceNameHeader = "x-ai-guard-service-name"

	AIGuardActionAllow = "ALLOW" // ALLOW value returned by AIGuard

	// AIGuardActionRequestHeader is returned by AI Gateway and indicates AI Guard's
	// decision (ALLOW/DENY/ABORT/CLIENT_ERROR) for the request phase check
	// (the user prompt).
	AIGuardActionRequestHeader = "x-ai-guard-action-request"

	// AIGuardActionResponseHeader is returned by AI Gateway and indicates AI Guard's
	// decision (ALLOW/DENY/ABORT/CLIENT_ERROR) for the response phase check
	// (model response).
	AIGuardActionResponseHeader = "x-ai-guard-action-response"
)
View Source
const (
	ApplicationJsonHeader = "application/json"
)
View Source
const (
	SOURCE = "datadog-ai-static-analyzer"
)

Variables

View Source
var ErrRateLimited = errors.New("rate limited by API")

ErrRateLimited is returned when the API returns a 429 status (rate limit exceeded). This error triggers fail-fast behavior - the analysis stops immediately without retries.

Functions

func GenerateSchema

func GenerateSchema[T any]() interface{}

func GetHost

func GetHost(provider, customURL string) string

func GetProvidedAPIKey

func GetProvidedAPIKey(provider string) string

func IsRateLimitError

func IsRateLimitError(err error) bool

IsRateLimitError checks if an error is or wraps a rate limit error

func SetProvidedAPIKey

func SetProvidedAPIKey(provider, key string)

Types

type AnthropicClient

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

func NewAnthropicClient

func NewAnthropicClient(ctx context.Context, model string) (*AnthropicClient, error)

func (*AnthropicClient) GenerateContent

func (c *AnthropicClient) GenerateContent(ctx context.Context, systemPrompt, userPrompt string,
	options *GenerateOptions) (*GenerateResponse, error)

type AnthropicTokenGetter

type AnthropicTokenGetter struct{}

func (*AnthropicTokenGetter) Get

type DefaultTokenGetter

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

func (*DefaultTokenGetter) Get

type GeminiClient

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

func NewGeminiClient

func NewGeminiClient(ctx context.Context, modelName string) (*GeminiClient, error)

func (*GeminiClient) GenerateContent

func (c *GeminiClient) GenerateContent(ctx context.Context, systemPrompt,
	userPrompt string, options *GenerateOptions) (*GenerateResponse, error)

type GeminiTokenGetter

type GeminiTokenGetter struct{}

func (*GeminiTokenGetter) Get

func (t *GeminiTokenGetter) Get(ctx context.Context) (string, error)

type GenerateOptionSchema

type GenerateOptionSchema struct {
	Name        string
	Description string
	JsonSchema  any
}

type GenerateOptions

type GenerateOptions struct {
	MaxTokens    int
	Temperature  float64
	ResponseType string
	Schema       GenerateOptionSchema
}

type GenerateResponse

type GenerateResponse struct {
	Content      string
	InputTokens  int32
	OutputTokens int32
}

type LLMClient

type LLMClient interface {
	GenerateContent(ctx context.Context, systemPrompt, userPrompt string, options *GenerateOptions) (*GenerateResponse, error)
}

type OpenAIClient

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

func NewOpenAIClient

func NewOpenAIClient(ctx context.Context, model string, baseURL string, isAIGateway bool, aiGuardEnabled bool,
	orgID int64, isCustom bool) (*OpenAIClient, error)

func (*OpenAIClient) GenerateContent

func (c *OpenAIClient) GenerateContent(ctx context.Context, systemPrompt, userPrompt string,
	options *GenerateOptions) (*GenerateResponse, error)

type OpenAITokenGetter

type OpenAITokenGetter struct{}

func (*OpenAITokenGetter) Get

func (t *OpenAITokenGetter) Get(ctx context.Context) (string, error)

type TokenGetter

type TokenGetter interface {
	Get(ctx context.Context) (string, error)
}

func GetTokenGetter

func GetTokenGetter(provider string) TokenGetter

Jump to

Keyboard shortcuts

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