Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateMultiModalResponse(ctx context.Context, inputTokenCounter metric.Int64Counter, ...) (value string, err error)
- func GetContentTypeTemplate(config *Config) *template.Template
- func GetGCSObjectName() string
- func GetTemplateByMediaType(config *Config) map[string]*PromptTemplate
- func LoadConfig(baseConfig interface{})
- func NewFileData(in string, mimeType string) genai.FileData
- func NewTextPart(in string) []*genai.Content
- type BigQueryDataSource
- type Category
- type Config
- type ContentType
- type GCSObject
- type GCSPubSubNotification
- type PromptTemplate
- type PromptTemplates
- type PubSubListener
- type QuotaAwareGenerativeAIModel
- type ServiceClients
- type Storage
- type TemplateService
- type TopicSubscription
- type VertexAiEmbeddingModel
- type VertexAiLLMModel
Constants ¶
const ( ConfigFileBaseName = ".env" ConfigFileExtension = ".toml" ConfigSeparator = "." EnvConfigFilePrefix = "GCP_CONFIG_PREFIX" EnvConfigRuntime = "GCP_RUNTIME" MaxRetries = 3 )
Cloud Constants
Variables ¶
var DefaultSafetySettings = []*genai.SafetySetting{ { Category: genai.HarmCategoryDangerousContent, Threshold: genai.HarmBlockThresholdBlockNone, }, { Category: genai.HarmCategoryHarassment, Threshold: genai.HarmBlockThresholdBlockNone, }, { Category: genai.HarmCategoryHateSpeech, Threshold: genai.HarmBlockThresholdBlockNone, }, { Category: genai.HarmCategorySexuallyExplicit, Threshold: genai.HarmBlockThresholdBlockNone, }, }
DefaultSafetySettings Default System Settings for GenAI agents
Functions ¶
func GenerateMultiModalResponse ¶
func GenerateMultiModalResponse( ctx context.Context, inputTokenCounter metric.Int64Counter, outputTokenCounter metric.Int64Counter, retryCounter metric.Int64Counter, tryCount int, model *QuotaAwareGenerativeAIModel, systemInstruction string, cacheName string, contents []*genai.Content, outputSchema *genai.Schema) (value string, err error)
GenerateMultiModalResponse A GenAI helper function for executing multi-modal requests with a retry limit.
func GetContentTypeTemplate ¶
func GetGCSObjectName ¶
func GetGCSObjectName() string
GetGCSObjectName returns a placeholder string for a GCS object name.
func GetTemplateByMediaType ¶
func GetTemplateByMediaType(config *Config) map[string]*PromptTemplate
func LoadConfig ¶
func LoadConfig(baseConfig interface{})
LoadConfig The configuration loader, a hierarchical loader that allows environment overrides.
func NewFileData ¶
NewFileData A delegate method for creating File Data parts.
func NewTextPart ¶
NewTextPart A delegate method for creating text parts
Types ¶
type BigQueryDataSource ¶
type BigQueryDataSource struct {
DatasetName string `toml:"dataset"` // The name of the BigQuery dataset.
MediaTable string `toml:"media_table"` // The name of the BigQuery table containing media information.
EmbeddingTable string `toml:"embedding_table"` // The name of the BigQuery table containing embedding vectors.
}
BigQueryDataSource represents the configuration for a BigQuery data source.
type Config ¶
type Config struct {
Application struct {
Name string `toml:"name"` // The name of the application.
GoogleProjectId string `toml:"google_project_id"` // The Google Cloud project ID.
GoogleLocation string `toml:"location"` // The Google Cloud location.
ThreadPoolSize int `toml:"thread_pool_size"` // The size of the thread pool.
} `toml:"application"`
Storage Storage `toml:"storage"` // Storage configuration.
BigQueryDataSource BigQueryDataSource `toml:"big_query_data_source"` // BigQuery data source configuration.
PromptTemplates map[string]PromptTemplates `toml:"prompt_templates"` // Prompt templates configuration.
TopicSubscriptions map[string]TopicSubscription `toml:"topic_subscriptions"` // Pub/Sub topic subscriptions configuration.
EmbeddingModels map[string]VertexAiEmbeddingModel `toml:"embedding_models"` // Vertex AI embedding models configuration.
AgentModels map[string]VertexAiLLMModel `toml:"agent_models"` // Vertex AI LLM models configuration.
Categories map[string]Category `toml:"categories"` // A list of category definitions and LLM overrides.
ContentType ContentType `toml:"content_type"` // Content type configuration.
}
Config represents the overall configuration for the application.
type ContentType ¶
type GCSObject ¶
GCSObject is a simplified representation of a Google Cloud Storage (GCS) object. It contains the bucket name, object name, and MIME type of the object.
type GCSPubSubNotification ¶
type GCSPubSubNotification struct {
Kind string `json:"kind"`
ID string `json:"id"`
SelfLink string `json:"selfLink"`
Name string `json:"name"`
Bucket string `json:"bucket"`
Generation string `json:"generation"`
MetaGeneration string `json:"metageneration"`
ContentType string `json:"contentType"`
TimeCreated string `json:"timeCreated"`
Updated string `json:"updated"`
StorageClass string `json:"storageClass"`
TimeStorageClassUpdated string `json:"timeStorageClassUpdated"`
Size string `json:"size"`
MD5Hash string `json:"md5Hash"`
MediaLink string `json:"mediaLink"`
MetaData map[string]interface{} `json:"metadata"`
Crc32c string `json:"crc32c"`
ETag string `json:"etag"`
}
GCSPubSubNotification is the structure of a message received from a Google Cloud Storage (GCS) Pub/Sub notification. It contains metadata about a change to an object in a GCS bucket.
type PromptTemplate ¶
type PromptTemplate struct {
SystemInstructions string
SummaryPrompt *template.Template
SegmentPrompt *template.Template
}
PromptTemplate holds the templates for generating summaries and segments.
type PromptTemplates ¶
type PromptTemplates struct {
SystemInstructions string `toml:"system_instructions"` // The system instructions for the LLM.
SummaryPrompt string `toml:"summary"` // The template for generating summaries.
SegmentPrompt string `toml:"segment"` // The template for generating segment descriptions.
}
PromptTemplates holds the templates for different types of prompts.
type PubSubListener ¶
type PubSubListener struct {
// contains filtered or unexported fields
}
PubSubListener is a simple stateful wrapper around a subscription object. this allows for the easy configuration of multiple listeners. Since listeners life-cycles are outside the command life-cycle they are considered cloud components.
func NewPubSubListener ¶
func NewPubSubListener( pubsubClient *pubsub.Client, subscriptionID string, command cor.Command, ) (cmd *PubSubListener, err error)
NewPubSubListener the constructor for PubSubListener
func (*PubSubListener) Listen ¶
func (m *PubSubListener) Listen(ctx context.Context)
Listen starts the async function for listening and should be instantiated using the same context of the cloud service but may be configured independently for a different recovery life-cycle.
func (*PubSubListener) SetCommand ¶
func (m *PubSubListener) SetCommand(command cor.Command)
SetCommand A setter for the underlying handler command.
type QuotaAwareGenerativeAIModel ¶
type QuotaAwareGenerativeAIModel struct {
GenerativeContentConfig *genai.GenerateContentConfig // The configuration for LLM content genration.
ModelName string
ModelHandle *genai.Models
RateLimit rate.Limiter // The rate limiter for the LLM.
}
QuotaAwareGenerativeAIModel wraps a genai.GenerativeModel with rate limiting.
func NewQuotaAwareModel ¶
func NewQuotaAwareModel(wrapped *genai.GenerateContentConfig, modelName string, modelHandle *genai.Models, requestsPerSecond int) *QuotaAwareGenerativeAIModel
NewQuotaAwareModel creates a new QuotaAwareGenerativeAIModel with the given rate limit.
func (*QuotaAwareGenerativeAIModel) GenerateContent ¶
func (q *QuotaAwareGenerativeAIModel) GenerateContent(ctx context.Context, systemInstruction string, cacheName string, contents []*genai.Content, outputSchema *genai.Schema) (resp *genai.GenerateContentResponse, err error)
GenerateContent generates content using the wrapped LLM with rate limiting.
type ServiceClients ¶
type ServiceClients struct {
StorageClient *storage.Client // The Google Cloud Storage client.
PubsubClient *pubsub.Client // The Google Cloud Pub/Sub client.
GenAIClient *genai.Client // The Google Cloud Vertex AI client.
BiqQueryClient *bigquery.Client // The Google Cloud BigQuery client.
PubSubListeners map[string]*PubSubListener // A map of Pub/Sub listeners, keyed by subscription name.
EmbeddingModels map[string]*genai.Models // A map of Vertex AI embedding models, keyed by model name.
AgentModels map[string]*QuotaAwareGenerativeAIModel // A map of Vertex AI LLM models, keyed by model name.
}
ServiceClients is the state machine for the cloud clients.
func NewCloudServiceClients ¶
func NewCloudServiceClients(ctx context.Context, config *Config) (cloud *ServiceClients, err error)
NewCloudServiceClients A helper function for correctly initializing the Google Cloud Services based on the configuration.
func (*ServiceClients) Close ¶
func (c *ServiceClients) Close()
Close A close method to ensure all clients are shut down, these are handled using a closable context, but here for clean testing.
type Storage ¶
type Storage struct {
HiResInputBucket string `toml:"high_res_input_bucket"` // The name of the bucket for high-resolution input files.
LowResOutputBucket string `toml:"low_res_output_bucket"` // The name of the bucket for low-resolution output files.
GCSFuseMountPoint string `toml:"gcs_fuse_mount_point"` // The mount point for GCS FUSE.
}
Storage represents the configuration for storage buckets.
type TemplateService ¶
type TemplateService struct {
// contains filtered or unexported fields
}
func NewTemplateService ¶
func NewTemplateService(config *Config) *TemplateService
func (*TemplateService) GetContentTypeTemplate ¶
func (t *TemplateService) GetContentTypeTemplate() *template.Template
func (*TemplateService) GetTemplateBy ¶
func (t *TemplateService) GetTemplateBy(mediaType string) *PromptTemplate
func (*TemplateService) UpdateTemplates ¶
func (t *TemplateService) UpdateTemplates()
type TopicSubscription ¶
type TopicSubscription struct {
Name string `toml:"name"` // The name of the Pub/Sub subscription.
DeadLetterTopic string `toml:"dead_letter_topic"` // The name of the dead-letter topic for the subscription.
TimeoutInSeconds int `toml:"timeout_in_seconds"` // The timeout for the subscription in seconds.
}
TopicSubscription represents the configuration for a Pub/Sub topic subscription.
type VertexAiEmbeddingModel ¶
type VertexAiEmbeddingModel struct {
Model string `toml:"model"` // The name of the Vertex AI embedding model.
MaxRequestsPerMinute int `toml:"max_requests_per_minute"` // The maximum number of requests allowed per minute.
}
VertexAiEmbeddingModel represents the configuration for a Vertex AI embedding model.
type VertexAiLLMModel ¶
type VertexAiLLMModel struct {
Model string `toml:"model"` // The name of the Vertex AI LLM.
SystemInstructions string `toml:"system_instructions"` // The system instructions for the LLM.
Temperature float32 `toml:"temperature"` // The temperature parameter for the LLM.
TopP float32 `toml:"top_p"` // The top_p parameter for the LLM.
TopK float32 `toml:"top_k"` // The top_k parameter for the LLM.
MaxTokens int32 `toml:"max_tokens"` // The maximum number of tokens for the LLM output.
OutputFormat string `toml:"output_format"` // The desired output format for the LLM.
EnableGoogle bool `toml:"enable_google"` // Whether to enable Google Search for the LLM.
RateLimit int `toml:"rate_limit"` // The rate limit for the LLM in requests per second.
}
VertexAiLLMModel represents the configuration for a Vertex AI large language model (LLM).