From 6b7363be74694999f86a53f554939425a9eac05b Mon Sep 17 00:00:00 2001 From: Pawel Kosiec Date: Tue, 5 Nov 2024 21:53:09 +0100 Subject: [PATCH] Support OpenAI API token for AI Assistant --- internal/source/ai-brain/assistant.go | 2 +- internal/source/ai-brain/config.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/source/ai-brain/assistant.go b/internal/source/ai-brain/assistant.go index bce4f79..14ab463 100644 --- a/internal/source/ai-brain/assistant.go +++ b/internal/source/ai-brain/assistant.go @@ -118,7 +118,7 @@ func newAssistant(cfg *Config, log logrus.FieldLogger, out chan source.Event, ku return nil, fmt.Errorf("while creating Botkube runner: %w", err) } - config := openai.DefaultConfig("") + config := openai.DefaultConfig(cfg.OpenAIAPIToken) config.BaseURL = cfg.OpenAIBaseURL config.AssistantVersion = "v2" diff --git a/internal/source/ai-brain/config.go b/internal/source/ai-brain/config.go index 883a7df..0fdd401 100644 --- a/internal/source/ai-brain/config.go +++ b/internal/source/ai-brain/config.go @@ -17,7 +17,8 @@ const assistantID = "asst_eMM9QaWLi6cajHE4PdG1yU53" type Config struct { Log config.Logger `yaml:"log"` OpenAIBaseURL string `yaml:"openAIBaseURL"` - OpenAIAssistantID string `yaml:"openAIAssistantId"` + OpenAIAssistantID string `yaml:"openAIAssistantID"` + OpenAIAPIToken string `yaml:"openAIAPIToken"` HoneycombAPIKey string `yaml:"honeycombAPIKey"` HoneycombSampleRate int `yaml:"honeycombSampleRate"` VectorStoreIDForThread string `yaml:"vectorStoreIDForThread"` @@ -30,6 +31,9 @@ func (c *Config) Validate() error { if c.OpenAIAssistantID == "" { issues = multierror.Append(issues, errors.New("the Open AI Assistant ID cannot be empty")) } + if c.OpenAIAPIToken == "" { + issues = multierror.Append(issues, errors.New("the Open AI API token cannot be empty")) + } return issues.ErrorOrNil() }