refactor: ai config.
This commit is contained in:
+10
-11
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"hr_receiver/config"
|
||||
"hr_receiver/util"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -16,13 +17,6 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// 配置文件 (与 main.go 保持一致)
|
||||
const (
|
||||
BaseURL = "https://api.lkeap.cloud.tencent.com/v1"
|
||||
APIKey = "sk-Y4zjnwulSuSlf60mrzwCxq2ipktHSs4jZHgWeQOArWuWJEOd" // 请替换为实际的 API Key
|
||||
Model = "deepseek-v3"
|
||||
)
|
||||
|
||||
// readDocxContent 读取 .docx 文件并将其转换为结构化文本
|
||||
// 修改为先保存临时文件再读取
|
||||
func readDocxContent(fileHeader *multipart.FileHeader) (string, error) {
|
||||
@@ -143,14 +137,19 @@ func buildAnalysisPrompt(teachingPlanContent, heartRateContent string) string {
|
||||
|
||||
// callAIForAnalysis 调用大模型进行分析
|
||||
func callAIForAnalysis(prompt string) (string, error) {
|
||||
config := openai.DefaultConfig(APIKey)
|
||||
config.BaseURL = BaseURL
|
||||
client := openai.NewClientWithConfig(config)
|
||||
baseURL, apiKey, model, err := config.GetAIConfig()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
clientConfig := openai.DefaultConfig(apiKey)
|
||||
clientConfig.BaseURL = baseURL
|
||||
client := openai.NewClientWithConfig(clientConfig)
|
||||
|
||||
resp, err := client.CreateChatCompletion(
|
||||
context.Background(),
|
||||
openai.ChatCompletionRequest{
|
||||
Model: Model,
|
||||
Model: model,
|
||||
Messages: []openai.ChatCompletionMessage{
|
||||
{
|
||||
Role: openai.ChatMessageRoleUser,
|
||||
|
||||
Reference in New Issue
Block a user