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

✨ feat: add SenseNova (商汤) model provider #4162

Open
wants to merge 57 commits into
base: main
Choose a base branch
from

Conversation

hezhijie0327
Copy link
Contributor

@hezhijie0327 hezhijie0327 commented Sep 26, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

  1. 使用 OpenAI 兼容模式,初步实现对话
  2. 覆写 frequency_penaltytop_p 范围 [TODO] https://console.sensecore.cn/help/docs/model-as-a-service/nova/chat/ChatCompletions/ChatCompletion
  3. 禁用客户端模式,不支持
  4. 更新模型列表,版本 [TODO]
  5. 添加商汤图标 [TODO] [Request] 帮忙增加下 SenseChat (SenseNova / SenseCore) 模型 Icon lobe-icons#43
  6. APIToken 计算逻辑如下
    a. 输入 AccessKeyIDAccessKeySecret,使用 : 进行拼接存入 apiKey
    b. 计算时以 : 进行拆分,并按照官网文档参数进行 JWT 计算,并返回 apiKey
    c. APIToken 有效期为当前时间的 -5s 至 +1800s,每次对话前会重新计算

Note:
1. 获取临时 TOKEN:https://console.sensecore.cn/iam/Security/private-security
2. 创建有效期 TOKEN: https://console.sensecore.cn/help/docs/model-as-a-service/nova/overview/Authorization
3. SenseChat-Vision 不支持 Base64 URL

📝 补充信息 | Additional Information

对话
image
工具调用
image
多模态
image
模型列表
image
image

Copy link

vercel bot commented Sep 26, 2024

@hezhijie0327 is attempting to deploy a commit to the LobeHub Pro Team on Vercel.

A member of the Team first needs to authorize it.

@lobehubbot
Copy link
Member

👍 @hezhijie0327

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 92.50000% with 24 lines in your changes missing coverage. Please review.

Project coverage is 92.21%. Comparing base (04b58f8) to head (91bc2d2).

Files with missing lines Patch % Lines
src/services/_auth.ts 14.28% 12 Missing ⚠️
src/server/modules/AgentRuntime/index.ts 10.00% 9 Missing ⚠️
src/libs/agent-runtime/AgentRuntime.ts 57.14% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #4162    +/-   ##
========================================
  Coverage   92.21%   92.21%            
========================================
  Files         493      496     +3     
  Lines       35390    35710   +320     
  Branches     3403     3430    +27     
========================================
+ Hits        32634    32930   +296     
- Misses       2756     2780    +24     
Flag Coverage Δ
app 92.21% <92.50%> (+<0.01%) ⬆️
server 97.37% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Codecov Report

Attention: Patch coverage is 94.88636% with 9 lines in your changes missing coverage. Please review.

Project coverage is 92.49%. Comparing base (40d347f) to head (68dd185).

Files with missing lines Patch % Lines
src/app/api/chat/agentRuntime.ts 14.28% 6 Missing ⚠️
src/libs/agent-runtime/AgentRuntime.ts 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4162      +/-   ##
==========================================
+ Coverage   92.48%   92.49%   +0.01%     
==========================================
  Files         482      484       +2     
  Lines       34488    34664     +176     
  Branches     3231     2139    -1092     
==========================================
+ Hits        31896    32063     +167     
- Misses       2592     2601       +9     
Flag Coverage Δ
app 92.49% <94.88%> (+0.01%) ⬆️
server ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LovelyGuYiMeng
Copy link
Contributor

LovelyGuYiMeng commented Sep 26, 2024

商汤的话,根据模型和体量,我建议放在零一万物和阶跃星辰中间
模型排序推荐如下样式:
SenseChat 5.5
SenseChat 5.5 Vision
SenseChat 5.0 Cantonese
SenseChat 5.0 Turbo
SenseChat 4.0
SenseChat 4.0 32k
SenseChat 4.0 128k
SenseChat Character
SenseChat Character Pro
默认开启就除了Cantonese和Character都开吧

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


As for Shangtang, based on the model and volume, I suggest placing it between Zero One Thing and Stepping Stars.
The following style is recommended for model sorting:
SenseChat 5.5
SenseChat 5.0 (128K)
SenseChat 5.0 Cantonese
SenseChat 5.0 Turbo
SenseChat 5.0 Vision
SenseChat 4.0
SenseChat 4.0 32k
SenseChat Character
SenseChat Character Pro
5.5, 5.0 (except Cantonese), 4.0 and Character are not enabled by default.

@LovelyGuYiMeng
Copy link
Contributor

128K模型是4.0,vision模型是5.5
image
image

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The 128K model is 4.0 and the vision model is 5.5
image
image

@hezhijie0327
Copy link
Contributor Author

欸 这个等计算 API_TOKEN 这个做完并过去再改,先放 TODO...

商汤这个非固定 API Key 有点意思

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Well, wait until the calculation of API_TOKEN is completed and then change it. Put TODO first...

SenseTime’s non-fixed API Key is a bit interesting

@hezhijie0327
Copy link
Contributor Author

@LovelyGuYiMeng 这个模型版本有点歧义,官网的几个文档信息貌似没同步... 由于模型广场中有更新时间,采信度较高,目前以这个为主

https://console.sensecore.cn/help/docs/model-as-a-service/nova/model/llm/GeneralLLM
image

https://platform.sensenova.cn/doc?path=/model/llm/GeneralLLM.md
image

https://console.sensecore.cn/aistudio/plaza?sort=sort_default&page=1&size=24
image

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@LovelyGuYiMeng This model version is a bit ambiguous. Several document information on the official website seems to be out of sync... Since there is an update time in the model square, it has a high degree of acceptance. Currently, this is the main one.

https://console.sensecore.cn/help/docs/model-as-a-service/nova/model/llm/GeneralLLM
image

https://platform.sensenova.cn/doc?path=/model/llm/GeneralLLM.md
image

https://console.sensecore.cn/aistudio/plaza?sort=sort_default&page=1&size=24
image

@hezhijie0327 hezhijie0327 marked this pull request as ready for review September 27, 2024 14:11
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🌠 Feature Request New feature or request | 特性与建议 labels Sep 27, 2024
@LovelyGuYiMeng
Copy link
Contributor

LovelyGuYiMeng commented Sep 27, 2024

我个人感觉https://platform.sensenova.cn/doc?path=/model/llm/GeneralLLM.md 的正确
另外你再看这个价格列表的模型版本号,也是一样https://platform.sensenova.cn/pricing
再不确定的话我已经发邮件问商汤支持了,等回复看看也行

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I personally feel that https://platform.sensenova.cn/doc?path=/model/llm/GeneralLLM.md is correct
In addition, if you look at the model version number of this price list, it is the same https://platform.sensenova.cn/pricing
If you are still unsure, I have already sent an email to ask SenseTime for support. I will wait and see for the reply.

@hezhijie0327
Copy link
Contributor Author

已更新 i18n
image
image
image

src/services/_auth.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,34 @@
import CryptoJS from 'crypto-js';
Copy link
Contributor

Choose a reason for hiding this comment

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

crypto-js 是 Nodejs 的模块吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

外部模块,原生的 crypto 不支持 edge 环境...

jose 能生成 token 但是异步调用有点问题,暂时想不出来该咋解了...
image

Copy link
Contributor

Choose a reason for hiding this comment

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

jose 可能会有个问题是不支持 http 协议? 如果直接用 jose 的话感觉可以试试我之前给 zhipu 做的方案:

await LobeZhipuAI.fromAPIKey(params.zhipu);

static async fromAPIKey({ apiKey, baseURL = DEFAULT_BASE_URL, ...res }: ClientOptions = {}) {
const invalidZhipuAPIKey = AgentRuntimeError.createError(
AgentRuntimeErrorType.InvalidProviderAPIKey,
);
if (!apiKey) throw invalidZhipuAPIKey;
let token: string;
try {
token = await generateApiToken(apiKey);
} catch {
throw invalidZhipuAPIKey;
}
const header = { Authorization: `Bearer ${token}` };
const llm = new OpenAI({ apiKey, baseURL, defaultHeaders: header, ...res });
return new LobeZhipuAI(llm);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

jose 走异步,createRuntime 这里方法就调用不了,仅实现了从环境变量生成,暂时回退回去用 crypto-js

Copy link
Contributor

Choose a reason for hiding this comment

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

为啥要走 createRuntime 呢?之前我给zhipu 初始化就是用的异步方案。 Wenxin 创建独立runtime 是因为它的sdk不支持edge runtime。 如果能用 jose 解决签名问题,感觉没有必要用createRuntime 吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

哎 有点绕不出来了,没啥思路...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

跑通了

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌠 Feature Request New feature or request | 特性与建议 size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants