fix: improve AI settings initialization and local service support

- Add dedicated default constants for tag recommendation config
- Set tag recommendation enabled to false by default instead of following AI enable state
- Remove API key requirement for AI enablement to support local services like Ollama
- Simplify loadAISettingFromEnv by removing redundant tag recommendation setup

Signed-off-by: ChaoLiu <chaoliu719@gmail.com>
This commit is contained in:
ChaoLiu 2025-08-19 15:17:50 +08:00
parent 0443fdc976
commit 96e527e264
1 changed files with 7 additions and 11 deletions

View File

@ -213,8 +213,10 @@ func (s *Store) GetWorkspaceStorageSetting(ctx context.Context) (*storepb.Worksp
} }
const ( const (
defaultAIEnabled = false
defaultAITimeoutSeconds = int32(15) defaultAITimeoutSeconds = int32(15)
defaultAITagRecommandationEnabled = false
defaultAITagRecommandationPrompt = ""
defaultAITagRecommandationRPM = int32(10)
) )
func (s *Store) GetWorkspaceAISetting(ctx context.Context) (*storepb.WorkspaceAISetting, error) { func (s *Store) GetWorkspaceAISetting(ctx context.Context) (*storepb.WorkspaceAISetting, error) {
@ -241,9 +243,9 @@ func (s *Store) GetWorkspaceAISetting(ctx context.Context) (*storepb.WorkspaceAI
// Set default tag recommendation config if not configured // Set default tag recommendation config if not configured
if workspaceAISetting.TagRecommendation == nil { if workspaceAISetting.TagRecommendation == nil {
workspaceAISetting.TagRecommendation = &storepb.TagRecommendationConfig{ workspaceAISetting.TagRecommendation = &storepb.TagRecommendationConfig{
Enabled: workspaceAISetting.EnableAi, Enabled: defaultAITagRecommandationEnabled,
SystemPrompt: "", SystemPrompt: defaultAITagRecommandationPrompt,
RequestsPerMinute: 10, RequestsPerMinute: defaultAITagRecommandationRPM,
} }
} }
@ -267,8 +269,7 @@ func loadAISettingFromEnv() *storepb.WorkspaceAISetting {
apiKey := os.Getenv("AI_API_KEY") apiKey := os.Getenv("AI_API_KEY")
model := os.Getenv("AI_MODEL") model := os.Getenv("AI_MODEL")
// Enable AI if all required fields are provided via environment variables enableAI := baseURL != "" && model != ""
enableAI := baseURL != "" && apiKey != "" && model != ""
return &storepb.WorkspaceAISetting{ return &storepb.WorkspaceAISetting{
EnableAi: enableAI, EnableAi: enableAI,
@ -276,11 +277,6 @@ func loadAISettingFromEnv() *storepb.WorkspaceAISetting {
ApiKey: apiKey, ApiKey: apiKey,
Model: model, Model: model,
TimeoutSeconds: timeoutSeconds, TimeoutSeconds: timeoutSeconds,
TagRecommendation: &storepb.TagRecommendationConfig{
Enabled: enableAI,
SystemPrompt: "",
RequestsPerMinute: 10,
},
} }
} }