From 4bd6486a14d181cd83d34dfa83d987abdfa5cf93 Mon Sep 17 00:00:00 2001 From: laoboli <1293528695@qq.com> Date: Mon, 27 Apr 2026 15:06:22 +0800 Subject: [PATCH] refactor: test ai config. --- test/main.go | 23 ++++++++++++----------- test/util.go | 10 ---------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/test/main.go b/test/main.go index 424ac59..dd1521e 100644 --- a/test/main.go +++ b/test/main.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "hr_receiver/config" "io/ioutil" "log" "os" @@ -12,13 +13,6 @@ import ( "github.com/sashabaranov/go-openai" ) -// 配置文件 -const ( - BaseURL = "https://api.lkeap.cloud.tencent.com/v1" - APIKey = "sk-Y4zjnwulSuSlf60mrzwCxq2ipktHSs4jZHgWeQOArWuWJEOd" // 替换为实际的API Key - Model = "deepseek-v3" // 推荐使用terminus版本 -) - // 读取文件内容 func readFileContent(filename string) (string, error) { content, err := ioutil.ReadFile(filename) @@ -91,10 +85,15 @@ func analyzeClassData(teachingPlanFile, heartRateFile string) (string, error) { return "", err } + baseURL, apiKey, model, err := config.GetAIConfig() + if err != nil { + return "", err + } + // 构建客户端 - config := openai.DefaultConfig(APIKey) - config.BaseURL = BaseURL - client := openai.NewClientWithConfig(config) + clientConfig := openai.DefaultConfig(apiKey) + clientConfig.BaseURL = baseURL + client := openai.NewClientWithConfig(clientConfig) // 构建提示词 prompt := buildAnalysisPrompt(teachingPlanContent, heartRateContent) @@ -103,7 +102,7 @@ func analyzeClassData(teachingPlanFile, heartRateFile string) (string, error) { resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ - Model: Model, + Model: model, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, @@ -146,6 +145,8 @@ func getCurrentTime() string { } func main() { + config.InitConfig() + // 文件路径配置 teachingPlanFile := "D:\\projects\\IdeaProjects\\hr_receiver\\test\\b.md" heartRateFile := "D:\\projects\\IdeaProjects\\hr_receiver\\test\\b.csv" diff --git a/test/util.go b/test/util.go index 275ceed..9b81860 100644 --- a/test/util.go +++ b/test/util.go @@ -74,13 +74,3 @@ func DocxToStructuredPrompt(filename string) (string, error) { return sb.String(), nil } - -func main1() { - // 測試用 - prompt, err := docxToStructuredPrompt("D:\\myDocument\\tencent\\weChat\\WeChat Files\\wxid_pv6rg3z2l28y22\\FileStorage\\File\\2026-01\\(改)小班体育活动《蚂蚁运粮》(泉秀实幼吴思莹).docx") - if err != nil { - fmt.Println("錯誤:", err) - return - } - fmt.Println(prompt) -}