Files
probo/pkg/llm/errors.go
Bryan Frimin 158c36d9ab Add LLM interface
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 17:21:43 +01:00

71 lines
1.9 KiB
Go

// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package llm
import (
"fmt"
"time"
)
type (
ErrRateLimit struct {
RetryAfter time.Duration
Err error
}
ErrContextLength struct {
MaxTokens int
Err error
}
ErrContentFilter struct {
Err error
}
ErrAuthentication struct {
Err error
}
)
func (e *ErrRateLimit) Error() string {
if e.RetryAfter > 0 {
return fmt.Sprintf("rate limited (retry after %s): %v", e.RetryAfter, e.Err)
}
return fmt.Sprintf("rate limited: %v", e.Err)
}
func (e *ErrRateLimit) Unwrap() error { return e.Err }
func (e *ErrContextLength) Error() string {
if e.MaxTokens > 0 {
return fmt.Sprintf("context length exceeded (max %d tokens): %v", e.MaxTokens, e.Err)
}
return fmt.Sprintf("context length exceeded: %v", e.Err)
}
func (e *ErrContextLength) Unwrap() error { return e.Err }
func (e *ErrContentFilter) Error() string {
return fmt.Sprintf("content filtered: %v", e.Err)
}
func (e *ErrContentFilter) Unwrap() error { return e.Err }
func (e *ErrAuthentication) Error() string {
return fmt.Sprintf("authentication failed: %v", e.Err)
}
func (e *ErrAuthentication) Unwrap() error { return e.Err }