Skip to content

Commit 2984337

Browse files
author
dianjixz
committed
[add] llm_framework
1 parent 4c26c72 commit 2984337

File tree

4,761 files changed

+1825064
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,761 files changed

+1825064
-0
lines changed

projects/llm_framework/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dist
2+
build
3+
.config.mk
4+
.flash.conf.json
5+
.vscode
6+
static_lib**
7+
*.deb
8+
*.tar.gz
9+
m5stack_*
10+
debian*

projects/llm_framework/README.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# LLM
2+
AX630C AI large model local voice assistant program. Provided by M5STACK STACKFLOW for basic communication architecture, coordinating multiple working units to work together.
3+
- llm-audio: Audio unit, providing system audio support.
4+
- llm-kws: Keyword detection unit, providing keyword wakeup service.
5+
- llm-asr: Speech-to-text unit, providing speech-to-text service.
6+
- llm-llm: Large model unit, providing AI large model inference service.
7+
- llm-melotts: NPU-accelerated TTS unit, providing text-to-speech and playback service.
8+
- llm-tts: CPU-computed TTS unit, providing text-to-speech and playback service.
9+
10+
## compile
11+
```bash
12+
wget https://m5share.oss-cn-shenzhen.aliyuncs.com/ax630c_llm_project/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.gz?OSSAccessKeyId=LTAI5tSGrycCku6R4TQkroEc&Expires=37727406013&Signature=U9YN9Tp6zrIhNlL%2FfjcO0xRQTzk%3D
13+
sudo tar zxvf gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.gz -C /opt
14+
15+
16+
sudo apt install python3 python3-pip libffi-dev
17+
pip3 install parse scons requests
18+
19+
20+
cd M5Stack_LLM_Framework/examples/llm_framework
21+
scons distclean
22+
scons -j22
23+
24+
```
25+
26+
27+
## assistant mode
28+
llm-sys llm-audio llm-kws llm-asr llm-llm llm-melotts Collaborative work。
29+
30+
Chinese environment:
31+
32+
1、reset
33+
34+
send :
35+
36+
```json
37+
{
38+
"request_id": "11212155",
39+
"work_id": "sys",
40+
"action": "reset"
41+
}
42+
```
43+
waiting reset over!
44+
45+
2、init all unit
46+
47+
send :
48+
49+
```json
50+
{
51+
"request_id": "1",
52+
"work_id": "kws",
53+
"action": "setup",
54+
"object": "kws.setup",
55+
"data": {
56+
"model": "sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01","response_format": "kws.bool",
57+
"input": "sys.pcm",
58+
"enoutput": true,
59+
"kws": "你好你好"
60+
}
61+
}
62+
63+
{
64+
"request_id": "2",
65+
"work_id": "asr",
66+
"action": "setup",
67+
"object": "asr.setup",
68+
"data": {
69+
"model": "sherpa-ncnn-streaming-zipformer-zh-14M-2023-02-23",
70+
"response_format": "asr.utf-8.stream",
71+
"input": "sys.pcm",
72+
"enoutput": true,
73+
"enkws":true,
74+
"rule1":2.4,
75+
"rule2":1.2,
76+
"rule3":30.1
77+
}
78+
}
79+
80+
{
81+
"request_id": "3",
82+
"work_id": "llm",
83+
"action": "setup","object": "llm.setup",
84+
"data": {
85+
"model": "qwen2.5-0.5B-prefill-20e",
86+
"response_format": "llm.utf-8.stream",
87+
"input": "llm.utf-8",
88+
"enoutput": true,
89+
"max_token_len": 256,
90+
"prompt": "You are a knowledgeable assistant capable of answering various questions and providing information."
91+
}
92+
}
93+
94+
{
95+
"request_id": "4",
96+
"work_id": "melotts",
97+
"action": "setup",
98+
"object": "melotts.setup",
99+
"data": {
100+
"model": "melotts_zh-cn",
101+
"response_format": "sys.pcm",
102+
"input": "tts.utf-8",
103+
"enoutput": false
104+
}
105+
}
106+
```
107+
waiting return work_id:
108+
```json
109+
{"created":1731488371,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"3","work_id":"asr.1001"}
110+
{"created":1731488377,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"4","work_id":"llm.1002"}
111+
{"created":1731488392,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"4","work_id":"melotts.1003"}
112+
{"created":1731488402,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"2","work_id":"kws.1000"}
113+
```
114+
115+
creat assembly line:
116+
```json
117+
{
118+
"request_id": "2",
119+
"work_id": "asr.1001",
120+
"action": "link",
121+
"object":"work_id",
122+
"data":"kws.1000"
123+
}
124+
125+
{
126+
"request_id": "3",
127+
"work_id": "llm.1002",
128+
"action": "link",
129+
"object":"work_id",
130+
"data":"asr.1001"
131+
}
132+
133+
{
134+
"request_id": "4",
135+
"work_id": "melotts.1003",
136+
"action": "link",
137+
"object":"work_id",
138+
"data":"llm.1002"
139+
}
140+
141+
{
142+
"request_id": "3",
143+
"work_id": "llm.1002",
144+
"action": "link",
145+
"object":"work_id",
146+
"data":"kws.1000"
147+
}
148+
{
149+
"request_id": "4",
150+
"work_id": "melotts.1003",
151+
"action": "link",
152+
"object":"work_id",
153+
"data":"kws.1000"
154+
}
155+
156+
```
157+
158+
waiting return status:
159+
160+
```json
161+
{"created":1731488403,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"3","work_id":"llm.1002"}
162+
{"created":1731488403,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"4","work_id":"melotts.1003"}
163+
{"created":1731488403,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"2","work_id":"asr.1001"}
164+
{"created":1731488403,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"4","work_id":"melotts.1003"}
165+
{"created":1731488403,"data":"None","error":{"code":0,"message":""},"object":"None","request_id":"3","work_id":"llm.1002"}
166+
```
167+
168+
**Please enjoy the large model voice assistant.**

projects/llm_framework/SConstruct

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from pathlib import Path
2+
import os
3+
import shutil
4+
5+
os.environ['SDK_PATH'] = os.path.normpath(str(Path(os.getcwd())/'..'/'..'/'SDK'))
6+
os.environ['EXT_COMPONENTS_PATH'] = os.path.normpath(str(Path(os.getcwd())/'..'/'..'/'ext_components'))
7+
8+
version = 'v0.0.5'
9+
static_lib = 'static_lib'
10+
update = False
11+
if not os.path.exists(static_lib):
12+
update = True
13+
else:
14+
try:
15+
with open(str(Path(static_lib)/'version'), 'r') as f:
16+
if f.read() != version:
17+
update = True
18+
except:
19+
update = True
20+
21+
if update:
22+
zip_file = static_lib + '_{}.tar.gz'.format(version)
23+
zip_file_extrpath = static_lib + '_tmp'
24+
down_url = "https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/linux/llm/static_lib_{}.tar.gz".format(version)
25+
26+
if 'CONFIG_REPO_AUTOMATION' in os.environ:
27+
down = 'y'
28+
else:
29+
down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format('static_lib_{}.tar.gz').format(version))
30+
down = down.lower()
31+
if down == 'y':
32+
# from git import Repo
33+
import requests
34+
import parse
35+
import tarfile
36+
import shutil
37+
try:
38+
# Downloading via HTTP (more common)
39+
if not os.path.exists(zip_file):
40+
response = requests.get(down_url)
41+
if response.status_code == 200:
42+
with open(zip_file, 'wb') as file:
43+
file.write(response.content)
44+
else:
45+
print("{} down failed".format(down_url))
46+
try:
47+
shutil.rmtree(static_lib)
48+
except:
49+
pass
50+
with tarfile.open(zip_file, 'r:gz') as tar:
51+
tar.extractall(path=zip_file_extrpath)
52+
shutil.move(zip_file_extrpath, static_lib)
53+
try:
54+
os.remove(zip_file)
55+
except:
56+
pass
57+
print("The {} download successful.".format(down_url))
58+
except Exception as e:
59+
print('Please manually download {} to {} .'.format(down_url, zip_file))
60+
print("Cloning failed.: {}".format(e))
61+
else:
62+
print('Please manually download {} to {} .'.format(down_url, zip_file))
63+
64+
65+
with open(str(Path(os.getcwd())/'..'/'..'/'SDK'/'tools'/'scons'/'project.py')) as f:
66+
exec(f.read())
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CONFIG_TOOLCHAIN_PATH="/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin"
2+
CONFIG_TOOLCHAIN_PREFIX="aarch64-none-linux-gnu-"
3+
4+
# CONFIG_COMMPILE_DEBUG=y
5+
CONFIG_AX_MSP_ENABLED=y
6+
CONFIG_AX_620E_MSP_ENABLED=y
7+
CONFIG_AX630C_OPENWRT_SDK_ENABLED=y
8+
CONFIG_DEVICE_DRIVER_ENABLED=y
9+
CONFIG_DEVICE_UART_ENABLED=y
10+
# CONFIG_LHV_ENABLED=y
11+
# CONFIG_LHV_WITH_KCP is not set
12+
# CONFIG_LHV_WITH_PROTOCOL is not set
13+
# CONFIG_LHV_WITH_EVPP=y
14+
CONFIG_UTILITIES_ENABLED=y
15+
CONFIG_BACKWARD_CPP_ENABLED=y
16+
CONFIG_TOOLCHAIN_FLAGS="-g"
17+
CONFIG_EVENTPP_ENABLED=y
18+
CONFIG_LHV_ENABLED=y
19+
CONFIG_LHV_WITH_EVPP=y
20+
CONFIG_EVENTPP_ENABLED=y
21+
CONFIG_STACKFLOW_ENABLED=y
22+
CONFIG_UTILITIES_BASE64_ENABLED=y
23+
CONFIG_SINGLE_HEADER_LIBS_ENABLED=y
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2017 The Abseil Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// -----------------------------------------------------------------------------
16+
// File: algorithm.h
17+
// -----------------------------------------------------------------------------
18+
//
19+
// This header file contains Google extensions to the standard <algorithm> C++
20+
// header.
21+
22+
#ifndef ABSL_ALGORITHM_ALGORITHM_H_
23+
#define ABSL_ALGORITHM_ALGORITHM_H_
24+
25+
#include <algorithm>
26+
#include <iterator>
27+
#include <type_traits>
28+
29+
#include "absl/base/config.h"
30+
31+
namespace absl {
32+
ABSL_NAMESPACE_BEGIN
33+
34+
// equal()
35+
// rotate()
36+
//
37+
// Historical note: Abseil once provided implementations of these algorithms
38+
// prior to their adoption in C++14. New code should prefer to use the std
39+
// variants.
40+
//
41+
// See the documentation for the STL <algorithm> header for more information:
42+
// https://en.cppreference.com/w/cpp/header/algorithm
43+
using std::equal;
44+
using std::rotate;
45+
46+
// linear_search()
47+
//
48+
// Performs a linear search for `value` using the iterator `first` up to
49+
// but not including `last`, returning true if [`first`, `last`) contains an
50+
// element equal to `value`.
51+
//
52+
// A linear search is of O(n) complexity which is guaranteed to make at most
53+
// n = (`last` - `first`) comparisons. A linear search over short containers
54+
// may be faster than a binary search, even when the container is sorted.
55+
template <typename InputIterator, typename EqualityComparable>
56+
bool linear_search(InputIterator first, InputIterator last,
57+
const EqualityComparable& value) {
58+
return std::find(first, last, value) != last;
59+
}
60+
61+
ABSL_NAMESPACE_END
62+
} // namespace absl
63+
64+
#endif // ABSL_ALGORITHM_ALGORITHM_H_

0 commit comments

Comments
 (0)