bridge

package
v2.31.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Mode determines how requests are made.
	// "bridge": Create users in Coder and use their session tokens to make requests through AI Bridge.
	// "direct": Make requests directly to UpstreamURL without user creation.
	Mode RequestMode `json:"mode"`

	// User is the configuration for the user to create.
	// Required in bridge mode.
	User createusers.Config `json:"user"`

	// UpstreamURL is the URL to make requests to directly.
	// Only used in direct mode.
	UpstreamURL string `json:"upstream_url"`

	// Provider is the API provider to use: "completions", "messages", or "responses".
	Provider string `json:"provider"`

	// RequestCount is the number of requests to make per runner.
	RequestCount int `json:"request_count"`

	// Stream indicates whether to use streaming requests.
	Stream bool `json:"stream"`

	// RequestPayloadSize is the size in bytes of the request payload (user message content).
	// If 0, uses default message content.
	RequestPayloadSize int `json:"request_payload_size"`

	// NumMessages is the number of messages to include in the conversation.
	// Messages alternate between user and assistant roles, always ending with user.
	// Must be greater than 0.
	NumMessages int `json:"num_messages"`

	// HTTPTimeout is the timeout for individual HTTP requests to the upstream
	// provider. This is separate from the job timeout which controls the overall
	// test execution.
	HTTPTimeout time.Duration `json:"http_timeout"`

	Metrics *Metrics `json:"-"`

	// RequestBody is the pre-serialized JSON request body. This is generated
	// once by PrepareRequestBody and shared across all runners and requests.
	RequestBody []byte `json:"-"`
}

func (Config) NewStrategy

func (c Config) NewStrategy(client *codersdk.Client) requestModeStrategy

func (*Config) PrepareRequestBody

func (c *Config) PrepareRequestBody() error

PrepareRequestBody generates the conversation and serializes the full request body once. This should be called before creating Runners so that all runners share the same pre-generated payload.

func (Config) Validate

func (c Config) Validate() error

type Metrics

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

func NewMetrics

func NewMetrics(reg prometheus.Registerer) *Metrics

func (*Metrics) AddError

func (m *Metrics) AddError(action string)

func (*Metrics) AddRequest

func (m *Metrics) AddRequest(status string)

func (*Metrics) AddTokens

func (m *Metrics) AddTokens(tokenType string, count int64)

func (*Metrics) ObserveDuration

func (m *Metrics) ObserveDuration(duration float64)

type ProviderStrategy

type ProviderStrategy interface {
	DefaultModel() string
	// contains filtered or unexported methods
}

ProviderStrategy handles provider-specific message formatting for LLM APIs.

func NewProviderStrategy

func NewProviderStrategy(provider string) ProviderStrategy

type RequestMode

type RequestMode string
const (
	RequestModeBridge RequestMode = "bridge"
	RequestModeDirect RequestMode = "direct"
)

type Runner

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

func NewRunner

func NewRunner(client *codersdk.Client, cfg Config) *Runner

func (*Runner) Cleanup

func (r *Runner) Cleanup(ctx context.Context, id string, logs io.Writer) error

func (*Runner) GetMetrics

func (r *Runner) GetMetrics() map[string]any

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error

func (*Runner) WithClock

func (r *Runner) WithClock(clock quartz.Clock) *Runner

Jump to

Keyboard shortcuts

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