diff --git a/command/openai/client.go b/command/openai/client.go index 0fe3f2d6..94da5473 100644 --- a/command/openai/client.go +++ b/command/openai/client.go @@ -20,6 +20,7 @@ func CallChatGPT(cfg Config, inputMessages []ChatMessage, stream bool) (<-chan s Temperature: cfg.Temperature, Seed: cfg.Seed, MaxTokens: cfg.MaxTokens, + User: cfg.APILogUser, Stream: stream, Messages: inputMessages, }) diff --git a/command/openai/config.go b/command/openai/config.go index d215af52..446a7b53 100644 --- a/command/openai/config.go +++ b/command/openai/config.go @@ -1,6 +1,7 @@ package openai import ( + "os" "time" "github.com/innogames/slack-bot/v2/bot/config" @@ -27,6 +28,10 @@ type Config struct { // log all input+output text to the logger. This could include personal information, therefore disabled by default! LogTexts bool `mapstructure:"log_texts"` + + // user name to identify the bot which should be part of the OpenAI usage statistics. + // use {hostname} to set the hostname of the machine + APILogUser string `mapstructure:"api_log_user"` } // IsEnabled checks if token is set @@ -46,5 +51,9 @@ func loadConfig(config *config.Config) Config { cfg := defaultConfig _ = config.LoadCustom("openai", &cfg) + if cfg.APILogUser == "{hostname}" { + cfg.APILogUser, _ = os.Hostname() + } + return cfg }