gt

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 16 Imported by: 5

README

gemini-things-go

A helper library for generating things with Gemini API.

Test

$ API_KEY="AIabcdefghijklmnopqrstuvwxyz_ABCDEFG-00000000-00" go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncArg

func FuncArg[T any](from map[string]any, key string) (*T, error)

FuncArg searches for and returns a value with given `key` from the function call arguments `from`.

func UploadFilesAndWait added in v0.0.2

func UploadFilesAndWait(ctx context.Context, client *genai.Client, files []io.Reader) (uploaded []genai.FileData, err error)

UploadFilesAndWait uploads files and wait for them to be ready

Types

type Client

type Client struct {
	Verbose bool
	// contains filtered or unexported fields
}

Client struct

func NewClient

func NewClient(model, apiKey string) *Client

NewClient returns a new client with given values.

func (*Client) Generate

func (c *Client) Generate(
	ctx context.Context,
	promptText string,
	promptFiles []io.Reader,
	options ...*GenerationOptions,
) (res *genai.GenerateContentResponse, err error)

Generate generates with given values synchronously.

func (*Client) GenerateStreamed

func (c *Client) GenerateStreamed(
	ctx context.Context,
	promptText string,
	promptFiles []io.Reader,
	fnStreamCallback FnStreamCallback,
	options ...*GenerationOptions,
) error

GenerateStreamed generates with given values synchronously.

func (*Client) SetSystemInstructionFunc

func (c *Client) SetSystemInstructionFunc(fn FnSystemInstruction)

SetSystemInstructionFunc sets the system instruction function.

func (*Client) SetTimeout

func (c *Client) SetTimeout(seconds int)

SetTimeout sets the timeout in seconds.

type FnStreamCallback

type FnStreamCallback func(callbackData StreamCallbackData)

type FnSystemInstruction

type FnSystemInstruction func() string

function definitions

type GenerationOptions

type GenerationOptions struct {
	// generation config
	Config *genai.GenerationConfig

	// tool config
	Tools      []*genai.Tool
	ToolConfig *genai.ToolConfig

	// history (for session)
	History []*genai.Content
}

GenerationOptions struct for function Generate.

type NumTokens

type NumTokens struct {
	Input  int32
	Output int32
	Cached int32
}

NumTokens struct for input/output token numbers

type StreamCallbackData

type StreamCallbackData struct {
	// when there is a text delta,
	TextDelta *string

	// when there is a function call,
	FunctionCall *genai.FunctionCall

	// when the number of tokens are calculated,
	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.

Jump to

Keyboard shortcuts

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