Commit
·
d2e955e
1
Parent(s):
c393ddc
VolcEngine SDK V3 adaptation (#2082)
Browse files1) Configuration interface update
2) Back-end adaptation API update
Note: The official no longer supports the Skylark1/2 series, and all
have been switched to the Doubao series

### What problem does this PR solve?
_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
Co-authored-by: 海贼宅 <stu_xyx@163.com>
api/apps/llm_app.py
CHANGED
|
@@ -113,13 +113,10 @@ def add_llm():
|
|
| 113 |
|
| 114 |
if factory == "VolcEngine":
|
| 115 |
# For VolcEngine, due to its special authentication method
|
| 116 |
-
# Assemble
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
api_key = '{' + f'"volc_ak": "{req.get("volc_ak", "")}", ' \
|
| 121 |
-
f'"volc_sk": "{req.get("volc_sk", "")}", ' \
|
| 122 |
-
f'"ep_id": "{endpoint_id}", ' + '}'
|
| 123 |
elif factory == "Tencent Hunyuan":
|
| 124 |
api_key = '{' + f'"hunyuan_sid": "{req.get("hunyuan_sid", "")}", ' \
|
| 125 |
f'"hunyuan_sk": "{req.get("hunyuan_sk", "")}"' + '}'
|
|
|
|
| 113 |
|
| 114 |
if factory == "VolcEngine":
|
| 115 |
# For VolcEngine, due to its special authentication method
|
| 116 |
+
# Assemble ark_api_key endpoint_id into api_key
|
| 117 |
+
llm_name = req["llm_name"]
|
| 118 |
+
api_key = '{' + f'"ark_api_key": "{req.get("ark_api_key", "")}", ' \
|
| 119 |
+
f'"ep_id": "{req.get("endpoint_id", "")}", ' + '}'
|
|
|
|
|
|
|
|
|
|
| 120 |
elif factory == "Tencent Hunyuan":
|
| 121 |
api_key = '{' + f'"hunyuan_sid": "{req.get("hunyuan_sid", "")}", ' \
|
| 122 |
f'"hunyuan_sk": "{req.get("hunyuan_sk", "")}"' + '}'
|
conf/llm_factories.json
CHANGED
|
@@ -349,13 +349,19 @@
|
|
| 349 |
"status": "1",
|
| 350 |
"llm": [
|
| 351 |
{
|
| 352 |
-
"llm_name": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
"tags": "LLM,CHAT,32k",
|
| 354 |
"max_tokens": 32768,
|
| 355 |
"model_type": "chat"
|
| 356 |
},
|
| 357 |
{
|
| 358 |
-
"llm_name": "
|
| 359 |
"tags": "LLM,CHAT,4k",
|
| 360 |
"max_tokens": 4096,
|
| 361 |
"model_type": "chat"
|
|
|
|
| 349 |
"status": "1",
|
| 350 |
"llm": [
|
| 351 |
{
|
| 352 |
+
"llm_name": "Doubao-pro-128k",
|
| 353 |
+
"tags": "LLM,CHAT,128k",
|
| 354 |
+
"max_tokens": 131072,
|
| 355 |
+
"model_type": "chat"
|
| 356 |
+
},
|
| 357 |
+
{
|
| 358 |
+
"llm_name": "Doubao-pro-32k",
|
| 359 |
"tags": "LLM,CHAT,32k",
|
| 360 |
"max_tokens": 32768,
|
| 361 |
"model_type": "chat"
|
| 362 |
},
|
| 363 |
{
|
| 364 |
+
"llm_name": "Doubao-pro-4k",
|
| 365 |
"tags": "LLM,CHAT,4k",
|
| 366 |
"max_tokens": 4096,
|
| 367 |
"model_type": "chat"
|
rag/llm/chat_model.py
CHANGED
|
@@ -450,72 +450,16 @@ class LocalLLM(Base):
|
|
| 450 |
|
| 451 |
|
| 452 |
class VolcEngineChat(Base):
|
| 453 |
-
def __init__(self, key, model_name, base_url):
|
| 454 |
"""
|
| 455 |
Since do not want to modify the original database fields, and the VolcEngine authentication method is quite special,
|
| 456 |
-
Assemble
|
| 457 |
model_name is for display only
|
| 458 |
"""
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
self.client.set_sk(self.volc_sk)
|
| 464 |
-
self.model_name = eval(key).get('ep_id', '')
|
| 465 |
-
|
| 466 |
-
def chat(self, system, history, gen_conf):
|
| 467 |
-
if system:
|
| 468 |
-
history.insert(0, {"role": "system", "content": system})
|
| 469 |
-
try:
|
| 470 |
-
req = {
|
| 471 |
-
"parameters": {
|
| 472 |
-
"min_new_tokens": gen_conf.get("min_new_tokens", 1),
|
| 473 |
-
"top_k": gen_conf.get("top_k", 0),
|
| 474 |
-
"max_prompt_tokens": gen_conf.get("max_prompt_tokens", 30000),
|
| 475 |
-
"temperature": gen_conf.get("temperature", 0.1),
|
| 476 |
-
"max_new_tokens": gen_conf.get("max_tokens", 1000),
|
| 477 |
-
"top_p": gen_conf.get("top_p", 0.3),
|
| 478 |
-
},
|
| 479 |
-
"messages": history
|
| 480 |
-
}
|
| 481 |
-
response = self.client.chat(self.model_name, req)
|
| 482 |
-
ans = response.choices[0].message.content.strip()
|
| 483 |
-
if response.choices[0].finish_reason == "length":
|
| 484 |
-
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|
| 485 |
-
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
|
| 486 |
-
return ans, response.usage.total_tokens
|
| 487 |
-
except Exception as e:
|
| 488 |
-
return "**ERROR**: " + str(e), 0
|
| 489 |
-
|
| 490 |
-
def chat_streamly(self, system, history, gen_conf):
|
| 491 |
-
if system:
|
| 492 |
-
history.insert(0, {"role": "system", "content": system})
|
| 493 |
-
ans = ""
|
| 494 |
-
tk_count = 0
|
| 495 |
-
try:
|
| 496 |
-
req = {
|
| 497 |
-
"parameters": {
|
| 498 |
-
"min_new_tokens": gen_conf.get("min_new_tokens", 1),
|
| 499 |
-
"top_k": gen_conf.get("top_k", 0),
|
| 500 |
-
"max_prompt_tokens": gen_conf.get("max_prompt_tokens", 30000),
|
| 501 |
-
"temperature": gen_conf.get("temperature", 0.1),
|
| 502 |
-
"max_new_tokens": gen_conf.get("max_tokens", 1000),
|
| 503 |
-
"top_p": gen_conf.get("top_p", 0.3),
|
| 504 |
-
},
|
| 505 |
-
"messages": history
|
| 506 |
-
}
|
| 507 |
-
stream = self.client.stream_chat(self.model_name, req)
|
| 508 |
-
for resp in stream:
|
| 509 |
-
if not resp.choices[0].message.content:
|
| 510 |
-
continue
|
| 511 |
-
ans += resp.choices[0].message.content
|
| 512 |
-
if resp.choices[0].finish_reason == "stop":
|
| 513 |
-
tk_count = resp.usage.total_tokens
|
| 514 |
-
yield ans
|
| 515 |
-
|
| 516 |
-
except Exception as e:
|
| 517 |
-
yield ans + "\n**ERROR**: " + str(e)
|
| 518 |
-
yield tk_count
|
| 519 |
|
| 520 |
|
| 521 |
class MiniMaxChat(Base):
|
|
|
|
| 450 |
|
| 451 |
|
| 452 |
class VolcEngineChat(Base):
|
| 453 |
+
def __init__(self, key, model_name, base_url='https://ark.cn-beijing.volces.com/api/v3'):
|
| 454 |
"""
|
| 455 |
Since do not want to modify the original database fields, and the VolcEngine authentication method is quite special,
|
| 456 |
+
Assemble ark_api_key, ep_id into api_key, store it as a dictionary type, and parse it for use
|
| 457 |
model_name is for display only
|
| 458 |
"""
|
| 459 |
+
base_url = base_url if base_url else 'https://ark.cn-beijing.volces.com/api/v3'
|
| 460 |
+
ark_api_key = eval(key).get('ark_api_key', '')
|
| 461 |
+
model_name = eval(key).get('ep_id', '')
|
| 462 |
+
super().__init__(ark_api_key, model_name, base_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
|
| 464 |
|
| 465 |
class MiniMaxChat(Base):
|
web/src/locales/en.ts
CHANGED
|
@@ -502,12 +502,11 @@ The above is the content you need to summarize.`,
|
|
| 502 |
baseUrlNameMessage: 'Please input your base url!',
|
| 503 |
vision: 'Does it support Vision?',
|
| 504 |
ollamaLink: 'How to integrate {{name}}',
|
| 505 |
-
volcModelNameMessage:
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
volcSKMessage: 'Please input your SECRET_KEY',
|
| 511 |
bedrockModelNameMessage: 'Please input your model name!',
|
| 512 |
addBedrockEngineAK: 'ACCESS KEY',
|
| 513 |
bedrockAKMessage: 'Please input your ACCESS KEY',
|
|
|
|
| 502 |
baseUrlNameMessage: 'Please input your base url!',
|
| 503 |
vision: 'Does it support Vision?',
|
| 504 |
ollamaLink: 'How to integrate {{name}}',
|
| 505 |
+
volcModelNameMessage: 'Please input your model name!',
|
| 506 |
+
addEndpointID: 'EndpointID of the model',
|
| 507 |
+
endpointIDMessage: 'Please input your EndpointID of the model',
|
| 508 |
+
addArkApiKey: 'VOLC ARK_API_KEY',
|
| 509 |
+
ArkApiKeyMessage: 'Please input your ARK_API_KEY',
|
|
|
|
| 510 |
bedrockModelNameMessage: 'Please input your model name!',
|
| 511 |
addBedrockEngineAK: 'ACCESS KEY',
|
| 512 |
bedrockAKMessage: 'Please input your ACCESS KEY',
|
web/src/locales/zh-traditional.ts
CHANGED
|
@@ -465,11 +465,11 @@ export default {
|
|
| 465 |
modelTypeMessage: '請輸入模型類型!',
|
| 466 |
baseUrlNameMessage: '請輸入基礎 Url!',
|
| 467 |
ollamaLink: '如何集成 {{name}}',
|
| 468 |
-
volcModelNameMessage: '
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
bedrockModelNameMessage: '請輸入名稱!',
|
| 474 |
addBedrockEngineAK: 'ACCESS KEY',
|
| 475 |
bedrockAKMessage: '請輸入 ACCESS KEY',
|
|
|
|
| 465 |
modelTypeMessage: '請輸入模型類型!',
|
| 466 |
baseUrlNameMessage: '請輸入基礎 Url!',
|
| 467 |
ollamaLink: '如何集成 {{name}}',
|
| 468 |
+
volcModelNameMessage: '請輸入模型名稱!',
|
| 469 |
+
addEndpointID: '模型 EndpointID',
|
| 470 |
+
endpointIDMessage: '請輸入模型對應的EndpointID',
|
| 471 |
+
addArkApiKey: '火山 ARK_API_KEY',
|
| 472 |
+
ArkApiKeyMessage: '請輸入火山創建的ARK_API_KEY',
|
| 473 |
bedrockModelNameMessage: '請輸入名稱!',
|
| 474 |
addBedrockEngineAK: 'ACCESS KEY',
|
| 475 |
bedrockAKMessage: '請輸入 ACCESS KEY',
|
web/src/locales/zh.ts
CHANGED
|
@@ -482,11 +482,11 @@ export default {
|
|
| 482 |
modelTypeMessage: '请输入模型类型!',
|
| 483 |
baseUrlNameMessage: '请输入基础 Url!',
|
| 484 |
ollamaLink: '如何集成 {{name}}',
|
| 485 |
-
volcModelNameMessage: '
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
bedrockModelNameMessage: '请输入名称!',
|
| 491 |
addBedrockEngineAK: 'ACCESS KEY',
|
| 492 |
bedrockAKMessage: '请输入 ACCESS KEY',
|
|
|
|
| 482 |
modelTypeMessage: '请输入模型类型!',
|
| 483 |
baseUrlNameMessage: '请输入基础 Url!',
|
| 484 |
ollamaLink: '如何集成 {{name}}',
|
| 485 |
+
volcModelNameMessage: '请输入模型名称!',
|
| 486 |
+
addEndpointID: '模型 EndpointID',
|
| 487 |
+
endpointIDMessage: '请输入模型对应的EndpointID',
|
| 488 |
+
addArkApiKey: '火山 ARK_API_KEY',
|
| 489 |
+
ArkApiKeyMessage: '请输入火山创建的ARK_API_KEY',
|
| 490 |
bedrockModelNameMessage: '请输入名称!',
|
| 491 |
addBedrockEngineAK: 'ACCESS KEY',
|
| 492 |
bedrockAKMessage: '请输入 ACCESS KEY',
|
web/src/pages/user-setting/setting-model/volcengine-modal/index.tsx
CHANGED
|
@@ -8,6 +8,8 @@ type FieldType = IAddLlmRequestBody & {
|
|
| 8 |
vision: boolean;
|
| 9 |
volc_ak: string;
|
| 10 |
volc_sk: string;
|
|
|
|
|
|
|
| 11 |
};
|
| 12 |
|
| 13 |
const { Option } = Select;
|
|
@@ -51,7 +53,7 @@ const VolcEngineModal = ({
|
|
| 51 |
return (
|
| 52 |
<Flex justify={'space-between'}>
|
| 53 |
<a
|
| 54 |
-
href="https://www.volcengine.com/docs/82379/
|
| 55 |
target="_blank"
|
| 56 |
rel="noreferrer"
|
| 57 |
>
|
|
@@ -88,18 +90,18 @@ const VolcEngineModal = ({
|
|
| 88 |
<Input placeholder={t('volcModelNameMessage')} />
|
| 89 |
</Form.Item>
|
| 90 |
<Form.Item<FieldType>
|
| 91 |
-
label={t('
|
| 92 |
-
name="
|
| 93 |
-
rules={[{ required: true, message: t('
|
| 94 |
>
|
| 95 |
-
<Input placeholder={t('
|
| 96 |
</Form.Item>
|
| 97 |
<Form.Item<FieldType>
|
| 98 |
-
label={t('
|
| 99 |
-
name="
|
| 100 |
-
rules={[{ required: true, message: t('
|
| 101 |
>
|
| 102 |
-
<Input placeholder={t('
|
| 103 |
</Form.Item>
|
| 104 |
<Form.Item noStyle dependencies={['model_type']}>
|
| 105 |
{({ getFieldValue }) =>
|
|
|
|
| 8 |
vision: boolean;
|
| 9 |
volc_ak: string;
|
| 10 |
volc_sk: string;
|
| 11 |
+
endpoint_id: string;
|
| 12 |
+
ark_api_key: string;
|
| 13 |
};
|
| 14 |
|
| 15 |
const { Option } = Select;
|
|
|
|
| 53 |
return (
|
| 54 |
<Flex justify={'space-between'}>
|
| 55 |
<a
|
| 56 |
+
href="https://www.volcengine.com/docs/82379/1302008"
|
| 57 |
target="_blank"
|
| 58 |
rel="noreferrer"
|
| 59 |
>
|
|
|
|
| 90 |
<Input placeholder={t('volcModelNameMessage')} />
|
| 91 |
</Form.Item>
|
| 92 |
<Form.Item<FieldType>
|
| 93 |
+
label={t('addEndpointID')}
|
| 94 |
+
name="endpoint_id"
|
| 95 |
+
rules={[{ required: true, message: t('endpointIDMessage') }]}
|
| 96 |
>
|
| 97 |
+
<Input placeholder={t('endpointIDMessage')} />
|
| 98 |
</Form.Item>
|
| 99 |
<Form.Item<FieldType>
|
| 100 |
+
label={t('addArkApiKey')}
|
| 101 |
+
name="ark_api_key"
|
| 102 |
+
rules={[{ required: true, message: t('ArkApiKeyMessage') }]}
|
| 103 |
>
|
| 104 |
+
<Input placeholder={t('ArkApiKeyMessage')} />
|
| 105 |
</Form.Item>
|
| 106 |
<Form.Item noStyle dependencies={['model_type']}>
|
| 107 |
{({ getFieldValue }) =>
|