修正向量请求

This commit is contained in:
2023-11-27 16:36:21 +08:00
parent c7eb29db17
commit 06ff2e1e3b
4 changed files with 14 additions and 21 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"editor.inlineSuggest.showToolbar": "always"
}

View File

@@ -106,9 +106,6 @@ func NewSchema() (graphql.Schema, error) {
for _, field := range fieldAST.SelectionSet.Selections {
fieldAST, ok := field.(*ast.Field)
if ok {
//if fieldAST.Name.Value == "avatar" {
// fieldAST.Name.Value = fmt.Sprintf("IFNULL(%s,'')", fieldAST.Name.Value)
//}
fields = append(fields, fieldAST.Name.Value)
}
}
@@ -138,7 +135,6 @@ func NewSchema() (graphql.Schema, error) {
var query strings.Builder
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
if err := connection.Select(&users, query.String()); err != nil {
fmt.Println("获取用户列表失败", err)
@@ -241,7 +237,6 @@ func NewSchema() (graphql.Schema, error) {
// 执行查询
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))
fmt.Println(query.String())
var images []Image
if err := connection.Select(&images, query.String()); err != nil {

View File

@@ -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)

View File

@@ -108,7 +108,6 @@ type User struct {
// 获取一组用户信息
func QueryUserList(id_list []int) (users []User) {
fmt.Println("QueryUserList:", id_list)
count := len(id_list)
if count == 0 {
return
@@ -140,7 +139,6 @@ type Article struct {
// 获取一组文章信息
func QueryArticleList(id_list []int) (articles []Article) {
fmt.Println("QueryArticleList:", id_list)
count := len(id_list)
if count == 0 {
return