utils

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenRequestId

func GenRequestId() string

func Retry

func Retry(ctx context.Context,
	rp RetryPolicy,
	isNeedRetry func() bool,
	doFunc func() error, overRetryLimitError error,
	isNeedRetryError func(error) bool,
) error

Types

type BatchTask

type BatchTask struct {
	Model      string
	DoneChan   chan error
	TaskFunc   func() (BatchTaskResult, error)
	RetryTimes int
	Context    context.Context
}

type BatchTaskResult

type BatchTaskResult struct {
	RequeueAfter int64
}

type BatchWorkerPool

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

func NewBatchWorkerPool

func NewBatchWorkerPool(workerNum int) *BatchWorkerPool

func (*BatchWorkerPool) AddAfter

func (p *BatchWorkerPool) AddAfter(task BatchTask, duration time.Duration)

func (*BatchWorkerPool) Close

func (p *BatchWorkerPool) Close()

func (*BatchWorkerPool) GetOrCreateBreaker

func (p *BatchWorkerPool) GetOrCreateBreaker(model string) *Breaker

func (*BatchWorkerPool) Run

func (p *BatchWorkerPool) Run()

func (*BatchWorkerPool) Submit

func (p *BatchWorkerPool) Submit(ctx context.Context, model string, taskFunc func() (BatchTaskResult, error), doneChan chan error)

type BotChatCompletionStreamReader

type BotChatCompletionStreamReader struct {
	ChatCompletionStreamReader
}

func (*BotChatCompletionStreamReader) Close

func (stream *BotChatCompletionStreamReader) Close() error

type Breaker

type Breaker struct {
	LastTime time.Time
}

func NewBreaker

func NewBreaker() *Breaker

func (*Breaker) GetAllowedDuration

func (b *Breaker) GetAllowedDuration() time.Duration

func (*Breaker) IsAllowed

func (b *Breaker) IsAllowed() bool

func (*Breaker) Reset

func (b *Breaker) Reset(Duration time.Duration)

type ChatCompletionStreamReader

type ChatCompletionStreamReader struct {
	EmptyMessagesLimit uint
	IsFinished         bool

	Reader         *bufio.Reader
	Response       *http.Response
	ErrAccumulator ErrorAccumulator
	Unmarshaler    Unmarshaler

	model.HttpHeader
}

func (*ChatCompletionStreamReader) Close

func (stream *ChatCompletionStreamReader) Close() error

func (*ChatCompletionStreamReader) Recv

func (stream *ChatCompletionStreamReader) Recv() (response model.ChatCompletionStreamResponse, err error)

type DefaultErrorAccumulator

type DefaultErrorAccumulator struct {
	Buffer errorBuffer
}

func (*DefaultErrorAccumulator) Bytes

func (e *DefaultErrorAccumulator) Bytes() (errBytes []byte)

func (*DefaultErrorAccumulator) Write

func (e *DefaultErrorAccumulator) Write(p []byte) error

type ErrorAccumulator

type ErrorAccumulator interface {
	Write(p []byte) error
	Bytes() []byte
}

func NewErrorAccumulator

func NewErrorAccumulator() ErrorAccumulator

type HTTPRequestBuilder

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

func NewRequestBuilder

func NewRequestBuilder() *HTTPRequestBuilder

func (*HTTPRequestBuilder) Build

func (b *HTTPRequestBuilder) Build(
	ctx context.Context,
	method string,
	url string,
	body interface{},
	header http.Header,
) (req *http.Request, err error)

type JSONMarshaller

type JSONMarshaller struct{}

func (*JSONMarshaller) Marshal

func (jm *JSONMarshaller) Marshal(value interface{}) ([]byte, error)

type JSONUnmarshaler

type JSONUnmarshaler struct{}

func (*JSONUnmarshaler) Unmarshal

func (jm *JSONUnmarshaler) Unmarshal(data []byte, v interface{}) error

type Marshaller

type Marshaller interface {
	Marshal(value interface{}) ([]byte, error)
}

type RequestBuilder

type RequestBuilder interface {
	Build(ctx context.Context, method, url string, body interface{}, header http.Header) (*http.Request, error)
}

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts    int
	InitialBackoff time.Duration
	MaxBackoff     time.Duration
}

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(data []byte, v interface{}) error
}

Jump to

Keyboard shortcuts

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