mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
VolcEngine SDK V3 adaptation (#2082)
1) 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>
This commit is contained in:
@ -450,72 +450,16 @@ class LocalLLM(Base):
|
||||
|
||||
|
||||
class VolcEngineChat(Base):
|
||||
def __init__(self, key, model_name, base_url):
|
||||
def __init__(self, key, model_name, base_url='https://ark.cn-beijing.volces.com/api/v3'):
|
||||
"""
|
||||
Since do not want to modify the original database fields, and the VolcEngine authentication method is quite special,
|
||||
Assemble ak, sk, ep_id into api_key, store it as a dictionary type, and parse it for use
|
||||
Assemble ark_api_key, ep_id into api_key, store it as a dictionary type, and parse it for use
|
||||
model_name is for display only
|
||||
"""
|
||||
self.client = MaasService('maas-api.ml-platform-cn-beijing.volces.com', 'cn-beijing')
|
||||
self.volc_ak = eval(key).get('volc_ak', '')
|
||||
self.volc_sk = eval(key).get('volc_sk', '')
|
||||
self.client.set_ak(self.volc_ak)
|
||||
self.client.set_sk(self.volc_sk)
|
||||
self.model_name = eval(key).get('ep_id', '')
|
||||
|
||||
def chat(self, system, history, gen_conf):
|
||||
if system:
|
||||
history.insert(0, {"role": "system", "content": system})
|
||||
try:
|
||||
req = {
|
||||
"parameters": {
|
||||
"min_new_tokens": gen_conf.get("min_new_tokens", 1),
|
||||
"top_k": gen_conf.get("top_k", 0),
|
||||
"max_prompt_tokens": gen_conf.get("max_prompt_tokens", 30000),
|
||||
"temperature": gen_conf.get("temperature", 0.1),
|
||||
"max_new_tokens": gen_conf.get("max_tokens", 1000),
|
||||
"top_p": gen_conf.get("top_p", 0.3),
|
||||
},
|
||||
"messages": history
|
||||
}
|
||||
response = self.client.chat(self.model_name, req)
|
||||
ans = response.choices[0].message.content.strip()
|
||||
if response.choices[0].finish_reason == "length":
|
||||
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|
||||
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
|
||||
return ans, response.usage.total_tokens
|
||||
except Exception as e:
|
||||
return "**ERROR**: " + str(e), 0
|
||||
|
||||
def chat_streamly(self, system, history, gen_conf):
|
||||
if system:
|
||||
history.insert(0, {"role": "system", "content": system})
|
||||
ans = ""
|
||||
tk_count = 0
|
||||
try:
|
||||
req = {
|
||||
"parameters": {
|
||||
"min_new_tokens": gen_conf.get("min_new_tokens", 1),
|
||||
"top_k": gen_conf.get("top_k", 0),
|
||||
"max_prompt_tokens": gen_conf.get("max_prompt_tokens", 30000),
|
||||
"temperature": gen_conf.get("temperature", 0.1),
|
||||
"max_new_tokens": gen_conf.get("max_tokens", 1000),
|
||||
"top_p": gen_conf.get("top_p", 0.3),
|
||||
},
|
||||
"messages": history
|
||||
}
|
||||
stream = self.client.stream_chat(self.model_name, req)
|
||||
for resp in stream:
|
||||
if not resp.choices[0].message.content:
|
||||
continue
|
||||
ans += resp.choices[0].message.content
|
||||
if resp.choices[0].finish_reason == "stop":
|
||||
tk_count = resp.usage.total_tokens
|
||||
yield ans
|
||||
|
||||
except Exception as e:
|
||||
yield ans + "\n**ERROR**: " + str(e)
|
||||
yield tk_count
|
||||
base_url = base_url if base_url else 'https://ark.cn-beijing.volces.com/api/v3'
|
||||
ark_api_key = eval(key).get('ark_api_key', '')
|
||||
model_name = eval(key).get('ep_id', '')
|
||||
super().__init__(ark_api_key, model_name, base_url)
|
||||
|
||||
|
||||
class MiniMaxChat(Base):
|
||||
|
||||
Reference in New Issue
Block a user