gemini

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultModel = "gemini-1.5-flash"

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatSession

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

ChatSession represents a gemini powered chat session.

func NewChatSession

func NewChatSession(
	ctx context.Context, modelBuilder *GenerativeModelBuilder, apiKey string,
) (*ChatSession, error)

NewChatSession returns a new ChatSession.

func (*ChatSession) ClearHistory

func (c *ChatSession) ClearHistory()

ClearHistory clears the chat session history.

func (*ChatSession) Close

func (c *ChatSession) Close() error

Close closes the chat session.

func (*ChatSession) CopyModelBuilder added in v0.4.0

func (c *ChatSession) CopyModelBuilder() *GenerativeModelBuilder

CopyModelBuilder returns a copy builder for the chat generative model.

func (*ChatSession) GetHistory added in v0.4.0

func (c *ChatSession) GetHistory() []*genai.Content

GetHistory returns the chat session history.

func (*ChatSession) ListModels added in v0.4.0

func (c *ChatSession) ListModels() []string

ListModels returns a list of the supported generative model names.

func (*ChatSession) ModelInfo added in v0.4.0

func (c *ChatSession) ModelInfo() (string, error)

ModelInfo returns information about the chat generative model in JSON format.

func (*ChatSession) SendMessage

func (c *ChatSession) SendMessage(input string) (*genai.GenerateContentResponse, error)

SendMessage sends a request to the model as part of a chat session.

func (*ChatSession) SendMessageStream

func (c *ChatSession) SendMessageStream(input string) *genai.GenerateContentResponseIterator

SendMessageStream is like SendMessage, but with a streaming request.

func (*ChatSession) SetHistory added in v0.4.0

func (c *ChatSession) SetHistory(content []*genai.Content)

SetHistory sets the chat session history.

func (*ChatSession) SetModel added in v0.4.0

func (c *ChatSession) SetModel(modelBuilder *GenerativeModelBuilder)

SetModel sets a new generative model configured with the builder and starts a new chat session. It preserves the history of the previous chat session.

type GenerativeModelBuilder added in v0.4.0

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

GenerativeModelBuilder implements the builder pattern for genai.GenerativeModel.

func NewGenerativeModelBuilder added in v0.4.0

func NewGenerativeModelBuilder() *GenerativeModelBuilder

NewGenerativeModelBuilder returns a new GenerativeModelBuilder with empty default values.

func (*GenerativeModelBuilder) WithCachedContentName added in v0.4.0

func (b *GenerativeModelBuilder) WithCachedContentName(
	cachedContentName string,
) *GenerativeModelBuilder

WithCachedContentName sets the name of the genai.CachedContent to use.

func (*GenerativeModelBuilder) WithGenerationConfig added in v0.4.0

func (b *GenerativeModelBuilder) WithGenerationConfig(
	generationConfig genai.GenerationConfig,
) *GenerativeModelBuilder

WithGenerationConfig sets the generation config.

func (*GenerativeModelBuilder) WithName added in v0.4.0

func (b *GenerativeModelBuilder) WithName(
	modelName string,
) *GenerativeModelBuilder

WithName sets the model name.

func (*GenerativeModelBuilder) WithSafetySettings added in v0.4.0

func (b *GenerativeModelBuilder) WithSafetySettings(
	safetySettings []*genai.SafetySetting,
) *GenerativeModelBuilder

WithSafetySettings sets the safety settings.

func (*GenerativeModelBuilder) WithSystemInstruction added in v0.4.0

func (b *GenerativeModelBuilder) WithSystemInstruction(
	systemInstruction *genai.Content,
) *GenerativeModelBuilder

WithSystemInstruction sets the system instruction.

func (*GenerativeModelBuilder) WithToolConfig added in v0.4.0

func (b *GenerativeModelBuilder) WithToolConfig(
	toolConfig *genai.ToolConfig,
) *GenerativeModelBuilder

WithToolConfig sets the tool config.

func (*GenerativeModelBuilder) WithTools added in v0.4.0

func (b *GenerativeModelBuilder) WithTools(
	tools []*genai.Tool,
) *GenerativeModelBuilder

WithTools sets the tools.

type SerializableContent added in v0.4.0

type SerializableContent struct {
	// Ordered parts that constitute a single message.
	Parts []string
	// The producer of the content. Must be either 'user' or 'model'.
	Role string
}

SerializableContent is the data type containing multipart text message content. It is a serializable equivalent of genai.Content, where message content parts are represented as strings.

func NewSerializableContent added in v0.4.0

func NewSerializableContent(c *genai.Content) *SerializableContent

NewSerializableContent instantiates and returns a new SerializableContent from the given genai.Content. It will panic if the content type is not supported.

func (*SerializableContent) ToContent added in v0.4.0

func (c *SerializableContent) ToContent() *genai.Content

ToContent converts the SerializableContent into a genai.Content.

type SystemInstruction added in v0.4.0

type SystemInstruction string

SystemInstruction represents a serializable system prompt, a more forceful instruction to the language model. The model will prioritize adhering to system instructions over regular prompts.

func (SystemInstruction) ToContent added in v0.4.0

func (si SystemInstruction) ToContent() *genai.Content

ToContent converts the SystemInstruction to genai.Content.

Jump to

Keyboard shortcuts

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