Spaces:
Configuration error
Configuration error
BOHE
commited on
Commit
·
e5c3b47
1
Parent(s):
d0ca2c0
测试
Browse files- api/main.go +55 -22
api/main.go
CHANGED
|
@@ -8,7 +8,6 @@ import (
|
|
| 8 |
"io"
|
| 9 |
"mime/multipart"
|
| 10 |
"net/http"
|
| 11 |
-
"net/url"
|
| 12 |
"os"
|
| 13 |
"path/filepath"
|
| 14 |
"strings"
|
|
@@ -336,27 +335,44 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|
| 336 |
|
| 337 |
// 更新查询参数
|
| 338 |
q := youReq.URL.Query()
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
|
|
|
|
|
|
| 347 |
q.Add("page", "1")
|
| 348 |
q.Add("count", "10")
|
| 349 |
-
q.Add("safeSearch", "
|
| 350 |
-
q.Add("mkt", "
|
| 351 |
q.Add("enable_worklow_generation_ux", "true")
|
| 352 |
q.Add("domain", "youchat")
|
| 353 |
q.Add("use_personalization_extraction", "true")
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
q.Add("selectedChatMode", "custom")
|
| 356 |
q.Add("selectedAiModel", mapModelName(openAIReq.Model))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
q.Add("enable_agent_clarification_questions", "true")
|
| 358 |
q.Add("use_nested_youchat_updates", "true")
|
| 359 |
-
q.Add("
|
|
|
|
|
|
|
| 360 |
youReq.URL.RawQuery = q.Encode()
|
| 361 |
|
| 362 |
fmt.Printf("构建的请求 URL: %s\n", youReq.URL.String())
|
|
@@ -419,24 +435,41 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|
| 419 |
} else {
|
| 420 |
// 构建常规查询参数
|
| 421 |
q := youReq.URL.Query()
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
q.Add("page", "1")
|
| 428 |
q.Add("count", "10")
|
| 429 |
-
q.Add("safeSearch", "
|
| 430 |
-
q.Add("mkt", "
|
| 431 |
q.Add("enable_worklow_generation_ux", "true")
|
| 432 |
q.Add("domain", "youchat")
|
| 433 |
q.Add("use_personalization_extraction", "true")
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
q.Add("selectedChatMode", "custom")
|
| 436 |
q.Add("selectedAiModel", mapModelName(openAIReq.Model))
|
|
|
|
|
|
|
| 437 |
q.Add("enable_agent_clarification_questions", "true")
|
| 438 |
q.Add("use_nested_youchat_updates", "true")
|
| 439 |
-
q.Add("chat",
|
|
|
|
| 440 |
youReq.URL.RawQuery = q.Encode()
|
| 441 |
|
| 442 |
// 设置 You.com API 请求头
|
|
|
|
| 8 |
"io"
|
| 9 |
"mime/multipart"
|
| 10 |
"net/http"
|
|
|
|
| 11 |
"os"
|
| 12 |
"path/filepath"
|
| 13 |
"strings"
|
|
|
|
| 335 |
|
| 336 |
// 更新查询参数
|
| 337 |
q := youReq.URL.Query()
|
| 338 |
+
|
| 339 |
+
// 如果是第一次聊天(没有历史记录),使用空数组
|
| 340 |
+
chatJSON := "[]"
|
| 341 |
+
pastChatLength := "0"
|
| 342 |
+
if len(chatHistory) > 0 {
|
| 343 |
+
chatJSON = string(chatHistoryJSON)
|
| 344 |
+
pastChatLength = fmt.Sprintf("%d", len(chatHistory))
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
// 基本参数
|
| 348 |
q.Add("page", "1")
|
| 349 |
q.Add("count", "10")
|
| 350 |
+
q.Add("safeSearch", "Off") // 改为 Off
|
| 351 |
+
q.Add("mkt", "en-US") // 改为 en-US
|
| 352 |
q.Add("enable_worklow_generation_ux", "true")
|
| 353 |
q.Add("domain", "youchat")
|
| 354 |
q.Add("use_personalization_extraction", "true")
|
| 355 |
+
|
| 356 |
+
// ID 相关参数
|
| 357 |
+
q.Add("queryTraceId", chatId)
|
| 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")
|
| 372 |
q.Add("use_nested_youchat_updates", "true")
|
| 373 |
+
q.Add("q", fmt.Sprintf("Please review the attached file: %s", uploadResp.UserFilename))
|
| 374 |
+
q.Add("chat", chatJSON)
|
| 375 |
+
|
| 376 |
youReq.URL.RawQuery = q.Encode()
|
| 377 |
|
| 378 |
fmt.Printf("构建的请求 URL: %s\n", youReq.URL.String())
|
|
|
|
| 435 |
} else {
|
| 436 |
// 构建常规查询参数
|
| 437 |
q := youReq.URL.Query()
|
| 438 |
+
|
| 439 |
+
// 如果是第一次聊天(没有历史记录),使用空数组
|
| 440 |
+
chatJSON := "[]"
|
| 441 |
+
pastChatLength := "0"
|
| 442 |
+
if len(chatHistory) > 0 {
|
| 443 |
+
chatJSON = string(chatHistoryJSON)
|
| 444 |
+
pastChatLength = fmt.Sprintf("%d", len(chatHistory))
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
// 基本参数
|
| 448 |
q.Add("page", "1")
|
| 449 |
q.Add("count", "10")
|
| 450 |
+
q.Add("safeSearch", "Off") // 改为 Off
|
| 451 |
+
q.Add("mkt", "en-US") // 改为 en-US
|
| 452 |
q.Add("enable_worklow_generation_ux", "true")
|
| 453 |
q.Add("domain", "youchat")
|
| 454 |
q.Add("use_personalization_extraction", "true")
|
| 455 |
+
|
| 456 |
+
// ID 相关参数
|
| 457 |
+
q.Add("queryTraceId", chatId)
|
| 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")
|
| 470 |
q.Add("use_nested_youchat_updates", "true")
|
| 471 |
+
q.Add("chat", chatJSON)
|
| 472 |
+
|
| 473 |
youReq.URL.RawQuery = q.Encode()
|
| 474 |
|
| 475 |
// 设置 You.com API 请求头
|