Merge pull request #899 from trheyi/main
Implement built-in assistant deletion and loading improvements
This commit is contained in:
commit
431a6236aa
1 changed files with 27 additions and 1 deletions
|
|
@ -41,13 +41,23 @@ func LoadBuiltIn() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get all existing built-in assistants
|
||||||
|
deletedBuiltIn := map[string]bool{}
|
||||||
|
|
||||||
// Remove the built-in assistants
|
// Remove the built-in assistants
|
||||||
if storage != nil {
|
if storage != nil {
|
||||||
|
|
||||||
builtIn := true
|
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 {
|
if err != nil {
|
||||||
return err
|
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
|
// Check if the assistant is built-in
|
||||||
|
|
@ -96,6 +106,22 @@ func LoadBuiltIn() error {
|
||||||
sort++
|
sort++
|
||||||
loaded.Put(assistant)
|
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
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue