From 35168845aefaaea81b3905b4db9b64190b1c7802 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 17 Dec 2024 18:45:16 +0800 Subject: [PATCH] Enhance mentions handling in Neo API - Convert keywords to lowercase for case-insensitive matching in handleMentions method. - Introduce test data for mentions to improve testing and demonstration of functionality. - Implement filtering of mentions based on keywords, allowing users to retrieve relevant mentions more effectively. - Append test mentions to actual mentions before returning the response, enhancing the API's usability. --- neo/api.go | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/neo/api.go b/neo/api.go index 7e39f49a..2fd9289d 100644 --- a/neo/api.go +++ b/neo/api.go @@ -382,7 +382,7 @@ func (neo *DSL) handleMentions(c *gin.Context) { } // Get keywords from query parameter - keywords := c.Query("keywords") + keywords := strings.ToLower(c.Query("keywords")) mentions, err := neo.GetMentions(keywords) if err != nil { c.JSON(500, gin.H{"message": err.Error(), "code": 500}) @@ -390,6 +390,42 @@ func (neo *DSL) handleMentions(c *gin.Context) { return } + // Add test data + testMentions := []Mention{ + { + ID: "assistant_1", + Name: "Alice AI", + Type: "assistant", + Avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=Alice", + }, + { + ID: "assistant_2", + Name: "Bob Bot", + Type: "assistant", + Avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=Bob", + }, + { + ID: "assistant_3", + Name: "Carol AI", + Type: "assistant", + Avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=Carol", + }, + } + + // Filter mentions by keywords + if keywords != "" { + filtered := []Mention{} + for _, m := range testMentions { + if strings.Contains(strings.ToLower(m.Name), keywords) { + filtered = append(filtered, m) + } + } + testMentions = filtered + } + + // Append test data to actual mentions + mentions = append(mentions, testMentions...) + c.JSON(200, map[string]interface{}{"data": mentions}) c.Done() }