refactor: test ai config.
This commit is contained in:
+12
-11
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hr_receiver/config"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -12,13 +13,6 @@ import (
|
|||||||
"github.com/sashabaranov/go-openai"
|
"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) {
|
func readFileContent(filename string) (string, error) {
|
||||||
content, err := ioutil.ReadFile(filename)
|
content, err := ioutil.ReadFile(filename)
|
||||||
@@ -91,10 +85,15 @@ func analyzeClassData(teachingPlanFile, heartRateFile string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseURL, apiKey, model, err := config.GetAIConfig()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
// 构建客户端
|
// 构建客户端
|
||||||
config := openai.DefaultConfig(APIKey)
|
clientConfig := openai.DefaultConfig(apiKey)
|
||||||
config.BaseURL = BaseURL
|
clientConfig.BaseURL = baseURL
|
||||||
client := openai.NewClientWithConfig(config)
|
client := openai.NewClientWithConfig(clientConfig)
|
||||||
|
|
||||||
// 构建提示词
|
// 构建提示词
|
||||||
prompt := buildAnalysisPrompt(teachingPlanContent, heartRateContent)
|
prompt := buildAnalysisPrompt(teachingPlanContent, heartRateContent)
|
||||||
@@ -103,7 +102,7 @@ func analyzeClassData(teachingPlanFile, heartRateFile string) (string, error) {
|
|||||||
resp, err := client.CreateChatCompletion(
|
resp, err := client.CreateChatCompletion(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
openai.ChatCompletionRequest{
|
openai.ChatCompletionRequest{
|
||||||
Model: Model,
|
Model: model,
|
||||||
Messages: []openai.ChatCompletionMessage{
|
Messages: []openai.ChatCompletionMessage{
|
||||||
{
|
{
|
||||||
Role: openai.ChatMessageRoleUser,
|
Role: openai.ChatMessageRoleUser,
|
||||||
@@ -146,6 +145,8 @@ func getCurrentTime() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
config.InitConfig()
|
||||||
|
|
||||||
// 文件路径配置
|
// 文件路径配置
|
||||||
teachingPlanFile := "D:\\projects\\IdeaProjects\\hr_receiver\\test\\b.md"
|
teachingPlanFile := "D:\\projects\\IdeaProjects\\hr_receiver\\test\\b.md"
|
||||||
heartRateFile := "D:\\projects\\IdeaProjects\\hr_receiver\\test\\b.csv"
|
heartRateFile := "D:\\projects\\IdeaProjects\\hr_receiver\\test\\b.csv"
|
||||||
|
|||||||
@@ -74,13 +74,3 @@ func DocxToStructuredPrompt(filename string) (string, error) {
|
|||||||
|
|
||||||
return sb.String(), nil
|
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)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user