Implement built-in assistant deletion and loading improvements
- Retrieve existing built-in assistants before deletion to ensure accurate removal. - Update LoadBuiltIn function to track and delete assistants that are no longer present. - Enhance error handling during the deletion process for better reliability.
This commit is contained in:
parent
6edaa712df
commit
211e523759
1 changed files with 27 additions and 1 deletions
|
|
@ -41,13 +41,23 @@ func LoadBuiltIn() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Get all existing built-in assistants
|
||||
deletedBuiltIn := map[string]bool{}
|
||||
|
||||
// Remove the built-in assistants
|
||||
if storage != nil {
|
||||
|
||||
builtIn := true
|
||||
_, err := storage.DeleteAssistants(store.AssistantFilter{BuiltIn: &builtIn})
|
||||
res, err := storage.GetAssistants(store.AssistantFilter{BuiltIn: &builtIn, Select: []string{"assistant_id", "id"}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get all existing built-in assistants
|
||||
for _, assistant := range res.Data {
|
||||
assistantID := assistant["assistant_id"].(string)
|
||||
deletedBuiltIn[assistantID] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the assistant is built-in
|
||||
|
|
@ -96,6 +106,22 @@ func LoadBuiltIn() error {
|
|||
sort++
|
||||
loaded.Put(assistant)
|
||||
|
||||
// Remove the built-in assistant from the store
|
||||
if _, ok := deletedBuiltIn[assistant.ID]; ok {
|
||||
delete(deletedBuiltIn, assistant.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove deleted built-in assistants
|
||||
if len(deletedBuiltIn) > 0 {
|
||||
assistantIDs := []string{}
|
||||
for assistantID := range deletedBuiltIn {
|
||||
assistantIDs = append(assistantIDs, assistantID)
|
||||
}
|
||||
_, err := storage.DeleteAssistants(store.AssistantFilter{AssistantIDs: assistantIDs})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue