-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy patherrors.go
More file actions
38 lines (30 loc) · 844 Bytes
/
errors.go
File metadata and controls
38 lines (30 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package clients
import (
"errors"
"fmt"
"time"
)
var (
ErrEmptyResponse = errors.New("empty model response")
ErrProviderUnavailable = errors.New("provider is not available")
ErrUnauthorized = errors.New("API key is wrong or not set")
ErrChatStreamNotImplemented = errors.New("streaming chat API is not implemented for provider")
)
type RateLimitError struct {
untilReset time.Duration
}
func (e RateLimitError) Error() string {
return fmt.Sprintf("rate limit reached, please wait %v", e.untilReset)
}
func (e RateLimitError) UntilReset() time.Duration {
return e.untilReset
}
func NewRateLimitError(untilReset *time.Duration) *RateLimitError {
defaultResetTime := 1 * time.Minute
if untilReset == nil {
untilReset = &defaultResetTime
}
return &RateLimitError{
untilReset: *untilReset,
}
}