From 7c903121971b2f716b0fc668c6688160bcd1f12f Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 10 May 2025 14:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=83=E5=B8=86=E5=A4=A7?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/im.go | 16 +++++++++------- service/qianfan.go | 10 ++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/proto/im.go b/proto/im.go index bf77294..35125fe 100644 --- a/proto/im.go +++ b/proto/im.go @@ -37,13 +37,15 @@ type WSMessageReq struct { } type ModelParam struct { - Model string `json:"model"` //模型名称 - Domain string `json:"domain"` //domain参数,spark需要 - Url string `json:"url"` //模型地址 - APPID string `json:"appid"` //应用id - APISecret string `json:"apiSecret"` //应用密钥 - APIKey string `json:"apiKey"` //应用key - System string `json:"system"` //系统参数 + Model string `json:"model"` //模型名称 + Domain string `json:"domain"` //domain参数,spark需要 + Url string `json:"url"` //模型地址 + APPID string `json:"appid"` //应用id + APISecret string `json:"apiSecret"` //应用密钥 + APIKey string `json:"apiKey"` //应用key + System string `json:"system"` //系统参数 + AccessKey string `json:"access_key"` //accessKey参数 + SecretKey string `json:"Secret_key"` //secretKey参数 //其他参数 Temperature float32 `json:"temperature"` //温度,默认0.5,核采样阈值。取值越高随机性越强,即相同的问题得到的不同答案的可能性越大 MaxTokens int `json:"maxTokens"` //最大生成长度,默认4096 diff --git a/service/qianfan.go b/service/qianfan.go index 771696f..5a0332a 100644 --- a/service/qianfan.go +++ b/service/qianfan.go @@ -14,8 +14,14 @@ import ( ) func Qianfan(modelParam proto.ModelParam, imCtx *proto.IMParamContext) { - qianfan.GetConfig().AccessKey = proto.QianfanAccessKey - qianfan.GetConfig().SecretKey = proto.QianfanSecretKey + log.Println("qianfan model param:", modelParam) + log.Println("qianfan question:", imCtx.Question) + if modelParam.AccessKey == "" || modelParam.APISecret == "" { + log.Println("qianfan AccessKey or APISecret is empty") + return + } + qianfan.GetConfig().AccessKey = modelParam.AccessKey + qianfan.GetConfig().SecretKey = modelParam.APISecret chat := qianfan.NewChatCompletion(qianfan.WithModel(modelParam.Model)) var messages []qianfan.ChatCompletionMessage