mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-03 14:27:32 +08:00
Go CLI: Add create and drop commands (#16430)
### What problem does this PR solve? 1. Add CREATE and DROP DATASET / MEMORY / AGENT / SEARCH / CHAT. 2. Add option to build.sh to strip RAGFlow binary. ### Type of change - [x] Refactoring --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -1613,3 +1613,79 @@ func (c *CLI) getDatasetIDByName(datasetName string) (string, error) {
|
||||
}
|
||||
return "", fmt.Errorf("dataset %s not found", datasetName)
|
||||
}
|
||||
|
||||
func (c *CLI) getAgentIDByName(agentName string) (string, error) {
|
||||
response, err := c.APIListAgentsCommand(nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
commonResponse, ok := response.(*CommonResponse)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid response")
|
||||
}
|
||||
for _, agent := range commonResponse.Data {
|
||||
if agent["name"] == agentName {
|
||||
return agent["id"].(string), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("agent %s not found", agentName)
|
||||
}
|
||||
|
||||
func (c *CLI) getSearchIDByName(searchName string) (string, error) {
|
||||
response, err := c.APIListSearchesCommand(nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
searchesResponse, ok := response.(*ListSearchesResponse)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid response")
|
||||
}
|
||||
searches := searchesResponse.Data["search_apps"].([]interface{})
|
||||
for _, search := range searches {
|
||||
searchMap := search.(map[string]interface{})
|
||||
if searchMap["name"] == searchName {
|
||||
return searchMap["id"].(string), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("search %s not found", searchName)
|
||||
}
|
||||
|
||||
func (c *CLI) getChatIDByName(chatName string) (string, error) {
|
||||
response, err := c.APIListChatsCommand(nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
commonResponse, ok := response.(*CommonResponse)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid response")
|
||||
}
|
||||
for _, chat := range commonResponse.Data {
|
||||
if chat["name"] == chatName {
|
||||
return chat["id"].(string), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("chat %s not found", chatName)
|
||||
}
|
||||
|
||||
func (c *CLI) getMemoryIDByName(memoryName string) (string, error) {
|
||||
response, err := c.APIListMemoriesCommand(nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
listMemoriesResponse, ok := response.(*ListMemoriesResponse)
|
||||
memories := listMemoriesResponse.Data["memory_list"].([]interface{})
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid response")
|
||||
}
|
||||
for _, memory := range memories {
|
||||
var memoryMap map[string]interface{}
|
||||
memoryMap, ok = memory.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if memoryMap["name"] == memoryName {
|
||||
return memoryMap["id"].(string), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("memory %s not found", memoryName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user