BOHE commited on
Commit
649cbef
·
1 Parent(s): e5c3b47
Files changed (1) hide show
  1. api/main.go +29 -5
api/main.go CHANGED
@@ -343,6 +343,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
343
  chatJSON = string(chatHistoryJSON)
344
  pastChatLength = fmt.Sprintf("%d", len(chatHistory))
345
  }
 
346
 
347
  // 基本参数
348
  q.Add("page", "1")
@@ -358,14 +359,18 @@ func Handler(w http.ResponseWriter, r *http.Request) {
358
  q.Add("chatId", chatId)
359
  q.Add("conversationTurnId", conversationTurnId)
360
  q.Add("traceId", traceId)
 
361
 
362
  // 聊天相关参数
363
  q.Add("pastChatLength", pastChatLength)
364
  q.Add("selectedChatMode", "custom")
365
  q.Add("selectedAiModel", mapModelName(openAIReq.Model))
 
366
 
367
  // 文件源信息
368
- q.Add("sources", string(sourcesJSON)) // 不需要额外的 URL 编码
 
 
369
 
370
  // 其他参数
371
  q.Add("enable_agent_clarification_questions", "true")
@@ -375,7 +380,12 @@ func Handler(w http.ResponseWriter, r *http.Request) {
375
 
376
  youReq.URL.RawQuery = q.Encode()
377
 
378
- fmt.Printf("构建的请求 URL: %s\n", youReq.URL.String())
 
 
 
 
 
379
 
380
  // 设置请求头
381
  youReq.Header = http.Header{
@@ -403,6 +413,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
403
  cookieStrings = append(cookieStrings, fmt.Sprintf("%s=%s", name, value))
404
  }
405
  youReq.Header.Add("Cookie", strings.Join(cookieStrings, ";"))
 
 
406
 
407
  // 发送请求并获取响应
408
  client := &http.Client{}
@@ -443,6 +455,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
443
  chatJSON = string(chatHistoryJSON)
444
  pastChatLength = fmt.Sprintf("%d", len(chatHistory))
445
  }
 
446
 
447
  // 基本参数
448
  q.Add("page", "1")
@@ -458,12 +471,14 @@ func Handler(w http.ResponseWriter, r *http.Request) {
458
  q.Add("chatId", chatId)
459
  q.Add("conversationTurnId", conversationTurnId)
460
  q.Add("traceId", traceId)
 
461
 
462
  // 聊天相关参数
463
  q.Add("q", openAIReq.Messages[len(openAIReq.Messages)-1].Content)
464
  q.Add("pastChatLength", pastChatLength)
465
  q.Add("selectedChatMode", "custom")
466
  q.Add("selectedAiModel", mapModelName(openAIReq.Model))
 
467
 
468
  // 其他参数
469
  q.Add("enable_agent_clarification_questions", "true")
@@ -472,7 +487,14 @@ func Handler(w http.ResponseWriter, r *http.Request) {
472
 
473
  youReq.URL.RawQuery = q.Encode()
474
 
475
- // 设置 You.com API 请求头
 
 
 
 
 
 
 
476
  youReq.Header = http.Header{
477
  "sec-ch-ua-platform": {"Windows"},
478
  "Cache-Control": {"no-cache"},
@@ -482,7 +504,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
482
  "sec-ch-ua-mobile": {"?0"},
483
  "sec-ch-ua-arch": {"x86"},
484
  "sec-ch-ua-full-version": {"133.0.3065.39"},
485
- "Accept": {"text/event-stream"}, // 重要:接受 SSE 流
486
  "User-Agent": {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"},
487
  "sec-ch-ua-platform-version": {"19.0.0"},
488
  "Sec-Fetch-Site": {"same-origin"},
@@ -491,13 +513,15 @@ func Handler(w http.ResponseWriter, r *http.Request) {
491
  "Host": {"you.com"},
492
  }
493
 
494
- // 设置 You.com API 请求的 Cookie
495
  cookies := getCookies(dsToken)
496
  var cookieStrings []string
497
  for name, value := range cookies {
498
  cookieStrings = append(cookieStrings, fmt.Sprintf("%s=%s", name, value))
499
  }
500
  youReq.Header.Add("Cookie", strings.Join(cookieStrings, ";"))
 
 
501
 
502
  // 根据 OpenAI 请求的 stream 参数选择处理函数
503
  if !openAIReq.Stream {
 
343
  chatJSON = string(chatHistoryJSON)
344
  pastChatLength = fmt.Sprintf("%d", len(chatHistory))
345
  }
346
+ fmt.Printf("聊天历史状态: chatJSON=%s, pastChatLength=%s\n", chatJSON, pastChatLength)
347
 
348
  // 基本参数
349
  q.Add("page", "1")
 
359
  q.Add("chatId", chatId)
360
  q.Add("conversationTurnId", conversationTurnId)
361
  q.Add("traceId", traceId)
362
+ fmt.Printf("生成的 ID: chatId=%s, conversationTurnId=%s, traceId=%s\n", chatId, conversationTurnId, traceId)
363
 
364
  // 聊天相关参数
365
  q.Add("pastChatLength", pastChatLength)
366
  q.Add("selectedChatMode", "custom")
367
  q.Add("selectedAiModel", mapModelName(openAIReq.Model))
368
+ fmt.Printf("模型信息: 原始模型=%s, 映射后模型=%s\n", openAIReq.Model, mapModelName(openAIReq.Model))
369
 
370
  // 文件源信息
371
+ sourcesJSONStr := string(sourcesJSON)
372
+ q.Add("sources", sourcesJSONStr)
373
+ fmt.Printf("文件源信息: %s\n", sourcesJSONStr)
374
 
375
  // 其他参数
376
  q.Add("enable_agent_clarification_questions", "true")
 
380
 
381
  youReq.URL.RawQuery = q.Encode()
382
 
383
+ fmt.Printf("\n=== 完整请求信息 ===\n")
384
+ fmt.Printf("请求 URL: %s\n", youReq.URL.String())
385
+ fmt.Printf("请求头:\n")
386
+ for key, values := range youReq.Header {
387
+ fmt.Printf("%s: %v\n", key, values)
388
+ }
389
 
390
  // 设置请求头
391
  youReq.Header = http.Header{
 
413
  cookieStrings = append(cookieStrings, fmt.Sprintf("%s=%s", name, value))
414
  }
415
  youReq.Header.Add("Cookie", strings.Join(cookieStrings, ";"))
416
+ fmt.Printf("Cookie: %s\n", strings.Join(cookieStrings, ";"))
417
+ fmt.Printf("===================\n\n")
418
 
419
  // 发送请求并获取响应
420
  client := &http.Client{}
 
455
  chatJSON = string(chatHistoryJSON)
456
  pastChatLength = fmt.Sprintf("%d", len(chatHistory))
457
  }
458
+ fmt.Printf("聊天历史状态: chatJSON=%s, pastChatLength=%s\n", chatJSON, pastChatLength)
459
 
460
  // 基本参数
461
  q.Add("page", "1")
 
471
  q.Add("chatId", chatId)
472
  q.Add("conversationTurnId", conversationTurnId)
473
  q.Add("traceId", traceId)
474
+ fmt.Printf("生成的 ID: chatId=%s, conversationTurnId=%s, traceId=%s\n", chatId, conversationTurnId, traceId)
475
 
476
  // 聊天相关参数
477
  q.Add("q", openAIReq.Messages[len(openAIReq.Messages)-1].Content)
478
  q.Add("pastChatLength", pastChatLength)
479
  q.Add("selectedChatMode", "custom")
480
  q.Add("selectedAiModel", mapModelName(openAIReq.Model))
481
+ fmt.Printf("模型信息: 原始模型=%s, 映射后模型=%s\n", openAIReq.Model, mapModelName(openAIReq.Model))
482
 
483
  // 其他参数
484
  q.Add("enable_agent_clarification_questions", "true")
 
487
 
488
  youReq.URL.RawQuery = q.Encode()
489
 
490
+ fmt.Printf("\n=== 完整请求信息 ===\n")
491
+ fmt.Printf("请求 URL: %s\n", youReq.URL.String())
492
+ fmt.Printf("请求头:\n")
493
+ for key, values := range youReq.Header {
494
+ fmt.Printf("%s: %v\n", key, values)
495
+ }
496
+
497
+ // 设置请求头
498
  youReq.Header = http.Header{
499
  "sec-ch-ua-platform": {"Windows"},
500
  "Cache-Control": {"no-cache"},
 
504
  "sec-ch-ua-mobile": {"?0"},
505
  "sec-ch-ua-arch": {"x86"},
506
  "sec-ch-ua-full-version": {"133.0.3065.39"},
507
+ "Accept": {"text/event-stream"},
508
  "User-Agent": {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"},
509
  "sec-ch-ua-platform-version": {"19.0.0"},
510
  "Sec-Fetch-Site": {"same-origin"},
 
513
  "Host": {"you.com"},
514
  }
515
 
516
+ // 设置 Cookie
517
  cookies := getCookies(dsToken)
518
  var cookieStrings []string
519
  for name, value := range cookies {
520
  cookieStrings = append(cookieStrings, fmt.Sprintf("%s=%s", name, value))
521
  }
522
  youReq.Header.Add("Cookie", strings.Join(cookieStrings, ";"))
523
+ fmt.Printf("Cookie: %s\n", strings.Join(cookieStrings, ";"))
524
+ fmt.Printf("===================\n\n")
525
 
526
  // 根据 OpenAI 请求的 stream 参数选择处理函数
527
  if !openAIReq.Stream {