refactor: test ai config.
This commit is contained in:
+12
-11
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user