diff --git a/main.go b/main.go index c408c64..cf42a55 100644 --- a/main.go +++ b/main.go @@ -165,40 +165,47 @@ func createLLM() (llms.Model, error) { } func getAllTags(ctx context.Context, baseURL, apiToken string) (map[string]int, error) { + tagIDMapping := make(map[string]int) url := fmt.Sprintf("%s/api/tags/", baseURL) - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) - if err != nil { - return nil, err - } - req.Header.Set("Authorization", fmt.Sprintf("Token %s", apiToken)) client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - bodyBytes, _ := io.ReadAll(resp.Body) - return nil, fmt.Errorf("Error fetching tags: %d, %s", resp.StatusCode, string(bodyBytes)) - } + for url != "" { + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + req.Header.Set("Authorization", fmt.Sprintf("Token %s", apiToken)) - var tagsResponse struct { - Results []struct { - ID int `json:"id"` - Name string `json:"name"` - } `json:"results"` - } + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&tagsResponse) - if err != nil { - return nil, err - } + if resp.StatusCode != http.StatusOK { + bodyBytes, _ := io.ReadAll(resp.Body) + return nil, fmt.Errorf("Error fetching tags: %d, %s", resp.StatusCode, string(bodyBytes)) + } - tagIDMapping := make(map[string]int) - for _, tag := range tagsResponse.Results { - tagIDMapping[tag.Name] = tag.ID + var tagsResponse struct { + Results []struct { + ID int `json:"id"` + Name string `json:"name"` + } `json:"results"` + Next string `json:"next"` + } + + err = json.NewDecoder(resp.Body).Decode(&tagsResponse) + if err != nil { + return nil, err + } + + for _, tag := range tagsResponse.Results { + tagIDMapping[tag.Name] = tag.ID + } + + url = tagsResponse.Next } return tagIDMapping, nil diff --git a/web-app/src/components/SuggestionCard.tsx b/web-app/src/components/SuggestionCard.tsx index 25da077..361ce25 100644 --- a/web-app/src/components/SuggestionCard.tsx +++ b/web-app/src/components/SuggestionCard.tsx @@ -17,6 +17,7 @@ const SuggestionCard: React.FC = ({ onTagAddition, onTagDeletion, }) => { + const sortedAvailableTags = availableTags.sort((a, b) => a.name.localeCompare(b.name)); const document = suggestion.original_document; return (
@@ -64,7 +65,7 @@ const SuggestionCard: React.FC = ({ value: index.toString(), })) || [] } - suggestions={availableTags.map((tag) => ({ + suggestions={sortedAvailableTags.map((tag) => ({ id: tag.id, name: tag.name, label: tag.name,