Documentation
¶
Index ¶
- func ErrToStr(err error) (str string)
- func FuncArg[T any](from map[string]any, key string) (*T, error)
- func IsModelOverloaded(err error) bool
- func IsQuotaExceeded(err error) bool
- func SupportedMimeType(data []byte) (matchedMimeType string, supported bool, err error)
- func SupportedMimeTypePath(filepath string) (matchedMimeType string, supported bool, err error)
- type ChunkedText
- type Client
- func (c *Client) CacheContext(ctx context.Context, systemInstruction, promptText *string, ...) (cachedContextName string, err error)
- func (c *Client) Close() error
- func (c *Client) DeleteAllCachedContexts(ctx context.Context) (err error)
- func (c *Client) DeleteAllFiles(ctx context.Context) (err error)
- func (c *Client) DeleteCachedContext(ctx context.Context, cachedContextName string) (err error)
- func (c *Client) Generate(ctx context.Context, promptText string, promptFiles map[string]io.Reader, ...) (res *genai.GenerateContentResponse, err error)
- func (c *Client) GenerateEmbeddings(ctx context.Context, title string, parts []genai.Part) (vectors []float32, err error)
- func (c *Client) GenerateStreamIterated(ctx context.Context, promptText string, promptFiles map[string]io.Reader, ...) (iterator *genai.GenerateContentResponseIterator, err error)
- func (c *Client) GenerateStreamed(ctx context.Context, promptText string, promptFiles map[string]io.Reader, ...) error
- func (c *Client) ListAllCachedContexts(ctx context.Context) (listed map[string]genai.CachedContent, err error)
- func (c *Client) SetCachedContextExpireTime(ctx context.Context, cachedContextName string, expireTime time.Time) (err error)
- func (c *Client) SetCachedContextTTL(ctx context.Context, cachedContextName string, ttl time.Duration) (err error)
- func (c *Client) SetSystemInstructionFunc(fn FnSystemInstruction)
- func (c *Client) SetTimeout(seconds int)
- func (c *Client) UploadFilesAndWait(ctx context.Context, files map[string]io.Reader) (uploaded []genai.FileData, err error)
- type FnStreamCallback
- type FnSystemInstruction
- type GenerationOptions
- type NumTokens
- type StreamCallbackData
- type TextChunkOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FuncArg ¶
FuncArg searches for and returns a value with given `key` from the function call arguments `from`.
func IsModelOverloaded ¶ added in v0.1.33
IsModelOverloaded returns if given error is from overloaded model.
func IsQuotaExceeded ¶ added in v0.1.32
IsQuotaExceeded returns if given error is from execeeded API quota.
func SupportedMimeType ¶ added in v0.0.14
SupportedMimeType detects and returns the matched mime type of given bytes data and whether it's supported or not.
Types ¶
type ChunkedText ¶ added in v0.1.35
ChunkedText contains the original text and the chunks.
func ChunkText ¶ added in v0.1.35
func ChunkText(text string, opts ...TextChunkOption) (ChunkedText, error)
ChunkText splits the given text into chunks of the specified size.
type Client ¶
type Client struct { Verbose bool // contains filtered or unexported fields }
Client struct
func (*Client) CacheContext ¶ added in v0.1.0
func (c *Client) CacheContext(ctx context.Context, systemInstruction, promptText *string, promptFiles map[string]io.Reader, tools []*genai.Tool, toolConfig *genai.ToolConfig, cachedContextDisplayName *string) (cachedContextName string, err error)
CacheContext caches the context with given values and return the name of the cached context.
`promptText`, `promptFiles`, `tools`, `toolConfig`, and `cachedContextDisplayName` are optional.
func (*Client) DeleteAllCachedContexts ¶ added in v0.1.0
DeleteAllCachedContexts deletes all cached contexts.
func (*Client) DeleteAllFiles ¶ added in v0.1.0
DeleteAllFiles deletes all uploaded files.
func (*Client) DeleteCachedContext ¶ added in v0.1.4
DeleteCachedContext deletes a cached context.
func (*Client) Generate ¶
func (c *Client) Generate( ctx context.Context, promptText string, promptFiles map[string]io.Reader, options ...*GenerationOptions, ) (res *genai.GenerateContentResponse, err error)
Generate generates with given values synchronously.
It times out in `timeoutSeconds` seconds.
It retries on 5xx errors for `maxRetryCount` times.
func (*Client) GenerateEmbeddings ¶ added in v0.1.24
func (c *Client) GenerateEmbeddings(ctx context.Context, title string, parts []genai.Part) (vectors []float32, err error)
GenerateEmbeddings generates embeddings with given values.
`title` can be empty.
func (*Client) GenerateStreamIterated ¶ added in v0.0.11
func (c *Client) GenerateStreamIterated( ctx context.Context, promptText string, promptFiles map[string]io.Reader, options ...*GenerationOptions, ) (iterator *genai.GenerateContentResponseIterator, err error)
GenerateStreamIterated generates stream iterator with given values.
It does not timeout itself, so set timeout with `ctx` when needed.
func (*Client) GenerateStreamed ¶
func (c *Client) GenerateStreamed( ctx context.Context, promptText string, promptFiles map[string]io.Reader, fnStreamCallback FnStreamCallback, options ...*GenerationOptions, ) error
GenerateStreamed generates with given values synchronously and calls back `fnStreamCallback`.
It times out in `timeoutSeconds` seconds.
func (*Client) ListAllCachedContexts ¶ added in v0.1.3
func (c *Client) ListAllCachedContexts(ctx context.Context) (listed map[string]genai.CachedContent, err error)
ListAllCachedContexts lists all cached contexts.
`listed` is a map of cached context name and display name.
func (*Client) SetCachedContextExpireTime ¶ added in v0.1.0
func (c *Client) SetCachedContextExpireTime(ctx context.Context, cachedContextName string, expireTime time.Time) (err error)
SetCachedContextExpireTime sets the expiration time of a cached context.
(default: 1 hour later)
func (*Client) SetCachedContextTTL ¶ added in v0.1.0
func (c *Client) SetCachedContextTTL(ctx context.Context, cachedContextName string, ttl time.Duration) (err error)
SetCachedContextTTL sets the TTL of a cached context.
(default: 1 hour)
func (*Client) SetSystemInstructionFunc ¶
func (c *Client) SetSystemInstructionFunc(fn FnSystemInstruction)
SetSystemInstructionFunc sets the system instruction function.
func (*Client) SetTimeout ¶
SetTimeout sets the timeout in seconds.
func (*Client) UploadFilesAndWait ¶ added in v0.0.10
func (c *Client) UploadFilesAndWait(ctx context.Context, files map[string]io.Reader) (uploaded []genai.FileData, err error)
UploadFilesAndWait uploads files and wait for them to be ready.
`files` is a map of keys: display name, and values: io.Reader.
type FnStreamCallback ¶
type FnStreamCallback func(callbackData StreamCallbackData)
function definitions
type GenerationOptions ¶
type GenerationOptions struct { // generation config Config *genai.GenerationConfig // tool config Tools []*genai.Tool ToolConfig *genai.ToolConfig // safety settings: harm block threshold HarmBlockThreshold *genai.HarmBlockThreshold // cached context CachedContextName *string // history (for session) History []*genai.Content }
GenerationOptions struct for function Generate.
func NewGenerationOptions ¶ added in v0.1.12
func NewGenerationOptions() *GenerationOptions
NewGenerationOptions returns a new GenerationOptions with default values.
type StreamCallbackData ¶
type StreamCallbackData struct { // when there is a text delta, TextDelta *string // when there is a function call, FunctionCall *genai.FunctionCall // when there is a code execution result, ExecutableCode *genai.ExecutableCode CodeExecutionResult *genai.CodeExecutionResult // when the number of tokens are calculated, (after the stream is finished) NumTokens *NumTokens // when there is a finish reason, FinishReason *genai.FinishReason // when there is an error, Error error }
StreamCallbackData struct contains the data for stream callback function.