BOHE commited on
Commit
0987485
·
1 Parent(s): 6057651

修改上下文处理方式测试

Browse files
Files changed (1) hide show
  1. api/main.go +33 -8
api/main.go CHANGED
@@ -311,7 +311,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
311
 
312
  // 在历史记录中添加问答对
313
  chatHistory = append(chatHistory, ChatEntry{
314
- Question: fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s", userUploadResp.UserFilename),
315
  Answer: currentAnswer,
316
  })
317
  } else if msg.Role == "assistant" {
@@ -395,8 +395,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
395
 
396
  // 在历史记录中添加问答对
397
  chatHistory = append(chatHistory, ChatEntry{
398
- Question: fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s", userUploadResp.UserFilename),
399
- Answer: fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s", assistantUploadResp.UserFilename),
400
  })
401
  }
402
  }
@@ -426,8 +426,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
426
  // 设置基本参数
427
  q.Add("page", "1")
428
  q.Add("count", "10")
429
- q.Add("safeSearch", "Off")
430
- q.Add("mkt", "en-US")
431
  q.Add("enable_worklow_generation_ux", "true")
432
  q.Add("domain", "youchat")
433
  q.Add("use_personalization_extraction", "true")
@@ -483,8 +483,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
483
  sourcesJSON, _ := json.Marshal(sources)
484
  q.Add("sources", string(sourcesJSON))
485
 
486
- // 使用文件引用作为查询
487
- q.Add("q", fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s", uploadResp.UserFilename))
488
  } else {
489
  // 如果有之前上传的文件,添加 sources
490
  if len(sources) > 0 {
@@ -758,10 +758,35 @@ func uploadFile(dsToken, filePath string) (*UploadResponse, error) {
758
  }
759
  defer resp.Body.Close()
760
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
761
  var uploadResp UploadResponse
762
- if err := json.NewDecoder(resp.Body).Decode(&uploadResp); err != nil {
763
  return nil, err
764
  }
 
 
 
 
 
765
  return &uploadResp, nil
766
  }
767
 
 
311
 
312
  // 在历史记录中添加问答对
313
  chatHistory = append(chatHistory, ChatEntry{
314
+ Question: fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s.txt", strings.TrimSuffix(userUploadResp.UserFilename, ".txt")),
315
  Answer: currentAnswer,
316
  })
317
  } else if msg.Role == "assistant" {
 
395
 
396
  // 在历史记录中添加问答对
397
  chatHistory = append(chatHistory, ChatEntry{
398
+ Question: fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s.txt", strings.TrimSuffix(userUploadResp.UserFilename, ".txt")),
399
+ Answer: fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s.txt", strings.TrimSuffix(assistantUploadResp.UserFilename, ".txt")),
400
  })
401
  }
402
  }
 
426
  // 设置基本参数
427
  q.Add("page", "1")
428
  q.Add("count", "10")
429
+ q.Add("safeSearch", "Moderate")
430
+ q.Add("mkt", "zh-HK")
431
  q.Add("enable_worklow_generation_ux", "true")
432
  q.Add("domain", "youchat")
433
  q.Add("use_personalization_extraction", "true")
 
483
  sourcesJSON, _ := json.Marshal(sources)
484
  q.Add("sources", string(sourcesJSON))
485
 
486
+ // 使用文件引用作为查询,确保包含.txt后缀
487
+ q.Add("q", fmt.Sprintf("查看这个文件并且直接与文件内容进行聊天:%s.txt", strings.TrimSuffix(uploadResp.UserFilename, ".txt")))
488
  } else {
489
  // 如果有之前上传的文件,添加 sources
490
  if len(sources) > 0 {
 
758
  }
759
  defer resp.Body.Close()
760
 
761
+ // 打印上传响应状态码
762
+ fmt.Printf("文件上传响应状态码: %d\n", resp.StatusCode)
763
+
764
+ // 如果上传失败,记录错误响应
765
+ if resp.StatusCode != http.StatusOK {
766
+ respBody, _ := io.ReadAll(resp.Body)
767
+ fmt.Printf("文件上传错误响应内容: %s\n", string(respBody))
768
+ return nil, fmt.Errorf("上传文件失败,状态码: %d", resp.StatusCode)
769
+ }
770
+
771
+ // 先读取完整的响应体
772
+ respBody, err := io.ReadAll(resp.Body)
773
+ if err != nil {
774
+ return nil, err
775
+ }
776
+
777
+ // 打印完整的响应内容
778
+ fmt.Printf("文件上传响应内容: %s\n", string(respBody))
779
+
780
+ // 解析响应
781
  var uploadResp UploadResponse
782
+ if err := json.Unmarshal(respBody, &uploadResp); err != nil {
783
  return nil, err
784
  }
785
+
786
+ // 打印解析后的响应
787
+ fmt.Printf("上传文件成功: filename=%s, user_filename=%s\n",
788
+ uploadResp.Filename, uploadResp.UserFilename)
789
+
790
  return &uploadResp, nil
791
  }
792