Documentation ¶
Index ¶
- Variables
- func Ask(prompt string, temperature float32) (string, error)
- func MustAsk(prompt string, temperature float32) string
- type FunctionCallHandler
- type GeminiClient
- func MustNew() *GeminiClient
- func MustNewText(modelName string, temperature float32) *GeminiClient
- func MustNewWithTimeout(modelName string, temperature float32, timeout time.Duration) *GeminiClient
- func New(modelName string, temperature float32) (*GeminiClient, error)
- func NewCustom(modelName, multiModalModelName, projectLocation, projectID string, ...) (*GeminiClient, error)
- func NewMultiModal(modelName string, temperature float32) (*GeminiClient, error)
- func NewText(modelName, projectLocation, projectID string, temperature float32) (*GeminiClient, error)
- func NewWithTimeout(modelName string, temperature float32, timeout time.Duration) (*GeminiClient, error)
- func (gc *GeminiClient) AddData(mimeType string, data []byte)
- func (gc *GeminiClient) AddFunctionTool(name, description string, fn interface{}) error
- func (gc *GeminiClient) AddImage(filename string) error
- func (gc *GeminiClient) AddText(prompt string)
- func (gc *GeminiClient) AddURI(URI string)
- func (gc *GeminiClient) AddURL(URL string) error
- func (gc *GeminiClient) Clear()
- func (gc *GeminiClient) ClearParts()
- func (gc *GeminiClient) ClearToolsAndFunctions()
- func (gc *GeminiClient) CountPartTokensWithContext(ctx context.Context) (int, error)
- func (gc *GeminiClient) CountPromptTokens(prompt string) (int, error)
- func (gc *GeminiClient) CountPromptTokensWithClient(ctx context.Context, client *genai.Client, prompt, modelName string) (int, error)
- func (gc *GeminiClient) CountPromptTokensWithModel(ctx context.Context, prompt, modelName string) (int, error)
- func (gc *GeminiClient) CountTextTokens(text string) (int, error)
- func (gc *GeminiClient) CountTextTokensWithClient(ctx context.Context, client *genai.Client, text, modelName string) (int, error)
- func (gc *GeminiClient) CountTextTokensWithModel(ctx context.Context, text, modelName string) (int, error)
- func (gc *GeminiClient) CountTokens() (int, error)
- func (gc *GeminiClient) MultiQuery(prompt string, base64Data, dataMimeType *string, temperature *float32) (string, error)
- func (gc *GeminiClient) MultiQueryWithCallbacks(prompt string, base64Data, dataMimeType *string, temperature *float32, ...) (string, error)
- func (gc *GeminiClient) MultiQueryWithSequentialCallbacks(prompt string, callbacks map[string]FunctionCallHandler) (string, error)
- func (gc *GeminiClient) MustAddImage(filename string)
- func (gc *GeminiClient) Query(prompt string) (string, error)
- func (gc *GeminiClient) QueryWithCallbacks(prompt string, callback FunctionCallHandler) (string, error)
- func (gc *GeminiClient) QueryWithSequentialCallbacks(prompt string, callbacks map[string]FunctionCallHandler) (string, error)
- func (gc *GeminiClient) SetTimeout(timeout time.Duration)
- func (gc *GeminiClient) SetTrim(trim bool)
- func (gc *GeminiClient) SetVerbose(verbose bool)
- func (gc *GeminiClient) Submit() (string, error)
- func (gc *GeminiClient) SubmitToClient(ctx context.Context) (result string, err error)
- func (gc *GeminiClient) SubmitToClientStreaming(ctx context.Context, streamCallback func(string)) (result string, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyPrompt = errors.New("empty prompt")
var (
ErrGoogleCloudProjectID = errors.New("please set GCP_PROJECT_ID or PROJECT_ID to your Google Cloud project ID")
)
Functions ¶
Types ¶
type FunctionCallHandler ¶
FunctionCallHandler defines a callback type for handling function responses.
type GeminiClient ¶
type GeminiClient struct { Client *genai.Client Functions map[string]reflect.Value // For custom functions that the LLM can call ModelName string MultiModalModelName string ProjectLocation string ProjectID string Tools []*genai.Tool Parts []genai.Part Timeout time.Duration Temperature float32 Trim bool Verbose bool }
func MustNew ¶
func MustNew() *GeminiClient
func MustNewText ¶
func MustNewText(modelName string, temperature float32) *GeminiClient
func MustNewWithTimeout ¶
func MustNewWithTimeout(modelName string, temperature float32, timeout time.Duration) *GeminiClient
func NewMultiModal ¶
func NewMultiModal(modelName string, temperature float32) (*GeminiClient, error)
New creates a new MultiModal instance with a specified model name and temperature, initializing it with default values for parts, trim, and verbose settings.
func NewText ¶
func NewText(modelName, projectLocation, projectID string, temperature float32) (*GeminiClient, error)
func NewWithTimeout ¶
func (*GeminiClient) AddData ¶
func (gc *GeminiClient) AddData(mimeType string, data []byte)
AddData adds arbitrary data with a specified MIME type to the parts of the MultiModal instance.
func (*GeminiClient) AddFunctionTool ¶
func (gc *GeminiClient) AddFunctionTool(name, description string, fn interface{}) error
AddFunctionTool registers a custom Go function as a tool that the model can call.
func (*GeminiClient) AddImage ¶
func (gc *GeminiClient) AddImage(filename string) error
AddImage reads an image from a file, prepares it for processing, and adds it to the list of parts to be used by the model. It supports verbose logging of operations if enabled.
func (*GeminiClient) AddText ¶
func (gc *GeminiClient) AddText(prompt string)
AddText adds a textual part to the MultiModal instance.
func (*GeminiClient) AddURI ¶
func (gc *GeminiClient) AddURI(URI string)
AddURI adds a file part to the MultiModal instance from a Google Cloud URI, allowing for integration with cloud resources directly. Example URI: "gs://generativeai-downloads/images/scones.jpg"
func (*GeminiClient) AddURL ¶
func (gc *GeminiClient) AddURL(URL string) error
AddURL downloads the file from the given URL, identifies the MIME type, and adds it as a genai.Part.
func (*GeminiClient) Clear ¶
func (gc *GeminiClient) Clear()
Clear clears the prompt parts, tools, and functions registered with the client.
func (*GeminiClient) ClearParts ¶
func (gc *GeminiClient) ClearParts()
func (*GeminiClient) ClearToolsAndFunctions ¶
func (gc *GeminiClient) ClearToolsAndFunctions()
ClearToolsAndFunctions clears all registered tools and functions.
func (*GeminiClient) CountPartTokensWithContext ¶
func (gc *GeminiClient) CountPartTokensWithContext(ctx context.Context) (int, error)
CountPartTokensWithContext counts the tokens in the current multimodal parts using the default client and model.
func (*GeminiClient) CountPromptTokens ¶
func (gc *GeminiClient) CountPromptTokens(prompt string) (int, error)
CountPromptTokens counts the number of tokens in the given text prompt using the default client and model.
func (*GeminiClient) CountPromptTokensWithClient ¶
func (gc *GeminiClient) CountPromptTokensWithClient(ctx context.Context, client *genai.Client, prompt, modelName string) (int, error)
CountPromptTokensWithClient counts the tokens in the given text prompt using a specific client and model.
func (*GeminiClient) CountPromptTokensWithModel ¶
func (gc *GeminiClient) CountPromptTokensWithModel(ctx context.Context, prompt, modelName string) (int, error)
CountPromptTokensWithModel counts the tokens in the given text prompt using the specified model within the default client.
func (*GeminiClient) CountTextTokens ¶
func (gc *GeminiClient) CountTextTokens(text string) (int, error)
CountTextTokens counts the tokens in the given text using the default client and model.
func (*GeminiClient) CountTextTokensWithClient ¶
func (gc *GeminiClient) CountTextTokensWithClient(ctx context.Context, client *genai.Client, text, modelName string) (int, error)
CountTextTokensWithClient counts the tokens in the given text using a specific client and model.
func (*GeminiClient) CountTextTokensWithModel ¶
func (gc *GeminiClient) CountTextTokensWithModel(ctx context.Context, text, modelName string) (int, error)
CountTextTokensWithModel counts the tokens in the given text using the specified model within the default client.
func (*GeminiClient) CountTokens ¶
func (gc *GeminiClient) CountTokens() (int, error)
CountTokens counts the tokens in the current multimodal parts using the default client, model, and a new context.
func (*GeminiClient) MultiQuery ¶
func (gc *GeminiClient) MultiQuery(prompt string, base64Data, dataMimeType *string, temperature *float32) (string, error)
MultiQuery processes a prompt with optional base64-encoded data and MIME type for the data.
func (*GeminiClient) MultiQueryWithCallbacks ¶
func (gc *GeminiClient) MultiQueryWithCallbacks(prompt string, base64Data, dataMimeType *string, temperature *float32, callback FunctionCallHandler) (string, error)
MultiQueryWithCallbacks processes a prompt, supports function tools, and uses a callback function to handle function responses.
func (*GeminiClient) MultiQueryWithSequentialCallbacks ¶
func (gc *GeminiClient) MultiQueryWithSequentialCallbacks(prompt string, callbacks map[string]FunctionCallHandler) (string, error)
MultiQueryWithSequentialCallbacks handles multiple function calls in sequence, using callback functions to manage responses.
func (*GeminiClient) MustAddImage ¶
func (gc *GeminiClient) MustAddImage(filename string)
MustAddImage is a convenience function that adds an image to the MultiModal instance, terminating the program if adding the image fails.
func (*GeminiClient) QueryWithCallbacks ¶
func (gc *GeminiClient) QueryWithCallbacks(prompt string, callback FunctionCallHandler) (string, error)
QueryWithCallbacks allows querying with a prompt and processing function calls via a callback handler.
func (*GeminiClient) QueryWithSequentialCallbacks ¶
func (gc *GeminiClient) QueryWithSequentialCallbacks(prompt string, callbacks map[string]FunctionCallHandler) (string, error)
QueryWithSequentialCallbacks allows querying with a prompt and processing multiple function calls in sequence via a map of callback handlers.
func (*GeminiClient) SetTimeout ¶
func (gc *GeminiClient) SetTimeout(timeout time.Duration)
func (*GeminiClient) SetTrim ¶
func (gc *GeminiClient) SetTrim(trim bool)
SetTrim updates the trim flag of the MultiModal instance, controlling whether the output is trimmed for whitespace.
func (*GeminiClient) SetVerbose ¶
func (gc *GeminiClient) SetVerbose(verbose bool)
SetVerbose updates the verbose logging flag of the MultiModal instance, allowing for more detailed output during operations.
func (*GeminiClient) Submit ¶
func (gc *GeminiClient) Submit() (string, error)
Submit sends all added parts to the specified Vertex AI model for processing, returning the model's response. It supports temperature configuration and response trimming. This function creates a temporary client and is not meant to be used within Google Cloud (use SubmitToClient instead).
func (*GeminiClient) SubmitToClient ¶
func (gc *GeminiClient) SubmitToClient(ctx context.Context) (result string, err error)
SubmitToClient sends all added parts to the specified Vertex AI model for processing, returning the model's response. It supports temperature configuration and response trimming.
func (*GeminiClient) SubmitToClientStreaming ¶
func (gc *GeminiClient) SubmitToClientStreaming(ctx context.Context, streamCallback func(string)) (result string, err error)
SubmitToClientStreaming sends the current parts to Gemini, and streams the response back by calling the streamCallback function.