更新ai服务提醒

This commit is contained in:
2026-07-01 11:26:08 +08:00
parent 716f711373
commit f6fa167d76
6 changed files with 111 additions and 57 deletions
+9
View File
@@ -262,6 +262,9 @@ func (s *Service) Enabled() bool {
// ReloadLLMProvider reloads a specific LLM provider configuration
func (s *Service) ReloadLLMProvider(config interface{}) error {
if s == nil {
return nil
}
if !s.enabled || s.LLMState == nil {
return nil
}
@@ -274,6 +277,9 @@ func (s *Service) ReloadLLMProvider(config interface{}) error {
// AddLLMProvider adds a new LLM provider
func (s *Service) AddLLMProvider(config interface{}) error {
if s == nil {
return nil
}
if !s.enabled || s.LLMState == nil {
return nil
}
@@ -286,6 +292,9 @@ func (s *Service) AddLLMProvider(config interface{}) error {
// RemoveLLMProvider removes an LLM provider
func (s *Service) RemoveLLMProvider(name string) error {
if s == nil {
return nil
}
if !s.enabled || s.LLMState == nil {
return nil
}
+61 -47
View File
@@ -298,25 +298,30 @@ func handleCreateLLMProvider(store *storepkg.Store, aiService LLMProviderReloade
}
// Reload AI service with new provider
if aiService != nil {
providerConfig := map[string]interface{}{
"Name": record.Name,
"Active": record.Active,
"APIKey": record.APIKey,
"BaseURL": record.BaseURL,
"Model": record.Model,
"Timeout": record.Timeout,
"ContextWindowTokens": record.ContextWindowTokens,
}
if err := aiService.AddLLMProvider(providerConfig); err != nil {
// Log warning but don't fail the request - database is already updated
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"item": llmProviderDTO(*record),
"warning": "provider created but failed to reload AI service: " + err.Error(),
})
return
}
if aiService == nil {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"item": llmProviderDTO(*record),
"warning": "AI 服务未运行,配置已保存但需重启服务后生效",
})
return
}
providerConfig := map[string]interface{}{
"Name": record.Name,
"Active": record.Active,
"APIKey": record.APIKey,
"BaseURL": record.BaseURL,
"Model": record.Model,
"Timeout": record.Timeout,
"ContextWindowTokens": record.ContextWindowTokens,
}
if err := aiService.AddLLMProvider(providerConfig); err != nil {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"item": llmProviderDTO(*record),
"warning": "provider created but failed to reload AI service: " + err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{"status": "ok", "item": llmProviderDTO(*record)})
@@ -385,25 +390,30 @@ func handleUpdateLLMProvider(store *storepkg.Store, aiService LLMProviderReloade
}
// Reload AI service with updated provider
if aiService != nil {
providerConfig := map[string]interface{}{
"Name": record.Name,
"Active": record.Active,
"APIKey": record.APIKey,
"BaseURL": record.BaseURL,
"Model": record.Model,
"Timeout": record.Timeout,
"ContextWindowTokens": record.ContextWindowTokens,
}
if err := aiService.ReloadLLMProvider(providerConfig); err != nil {
// Log warning but don't fail the request - database is already updated
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"item": llmProviderDTO(*record),
"warning": "provider updated but failed to reload AI service: " + err.Error(),
})
return
}
if aiService == nil {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"item": llmProviderDTO(*record),
"warning": "AI 服务未运行,配置已保存但需重启服务后生效",
})
return
}
providerConfig := map[string]interface{}{
"Name": record.Name,
"Active": record.Active,
"APIKey": record.APIKey,
"BaseURL": record.BaseURL,
"Model": record.Model,
"Timeout": record.Timeout,
"ContextWindowTokens": record.ContextWindowTokens,
}
if err := aiService.ReloadLLMProvider(providerConfig); err != nil {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"item": llmProviderDTO(*record),
"warning": "provider updated but failed to reload AI service: " + err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{"status": "ok", "item": llmProviderDTO(*record)})
@@ -424,15 +434,19 @@ func handleDeleteLLMProvider(store *storepkg.Store, aiService LLMProviderReloade
}
// Remove provider from AI service
if aiService != nil {
if err := aiService.RemoveLLMProvider(name); err != nil {
// Log warning but don't fail the request - database is already updated
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"warning": "provider deleted but failed to reload AI service: " + err.Error(),
})
return
}
if aiService == nil {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"warning": "AI 服务未运行,配置已删除但需重启服务后生效",
})
return
}
if err := aiService.RemoveLLMProvider(name); err != nil {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"warning": "provider deleted but failed to reload AI service: " + err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{"status": "ok"})