feat: gateway.
This commit is contained in:
+30
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user