Skip to content

Commit a972fc0

Browse files
authored
Merge pull request xinnan-tech#962 from xinnan-tech/update-fix
update:让alibl、等非原生llm使用functional时不卡顿
2 parents e843d78 + 864081b commit a972fc0

File tree

4 files changed

+73
-31
lines changed

4 files changed

+73
-31
lines changed

docs/firmware-build.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
# esp32固件编译
22

3-
## 第1步 配置环境
3+
## 第1步 准备你的ota地址
4+
如果你按照教程使用的是全模块部署,就应该会有ota地址。
5+
6+
此刻,请你用浏览器打开你的ota地址,例如我的ota地址
7+
```
8+
http://192.168.1.25:8002/xiaozhi/ota/
9+
```
10+
11+
如果显示“OTA接口运行正常,websocket集群数量:X”。那就往下。
12+
13+
如果显示“OTA接口运行不正常”,大概是你还没在`智控台`配置`Websocket`地址。那就:
14+
15+
- 1、使用超级管理员登录智控台
16+
17+
- 2、顶部菜单点击`参数管理`
18+
19+
- 3、在列表中找到`server.websocket`项目,输入你的`Websocket`地址。例如我的就是
20+
21+
```
22+
ws://192.168.1.25:8000/xiaozhi/v1/
23+
```
24+
25+
配置完后,再使用浏览器刷新你的ota接口地址,看看是不是正常了。如果还不正常就,就再次确认一下Websocket是否正常启动,是否配置了Websocket地址。
26+
27+
## 第2步 配置环境
428
先按照这个教程配置项目环境[《Windows搭建 ESP IDF 5.3.2开发环境以及编译小智》](https://icnynnzcwou8.feishu.cn/wiki/JEYDwTTALi5s2zkGlFGcDiRknXf)
529

6-
## 第2步 打开配置文件
30+
## 第3步 打开配置文件
731
配置好编译环境后,下载虾哥iaozhi-esp32项目源码,
832

933
从这里下载虾哥[xiaozhi-esp32项目源码](https://github.com/78/xiaozhi-esp32)
1034

1135
下载后,打开`xiaozhi-esp32/main/Kconfig.projbuild`文件。
1236

13-
## 第3步 修改OTA地址
37+
## 第4步 修改OTA地址
1438

1539
找到`OTA_VERSION_URL``default`的内容,把`https://api.tenclass.net/xiaozhi/ota/`
1640
改成你自己的地址,例如,我的接口地址是`http://192.168.1.25:8002/xiaozhi/ota/`,就把内容改成这个。

main/xiaozhi-server/core/providers/llm/AliBL/AliBL.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
TAG = __name__
77
logger = setup_logging()
88

9+
910
class LLMProvider(LLMProviderBase):
1011
def __init__(self, config):
1112
self.api_key = config["api_key"]
@@ -19,21 +20,25 @@ def response(self, session_id, dialogue):
1920
# 处理dialogue
2021
if self.is_No_prompt:
2122
dialogue.pop(0)
22-
logger.bind(tag=TAG).debug(f"【阿里百练API服务】处理后的dialogue: {dialogue}")
23+
logger.bind(tag=TAG).debug(
24+
f"【阿里百练API服务】处理后的dialogue: {dialogue}"
25+
)
2326

2427
# 构造调用参数
2528
call_params = {
2629
"api_key": self.api_key,
2730
"app_id": self.app_id,
2831
"session_id": session_id,
29-
"messages": dialogue
32+
"messages": dialogue,
3033
}
3134
if self.memory_id != False:
3235
# 百练memory需要prompt参数
3336
prompt = dialogue[-1].get("content")
3437
call_params["memory_id"] = self.memory_id
3538
call_params["prompt"] = prompt
36-
logger.bind(tag=TAG).debug(f"【阿里百练API服务】处理后的prompt: {prompt}")
39+
logger.bind(tag=TAG).debug(
40+
f"【阿里百练API服务】处理后的prompt: {prompt}"
41+
)
3742

3843
responses = Application.call(**call_params)
3944
if responses.status_code != HTTPStatus.OK:
@@ -44,9 +49,15 @@ def response(self, session_id, dialogue):
4449
)
4550
yield "【阿里百练API服务响应异常】"
4651
else:
47-
logger.bind(tag=TAG).debug(f"【阿里百练API服务】构造参数: {call_params}")
52+
logger.bind(tag=TAG).debug(
53+
f"【阿里百练API服务】构造参数: {call_params}"
54+
)
4855
yield responses.output.text
4956

5057
except Exception as e:
5158
logger.bind(tag=TAG).error(f"【阿里百练API服务】响应异常: {e}")
5259
yield "【LLM服务响应异常】"
60+
61+
def response_with_functions(self, session_id, dialogue, functions=None):
62+
logger.bind(tag=TAG).info(f"阿里百练暂未实现完整的工具调用(function call)")
63+
return self.response(session_id, dialogue)

main/xiaozhi-server/core/providers/llm/fastgpt/fastgpt.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,36 @@ def response(self, session_id, dialogue):
2121

2222
# 发起流式请求
2323
with requests.post(
24-
f"{self.base_url}/chat/completions",
25-
headers={"Authorization": f"Bearer {self.api_key}"},
26-
json={
27-
"stream": True,
28-
"chatId": session_id,
29-
"detail": self.detail,
30-
"variables": self.variables,
31-
"messages": [
32-
{
33-
"role": "user",
34-
"content": last_msg["content"]
35-
}
36-
]
37-
},
38-
stream=True
24+
f"{self.base_url}/chat/completions",
25+
headers={"Authorization": f"Bearer {self.api_key}"},
26+
json={
27+
"stream": True,
28+
"chatId": session_id,
29+
"detail": self.detail,
30+
"variables": self.variables,
31+
"messages": [{"role": "user", "content": last_msg["content"]}],
32+
},
33+
stream=True,
3934
) as r:
4035
for line in r.iter_lines():
4136
if line:
4237
try:
43-
if line.startswith(b'data: '):
44-
if line[6:].decode('utf-8') == '[DONE]':
38+
if line.startswith(b"data: "):
39+
if line[6:].decode("utf-8") == "[DONE]":
4540
break
4641

4742
data = json.loads(line[6:])
48-
if 'choices' in data and len(data['choices']) > 0:
49-
delta = data['choices'][0].get('delta', {})
50-
if delta and 'content' in delta and delta['content'] is not None:
51-
content = delta['content']
52-
if '<think>' in content:
43+
if "choices" in data and len(data["choices"]) > 0:
44+
delta = data["choices"][0].get("delta", {})
45+
if (
46+
delta
47+
and "content" in delta
48+
and delta["content"] is not None
49+
):
50+
content = delta["content"]
51+
if "<think>" in content:
5352
continue
54-
if '</think>' in content:
53+
if "</think>" in content:
5554
continue
5655
yield content
5756

@@ -62,4 +61,8 @@ def response(self, session_id, dialogue):
6261

6362
except Exception as e:
6463
logger.bind(tag=TAG).error(f"Error in response generation: {e}")
65-
yield "【服务响应异常】"
64+
yield "【服务响应异常】"
65+
66+
def response_with_functions(self, session_id, dialogue, functions=None):
67+
logger.bind(tag=TAG).info(f"fastgpt暂未实现完整的工具调用(function call)")
68+
return self.response(session_id, dialogue)

main/xiaozhi-server/core/providers/llm/gemini/gemini.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,7 @@ def response(self, session_id, dialogue):
134134
yield f"JSON解码错误:{e}"
135135
except Exception as e:
136136
yield f"发生错误:{e}"
137+
138+
def response_with_functions(self, session_id, dialogue, functions=None):
139+
logger.bind(tag=TAG).info(f"gemini暂未实现完整的工具调用(function call)")
140+
return self.response(session_id, dialogue)

0 commit comments

Comments
 (0)