修正向量请求
This commit is contained in:
		
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "editor.inlineSuggest.showToolbar": "always"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -106,9 +106,6 @@ func NewSchema() (graphql.Schema, error) {
 | 
				
			|||||||
							for _, field := range fieldAST.SelectionSet.Selections {
 | 
												for _, field := range fieldAST.SelectionSet.Selections {
 | 
				
			||||||
								fieldAST, ok := field.(*ast.Field)
 | 
													fieldAST, ok := field.(*ast.Field)
 | 
				
			||||||
								if ok {
 | 
													if ok {
 | 
				
			||||||
									//if fieldAST.Name.Value == "avatar" {
 | 
					 | 
				
			||||||
									//	fieldAST.Name.Value = fmt.Sprintf("IFNULL(%s,'')", fieldAST.Name.Value)
 | 
					 | 
				
			||||||
									//}
 | 
					 | 
				
			||||||
									fields = append(fields, fieldAST.Name.Value)
 | 
														fields = append(fields, fieldAST.Name.Value)
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
@@ -138,7 +135,6 @@ func NewSchema() (graphql.Schema, error) {
 | 
				
			|||||||
				var query strings.Builder
 | 
									var query strings.Builder
 | 
				
			||||||
				query.WriteString(fmt.Sprintf("SELECT %s FROM web_member %s LIMIT %d OFFSET %s", fields_str, where_str, first, after))
 | 
									query.WriteString(fmt.Sprintf("SELECT %s FROM web_member %s LIMIT %d OFFSET %s", fields_str, where_str, first, after))
 | 
				
			||||||
				// 返回翻页信息
 | 
									// 返回翻页信息
 | 
				
			||||||
				fmt.Println(query.String())
 | 
					 | 
				
			||||||
				var users []User
 | 
									var users []User
 | 
				
			||||||
				if err := connection.Select(&users, query.String()); err != nil {
 | 
									if err := connection.Select(&users, query.String()); err != nil {
 | 
				
			||||||
					fmt.Println("获取用户列表失败", err)
 | 
										fmt.Println("获取用户列表失败", err)
 | 
				
			||||||
@@ -241,7 +237,6 @@ func NewSchema() (graphql.Schema, error) {
 | 
				
			|||||||
				// 执行查询
 | 
									// 执行查询
 | 
				
			||||||
				var query strings.Builder
 | 
									var query strings.Builder
 | 
				
			||||||
				query.WriteString(fmt.Sprintf("SELECT %s FROM web_images WHERE %s LIMIT %d OFFSET %s", fields_str, where_str, first, after))
 | 
									query.WriteString(fmt.Sprintf("SELECT %s FROM web_images WHERE %s LIMIT %d OFFSET %s", fields_str, where_str, first, after))
 | 
				
			||||||
				fmt.Println(query.String())
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				var images []Image
 | 
									var images []Image
 | 
				
			||||||
				if err := connection.Select(&images, query.String()); err != nil {
 | 
									if err := connection.Select(&images, query.String()); err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										25
									
								
								bin/main.go
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								bin/main.go
									
									
									
									
									
								
							@@ -103,27 +103,31 @@ func GetNetWorkEmbedding(id int) (embedding []float32) {
 | 
				
			|||||||
	httpClient := &http.Client{}
 | 
						httpClient := &http.Client{}
 | 
				
			||||||
	request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s:%d/api/default/%d", host, port, id), nil)
 | 
						request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s:%d/api/default/%d", host, port, id), nil)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Println("请求失败:", err)
 | 
							log.Println("请求失败1:", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	response, err := httpClient.Do(request)
 | 
						response, err := httpClient.Do(request)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Println("请求失败:", err)
 | 
							log.Println("请求失败2:", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer response.Body.Close()
 | 
						defer response.Body.Close()
 | 
				
			||||||
	var result map[string]interface{}
 | 
					
 | 
				
			||||||
 | 
						var result struct {
 | 
				
			||||||
 | 
							Code    int       `json:"code"`
 | 
				
			||||||
 | 
							Message string    `json:"message"`
 | 
				
			||||||
 | 
							Feature []float32 `json:"feature"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	err = json.NewDecoder(response.Body).Decode(&result)
 | 
						err = json.NewDecoder(response.Body).Decode(&result)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Println("解析失败:", err)
 | 
							log.Println("解析失败:", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if result["code"] != 0 {
 | 
						if result.Code != 0 {
 | 
				
			||||||
		log.Println("请求失败:", result["message"])
 | 
							log.Println("请求失败3:", result.Message)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	embedding = result["feature"].([]float32)
 | 
						return result.Feature
 | 
				
			||||||
	return embedding
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (image *Image) GetSimilarImagesIdList(collection_name string) (ids []int64) {
 | 
					func (image *Image) GetSimilarImagesIdList(collection_name string) (ids []int64) {
 | 
				
			||||||
@@ -311,7 +315,6 @@ func main() {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			if len(text_ids) > 0 {
 | 
								if len(text_ids) > 0 {
 | 
				
			||||||
				conditions.WriteString(fmt.Sprintf(" WHERE id IN (%s)", strings.Trim(strings.Replace(fmt.Sprint(text_ids), " ", ",", -1), "[]")))
 | 
									conditions.WriteString(fmt.Sprintf(" WHERE id IN (%s)", strings.Trim(strings.Replace(fmt.Sprint(text_ids), " ", ",", -1), "[]")))
 | 
				
			||||||
				fmt.Println("conditions", conditions.String())
 | 
					 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				// 直接返回空列表
 | 
									// 直接返回空列表
 | 
				
			||||||
				var images ListView
 | 
									var images ListView
 | 
				
			||||||
@@ -338,8 +341,6 @@ func main() {
 | 
				
			|||||||
			addCondition(&conditions, "sets", "sets")
 | 
								addCondition(&conditions, "sets", "sets")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fmt.Println("conditions", conditions.String())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 获取图片列表
 | 
							// 获取图片列表
 | 
				
			||||||
		var images ListView
 | 
							var images ListView
 | 
				
			||||||
		var image_list []Image
 | 
							var image_list []Image
 | 
				
			||||||
@@ -378,7 +379,6 @@ func main() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		conditions.WriteString(fmt.Sprintf(" LIMIT %d, %d", (images.Page-1)*images.PageSize, images.PageSize)) // 拼接分页条件
 | 
							conditions.WriteString(fmt.Sprintf(" LIMIT %d, %d", (images.Page-1)*images.PageSize, images.PageSize)) // 拼接分页条件
 | 
				
			||||||
		sql := fmt.Sprintf("SELECT id, width, height, content, update_time, create_time, user_id, article_id, article_category_top_id, praise_count, collect_count FROM web_images %s", conditions.String())
 | 
							sql := fmt.Sprintf("SELECT id, width, height, content, update_time, create_time, user_id, article_id, article_category_top_id, praise_count, collect_count FROM web_images %s", conditions.String())
 | 
				
			||||||
		fmt.Println("sql:", sql)
 | 
					 | 
				
			||||||
		rows, err := mysqlConnection.Database.Query(sql)
 | 
							rows, err := mysqlConnection.Database.Query(sql)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Println("获取图片列表失败", err)
 | 
								log.Println("获取图片列表失败", err)
 | 
				
			||||||
@@ -389,7 +389,6 @@ func main() {
 | 
				
			|||||||
		for rows.Next() {
 | 
							for rows.Next() {
 | 
				
			||||||
			var image Image
 | 
								var image Image
 | 
				
			||||||
			rows.Scan(&image.Id, &image.Width, &image.Height, &image.Content, &image.UpdateTime, &image.CreateTime, &image.User.ID, &image.Article.Id, &image.ArticleCategoryTopId, &image.PraiseCount, &image.CollectCount)
 | 
								rows.Scan(&image.Id, &image.Width, &image.Height, &image.Content, &image.UpdateTime, &image.CreateTime, &image.User.ID, &image.Article.Id, &image.ArticleCategoryTopId, &image.PraiseCount, &image.CollectCount)
 | 
				
			||||||
			fmt.Println("image", image.User.ID, image.Article.Id)
 | 
					 | 
				
			||||||
			image.UpdateTime = image.UpdateTime.UTC()
 | 
								image.UpdateTime = image.UpdateTime.UTC()
 | 
				
			||||||
			image.CreateTime = image.CreateTime.UTC()
 | 
								image.CreateTime = image.CreateTime.UTC()
 | 
				
			||||||
			image.Content = regexp.MustCompile(`http:`).ReplaceAllString(image.Content, "https:")
 | 
								image.Content = regexp.MustCompile(`http:`).ReplaceAllString(image.Content, "https:")
 | 
				
			||||||
@@ -426,7 +425,6 @@ func main() {
 | 
				
			|||||||
		var user_ids []int
 | 
							var user_ids []int
 | 
				
			||||||
		var article_ids []int
 | 
							var article_ids []int
 | 
				
			||||||
		for _, image := range image_list {
 | 
							for _, image := range image_list {
 | 
				
			||||||
			fmt.Println("image", image)
 | 
					 | 
				
			||||||
			user_ids = append(user_ids, image.User.ID)
 | 
								user_ids = append(user_ids, image.User.ID)
 | 
				
			||||||
			article_ids = append(article_ids, image.Article.Id)
 | 
								article_ids = append(article_ids, image.Article.Id)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -645,7 +643,6 @@ func main() {
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//fmt.Println("safeParam", safeParam)
 | 
					 | 
				
			||||||
		urls, err := models.GetVideoM3U8(safeParam)
 | 
							urls, err := models.GetVideoM3U8(safeParam)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Println("获取视频链接失败", err)
 | 
								log.Println("获取视频链接失败", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,7 +108,6 @@ type User struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 获取一组用户信息
 | 
					// 获取一组用户信息
 | 
				
			||||||
func QueryUserList(id_list []int) (users []User) {
 | 
					func QueryUserList(id_list []int) (users []User) {
 | 
				
			||||||
	fmt.Println("QueryUserList:", id_list)
 | 
					 | 
				
			||||||
	count := len(id_list)
 | 
						count := len(id_list)
 | 
				
			||||||
	if count == 0 {
 | 
						if count == 0 {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -140,7 +139,6 @@ type Article struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 获取一组文章信息
 | 
					// 获取一组文章信息
 | 
				
			||||||
func QueryArticleList(id_list []int) (articles []Article) {
 | 
					func QueryArticleList(id_list []int) (articles []Article) {
 | 
				
			||||||
	fmt.Println("QueryArticleList:", id_list)
 | 
					 | 
				
			||||||
	count := len(id_list)
 | 
						count := len(id_list)
 | 
				
			||||||
	if count == 0 {
 | 
						if count == 0 {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user