feat: gateway.

This commit is contained in:
2026-04-29 16:56:34 +08:00
parent 5f491b1375
commit f269502eac
5 changed files with 298 additions and 1 deletions
+30 -1
View File
@@ -72,6 +72,8 @@ func readDocxContentFromPath(filePath string) (string, error) {
// readCSVContent 读取 .csv 文件内容
// 修改为先保存临时文件再读取
// readCSVContent 读取 .csv 文件内容
// 修改压缩策略:每 4 行保留 1 行数据
func readCSVContent(fileHeader *multipart.FileHeader) (string, error) {
// 1. 创建临时文件
tempFile, err := os.CreateTemp("", "upload_*.csv")
@@ -100,7 +102,29 @@ func readCSVContent(fileHeader *multipart.FileHeader) (string, error) {
return "", fmt.Errorf("failed to read CSV content from temporary file: %w", err)
}
return string(content), nil
// --- 修改逻辑开始:每 4 行保留 1 行 ---
lines := strings.Split(string(content), "\n")
var compressedLines []string
for i, line := range lines {
// 1. 必须保留第一行(表头),让 AI 知道每一列是什么
if i == 0 {
compressedLines = append(compressedLines, line)
continue
}
// 2. 跳过空行
if strings.TrimSpace(line) == "" {
continue
}
if (i-1)%4 == 0 {
compressedLines = append(compressedLines, line)
}
}
resultContent := strings.Join(compressedLines, "\n")
return resultContent, nil
}
// buildAnalysisPrompt 构建发送给 AI 的提示词
@@ -213,6 +237,11 @@ func buildAnalysisPrompt(teachingPlanContent, heartRateContent, analysisType, st
// callAIForAnalysis 调用大模型进行分析
func callAIForAnalysis(prompt string) (string, error) {
sizeInBytes := len(prompt)
sizeInKB := float64(sizeInBytes) / 1024.0
// 在日志中打印大小,保留两位小数
log.Printf("=== 发送给 AI 的内容大小: %.2f KB (%d 字节) ===", sizeInKB, sizeInBytes)
baseURL, apiKey, model, err := config.GetAIConfig()
if err != nil {
return "", err