Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatGPTClient ¶
type ChatGPTClient struct {
// contains filtered or unexported fields
}
ChatGPTClient is the main client for interacting with the ChatGPT API.
func Initialize ¶
func Initialize(config Cfg, options ...ChatGPTClientOption) (*ChatGPTClient, error)
Initialize creates a new ChatGPTClient with the provided config and options. The config is validated using the validate package. The options are applied in the order they are provided, but will not override each other. If the config is invalid, an error is returned. If the config is valid, a new ChatGPTClient is returned.
func MustInitialize ¶
func MustInitialize(config Cfg, options ...ChatGPTClientOption) *ChatGPTClient
MustInitialize is the same as Initialize, but panics if an error is returned.
func (*ChatGPTClient) FetchResponse ¶
func (c *ChatGPTClient) FetchResponse(prompt string) (string, error)
FetchResponse fetches a response from the OpenAI API. This function is a wrapper around FetchResponseWithContext that uses the background context. See FetchResponseWithContext for more information.
func (*ChatGPTClient) FetchResponseWithContext ¶
func (c *ChatGPTClient) FetchResponseWithContext(ctx context.Context, prompt string) (string, error)
FetchResponseWithContext fetches a response from the OpenAI API. This function will return an error if the context is cancelled or times out. This function will also return an error if the client is unable to get an access token. Messages are retrieved from the OpenAI API using Server-Sent Events (SSE).
type ChatGPTClientOption ¶
type ChatGPTClientOption interface {
Apply(*ChatGPTClient)
}
ChatGPTClientOption is an option that is applied to ChatGPTClient.
func WithCustomRetry ¶
func WithCustomRetry(o RetryOptions) ChatGPTClientOption
func WithDebugLogs ¶
func WithDebugLogs() ChatGPTClientOption
WithDebugLogs prints debug logs from the ChatGPTClient.
func WithOnProgress ¶
func WithOnProgress(fn func(partialResp string)) ChatGPTClientOption
WithOnProgress sets the OnProgress function which will be applied to partial responses as they stream in.
func WithWrappedErrors ¶
func WithWrappedErrors() ChatGPTClientOption
WithWrappedErrors wraps all errors with additional context using github.com/pkg/errors.Wrap.
type RetryOptions ¶
type RetryOptions struct { RetryCount int `validate:"required"` BackoffMinSec int `validate:"required"` // Min time in seconds to wait before retry BackoffMaxSec int `validate:"required"` // Max time in seconds to wait before retry BackoffFactor float64 `validate:"gt=1"` // Factor is the multiplying factor for each increment step BackoffJitter bool // Jitter eases contention by randomizing backoff steps }