Spaces:
Configuration error
Configuration error
BOHE
commited on
Commit
·
82167ec
1
Parent(s):
afee268
修改上下文处理方式测试
Browse files- api/main.go +15 -8
api/main.go
CHANGED
|
@@ -285,8 +285,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|
| 285 |
shortFileName := generateShortFileName()
|
| 286 |
userTempFile := shortFileName + ".txt"
|
| 287 |
|
| 288 |
-
// 确保使用UTF-8
|
| 289 |
-
if err := os.WriteFile(userTempFile,
|
| 290 |
fmt.Printf("创建用户临时文件失败: %v\n", err)
|
| 291 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 292 |
return
|
|
@@ -333,8 +333,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|
| 333 |
userShortFileName := generateShortFileName()
|
| 334 |
userTempFile := userShortFileName + ".txt"
|
| 335 |
|
| 336 |
-
// 确保使用UTF-8
|
| 337 |
-
if err := os.WriteFile(userTempFile,
|
| 338 |
fmt.Printf("创建用户临时文件失败: %v\n", err)
|
| 339 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 340 |
return
|
|
@@ -369,8 +369,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|
| 369 |
assistantShortFileName := generateShortFileName()
|
| 370 |
assistantTempFile := assistantShortFileName + ".txt"
|
| 371 |
|
| 372 |
-
// 确保使用UTF-8
|
| 373 |
-
if err := os.WriteFile(assistantTempFile,
|
| 374 |
fmt.Printf("创建助手临时文件失败: %v\n", err)
|
| 375 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 376 |
return
|
|
@@ -455,8 +455,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|
| 455 |
shortFileName := generateShortFileName()
|
| 456 |
tempFile := shortFileName + ".txt"
|
| 457 |
|
| 458 |
-
// 确保使用UTF-8
|
| 459 |
-
if err := os.WriteFile(tempFile,
|
| 460 |
fmt.Printf("创建临时文件失败: %v\n", err)
|
| 461 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 462 |
return
|
|
@@ -824,3 +824,10 @@ func convertSystemToUser(messages []Message) []Message {
|
|
| 824 |
|
| 825 |
return newMessages
|
| 826 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
shortFileName := generateShortFileName()
|
| 286 |
userTempFile := shortFileName + ".txt"
|
| 287 |
|
| 288 |
+
// 确保使用UTF-8编码写入文件,添加BOM标记
|
| 289 |
+
if err := os.WriteFile(userTempFile, addUTF8BOM(currentQuestion), 0644); err != nil {
|
| 290 |
fmt.Printf("创建用户临时文件失败: %v\n", err)
|
| 291 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 292 |
return
|
|
|
|
| 333 |
userShortFileName := generateShortFileName()
|
| 334 |
userTempFile := userShortFileName + ".txt"
|
| 335 |
|
| 336 |
+
// 确保使用UTF-8编码写入文件,添加BOM标记
|
| 337 |
+
if err := os.WriteFile(userTempFile, addUTF8BOM(currentQuestion), 0644); err != nil {
|
| 338 |
fmt.Printf("创建用户临时文件失败: %v\n", err)
|
| 339 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 340 |
return
|
|
|
|
| 369 |
assistantShortFileName := generateShortFileName()
|
| 370 |
assistantTempFile := assistantShortFileName + ".txt"
|
| 371 |
|
| 372 |
+
// 确保使用UTF-8编码写入文件,添加BOM标记
|
| 373 |
+
if err := os.WriteFile(assistantTempFile, addUTF8BOM(currentAnswer), 0644); err != nil {
|
| 374 |
fmt.Printf("创建助手临时文件失败: %v\n", err)
|
| 375 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 376 |
return
|
|
|
|
| 455 |
shortFileName := generateShortFileName()
|
| 456 |
tempFile := shortFileName + ".txt"
|
| 457 |
|
| 458 |
+
// 确保使用UTF-8编码写入文件,添加BOM标记
|
| 459 |
+
if err := os.WriteFile(tempFile, addUTF8BOM(lastMessage.Content), 0644); err != nil {
|
| 460 |
fmt.Printf("创建临时文件失败: %v\n", err)
|
| 461 |
http.Error(w, "Failed to create temp file", http.StatusInternalServerError)
|
| 462 |
return
|
|
|
|
| 824 |
|
| 825 |
return newMessages
|
| 826 |
}
|
| 827 |
+
|
| 828 |
+
// 添加UTF-8 BOM标记的函数
|
| 829 |
+
func addUTF8BOM(content string) []byte {
|
| 830 |
+
// UTF-8 BOM: EF BB BF
|
| 831 |
+
bom := []byte{0xEF, 0xBB, 0xBF}
|
| 832 |
+
return append(bom, []byte(content)...)
|
| 833 |
+
}
|