Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

适配讯飞星火4.0模型,新增讯飞星火自定义prompt功能 #239

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/xunfei/xunfei.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const appID = env.XUNFEI_APP_ID
const apiKey = env.XUNFEI_API_KEY
const apiSecret = env.XUNFEI_API_SECRET
// 地址必须填写,代表着大模型的版本号!!!!!!!!!!!!!!!!
const httpUrl = new URL('https://spark-api.xf-yun.com/v3.5/chat')
const httpUrl = new URL('https://spark-api.xf-yun.com/v4.0/chat')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是现在将版本号放到 env 里去配置更好,因为默认的会导致部分用户不看代码,不知道为什么匹配不上模型

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改,.env里面也有说明


// 新增用户自定义prompt设定
const prompt = env.XUNFEI_PROMPT

let modelDomain // V1.1-V3.5动态获取,高于以上版本手动指定
function authenticate() {
Expand All @@ -29,6 +32,15 @@ function authenticate() {
case '/v3.5/chat':
modelDomain = 'generalv3.5'
break
case '/chat/pro-128k':
modelDomain = 'pro-128k'
break
case '/chat/max-32k':
modelDomain = 'max-32k'
break
case '/v4.0/chat':
modelDomain = '4.0Ultra'
break
}

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -77,8 +89,9 @@ export async function xunfeiSendMsg(inputVal) {
// 如果想获取结合上下文的回答,需要开发者每次将历史问答信息一起传给服务端,如下示例
// 注意:text里面的所有content内容加一起的tokens需要控制在8192以内,开发者如有较长对话需求,需要适当裁剪历史信息
text: [
{ role: 'user', content: '你是谁' }, //# 用户的历史问题
{ role: 'assistant', content: '你是一个专业的智能助手' }, //# AI的历史回答结果
// { role: 'user', content: '你是谁' }, //# 用户的历史问题
{ role: 'system', content: prompt }, //# 自行设定的prompt
// { role: 'assistant', content: '你是一个专业的智能助手' }, //# AI的历史回答结果
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里做一下兼容处理,如果没填自定义 prompt 还用之前的

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prompt已做处理

// ....... 省略的历史对话
{ role: 'user', content: inputVal }, //# 最新的一条问题,如无需上下文,可只传最新一条问题
],
Expand Down