40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package contracts
|
|
|
|
import "errors"
|
|
|
|
// ErrInvalidStructuredOutput identifies a provider response that cannot satisfy
|
|
// the caller's declared structured-output contract.
|
|
var ErrInvalidStructuredOutput = errors.New("invalid structured output")
|
|
|
|
// ErrLLMCapacityExceeded identifies backend admission exhaustion before model
|
|
// generation begins.
|
|
var ErrLLMCapacityExceeded = errors.New("LLM capacity exceeded")
|
|
|
|
// ErrLLMGeneration identifies a provider generation failure.
|
|
var ErrLLMGeneration = errors.New("LLM generation failed")
|
|
|
|
type LLMGenerationError struct {
|
|
status int
|
|
diagnostic string
|
|
}
|
|
|
|
func NewLLMGenerationError(status int, diagnostic string) *LLMGenerationError {
|
|
if status < 0 {
|
|
status = 0
|
|
}
|
|
return &LLMGenerationError{status: status, diagnostic: diagnostic}
|
|
}
|
|
func (e *LLMGenerationError) Error() string {
|
|
if e == nil || e.diagnostic == "" {
|
|
return ErrLLMGeneration.Error()
|
|
}
|
|
return e.diagnostic
|
|
}
|
|
func (e *LLMGenerationError) Unwrap() error { return ErrLLMGeneration }
|
|
func (e *LLMGenerationError) StatusCode() int {
|
|
if e == nil {
|
|
return 0
|
|
}
|
|
return e.status
|
|
}
|