修正向量请求
This commit is contained in:
25
bin/main.go
25
bin/main.go
@@ -103,27 +103,31 @@ func GetNetWorkEmbedding(id int) (embedding []float32) {
|
||||
httpClient := &http.Client{}
|
||||
request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s:%d/api/default/%d", host, port, id), nil)
|
||||
if err != nil {
|
||||
log.Println("请求失败:", err)
|
||||
log.Println("请求失败1:", err)
|
||||
return
|
||||
}
|
||||
response, err := httpClient.Do(request)
|
||||
if err != nil {
|
||||
log.Println("请求失败:", err)
|
||||
log.Println("请求失败2:", err)
|
||||
return
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
log.Println("解析失败:", err)
|
||||
return
|
||||
}
|
||||
if result["code"] != 0 {
|
||||
log.Println("请求失败:", result["message"])
|
||||
if result.Code != 0 {
|
||||
log.Println("请求失败3:", result.Message)
|
||||
return
|
||||
}
|
||||
embedding = result["feature"].([]float32)
|
||||
return embedding
|
||||
return result.Feature
|
||||
}
|
||||
|
||||
func (image *Image) GetSimilarImagesIdList(collection_name string) (ids []int64) {
|
||||
@@ -311,7 +315,6 @@ func main() {
|
||||
}
|
||||
if len(text_ids) > 0 {
|
||||
conditions.WriteString(fmt.Sprintf(" WHERE id IN (%s)", strings.Trim(strings.Replace(fmt.Sprint(text_ids), " ", ",", -1), "[]")))
|
||||
fmt.Println("conditions", conditions.String())
|
||||
} else {
|
||||
// 直接返回空列表
|
||||
var images ListView
|
||||
@@ -338,8 +341,6 @@ func main() {
|
||||
addCondition(&conditions, "sets", "sets")
|
||||
}
|
||||
|
||||
fmt.Println("conditions", conditions.String())
|
||||
|
||||
// 获取图片列表
|
||||
var images ListView
|
||||
var image_list []Image
|
||||
@@ -378,7 +379,6 @@ func main() {
|
||||
}
|
||||
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())
|
||||
fmt.Println("sql:", sql)
|
||||
rows, err := mysqlConnection.Database.Query(sql)
|
||||
if err != nil {
|
||||
log.Println("获取图片列表失败", err)
|
||||
@@ -389,7 +389,6 @@ func main() {
|
||||
for rows.Next() {
|
||||
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)
|
||||
fmt.Println("image", image.User.ID, image.Article.Id)
|
||||
image.UpdateTime = image.UpdateTime.UTC()
|
||||
image.CreateTime = image.CreateTime.UTC()
|
||||
image.Content = regexp.MustCompile(`http:`).ReplaceAllString(image.Content, "https:")
|
||||
@@ -426,7 +425,6 @@ func main() {
|
||||
var user_ids []int
|
||||
var article_ids []int
|
||||
for _, image := range image_list {
|
||||
fmt.Println("image", image)
|
||||
user_ids = append(user_ids, image.User.ID)
|
||||
article_ids = append(article_ids, image.Article.Id)
|
||||
}
|
||||
@@ -645,7 +643,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
//fmt.Println("safeParam", safeParam)
|
||||
urls, err := models.GetVideoM3U8(safeParam)
|
||||
if err != nil {
|
||||
log.Println("获取视频链接失败", err)
|
||||
|
Reference in New Issue
Block a user