mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
e00e85765b
This PR merges code from `coder/aibridge` repository into `coder/coder`. It was split into 4 PRs for easier review but stacked PRs will need to be merged into this PR so all checks pass. * https://github.com/coder/coder/pull/24190 -> raw code copy (this PR, before merging PRs on top of it, it was just 1 commit: https://github.com/coder/coder/commit/70d33f33200c7e77df910957595715f81f9bec24) * https://github.com/coder/coder/pull/24570 -> update imports in `coder/coder` to use copied code * https://github.com/coder/coder/pull/24586 -> linter fixes and CI integration (also added README.md) * https://github.com/coder/coder/pull/24571 -> added exclude to scripts/check_emdash.sh check Original PR message (before PR squash): Moves coder/aibridge code into coder/coder repository. Omitted files: - `go.mod`, `go.sum`, `.gitignore`, `.github/workflows/ci.yml,` `Makefile`, `LICENSE`, `README.md` (modified README.md is added later) - `.github`, `example`, `buildinfo,` `scripts` directories Simple verification script (will list omitted files) ``` tmp=$(mktemp -d) echo "$tmp" git clone --depth=1 https://github.com/coder/aibridge "$tmp/aibridge" git clone --depth=1 --branch pb/aibridge-code-move https://github.com/coder/coder "$tmp/coder" diff -rq --exclude=.git "$tmp/aibridge" "$tmp/coder/aibridge" # rm -rf "$tmp" ```
94 lines
3.1 KiB
Go
94 lines
3.1 KiB
Go
package config
|
|
|
|
import "time"
|
|
|
|
const (
|
|
ProviderAnthropic = "anthropic"
|
|
ProviderOpenAI = "openai"
|
|
ProviderCopilot = "copilot"
|
|
)
|
|
|
|
type Anthropic struct {
|
|
// Name is the provider instance name. If empty, defaults to "anthropic".
|
|
Name string
|
|
BaseURL string
|
|
Key string
|
|
APIDumpDir string
|
|
CircuitBreaker *CircuitBreaker
|
|
SendActorHeaders bool
|
|
ExtraHeaders map[string]string
|
|
// BYOKBearerToken is set in BYOK mode when the user authenticates
|
|
// with a access token. When set, the access token is used for upstream
|
|
// LLM requests instead of the API key.
|
|
BYOKBearerToken string
|
|
// MaxRetries controls the number of automatic retries the SDK will perform
|
|
// on transient errors. If nil, the SDK default (2) is used.
|
|
// Set to 0 to disable retries entirely.
|
|
MaxRetries *int
|
|
}
|
|
|
|
type AWSBedrock struct {
|
|
Region string
|
|
AccessKey, AccessKeySecret string
|
|
Model, SmallFastModel string
|
|
// If set, requests will be sent to this URL instead of the default AWS Bedrock endpoint
|
|
// (https://bedrock-runtime.{region}.amazonaws.com).
|
|
// This is useful for routing requests through a proxy or for testing.
|
|
BaseURL string
|
|
}
|
|
|
|
type OpenAI struct {
|
|
// Name is the provider instance name. If empty, defaults to "openai".
|
|
Name string
|
|
BaseURL string
|
|
Key string
|
|
APIDumpDir string
|
|
CircuitBreaker *CircuitBreaker
|
|
SendActorHeaders bool
|
|
ExtraHeaders map[string]string
|
|
// MaxRetries controls the number of automatic retries the SDK will perform
|
|
// on transient errors. If nil, the SDK default (2) is used.
|
|
// Set to 0 to disable retries entirely.
|
|
MaxRetries *int
|
|
}
|
|
|
|
type Copilot struct {
|
|
// Name is the provider instance name. If empty, defaults to "copilot".
|
|
Name string
|
|
BaseURL string
|
|
APIDumpDir string
|
|
CircuitBreaker *CircuitBreaker
|
|
// MaxRetries controls the number of automatic retries the SDK will perform
|
|
// on transient errors. If nil, the SDK default (2) is used.
|
|
// Set to 0 to disable retries entirely.
|
|
MaxRetries *int
|
|
}
|
|
|
|
// CircuitBreaker holds configuration for circuit breakers.
|
|
type CircuitBreaker struct {
|
|
// MaxRequests is the maximum number of requests allowed in half-open state.
|
|
MaxRequests uint32
|
|
// Interval is the cyclic period of the closed state for clearing internal counts.
|
|
Interval time.Duration
|
|
// Timeout is how long the circuit stays open before transitioning to half-open.
|
|
Timeout time.Duration
|
|
// FailureThreshold is the number of consecutive failures that triggers the circuit to open.
|
|
FailureThreshold uint32
|
|
// IsFailure determines if a status code should count as a failure.
|
|
// If nil, defaults to DefaultIsFailure.
|
|
IsFailure func(statusCode int) bool
|
|
// OpenErrorResponse returns the response body when the circuit is open.
|
|
// This should match the provider's error format.
|
|
OpenErrorResponse func() []byte
|
|
}
|
|
|
|
// DefaultCircuitBreaker returns sensible defaults for circuit breaker configuration.
|
|
func DefaultCircuitBreaker() CircuitBreaker {
|
|
return CircuitBreaker{
|
|
FailureThreshold: 5,
|
|
Interval: 10 * time.Second,
|
|
Timeout: 30 * time.Second,
|
|
MaxRequests: 3,
|
|
}
|
|
}
|