Spaces:
Sleeping
Sleeping
add skill library
Browse files- __pycache__/config.cpython-312.pyc +0 -0
- __pycache__/dialogue_management.cpython-312.pyc +0 -0
- __pycache__/function_trigger.cpython-312.pyc +0 -0
- __pycache__/scene_recognition.cpython-312.pyc +0 -0
- __pycache__/skill_repository.cpython-312.pyc +0 -0
- app.py +75 -43
- dialogue_management.py +0 -1
- flagged/log.csv +2 -0
- skill_repository.py +16 -2
- skills.json +34 -10
__pycache__/config.cpython-312.pyc
ADDED
Binary file (478 Bytes). View file
|
|
__pycache__/dialogue_management.cpython-312.pyc
ADDED
Binary file (2.03 kB). View file
|
|
__pycache__/function_trigger.cpython-312.pyc
ADDED
Binary file (312 Bytes). View file
|
|
__pycache__/scene_recognition.cpython-312.pyc
ADDED
Binary file (616 Bytes). View file
|
|
__pycache__/skill_repository.cpython-312.pyc
ADDED
Binary file (1.86 kB). View file
|
|
app.py
CHANGED
@@ -1,57 +1,89 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
from dialogue_management import manage_dialogue
|
4 |
from function_trigger import trigger_function
|
5 |
from config import load_config
|
6 |
-
from skill_repository import load_skills
|
7 |
|
8 |
config = load_config()
|
9 |
skills = load_skills()
|
10 |
|
11 |
-
# 场景识别功能
|
12 |
-
def recognize(system_time, app_name, system_load):
|
13 |
-
system_data = {
|
14 |
-
'time': system_time,
|
15 |
-
'app_name': app_name,
|
16 |
-
'system_load': system_load
|
17 |
-
}
|
18 |
-
scene = recognize_scene(config, system_data)
|
19 |
-
return scene['type']
|
20 |
-
|
21 |
# 对话功能
|
22 |
def respond(user_input):
|
23 |
response, action = manage_dialogue(user_input, skills)
|
24 |
result = trigger_function(action, config)
|
25 |
-
return response,result
|
26 |
-
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
)
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
from dialogue_management import manage_dialogue
|
4 |
from function_trigger import trigger_function
|
5 |
from config import load_config
|
6 |
+
from skill_repository import load_skills, save_skills, add_skill, delete_skill
|
7 |
|
8 |
config = load_config()
|
9 |
skills = load_skills()
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# 对话功能
|
12 |
def respond(user_input):
|
13 |
response, action = manage_dialogue(user_input, skills)
|
14 |
result = trigger_function(action, config)
|
15 |
+
return response, result
|
16 |
+
|
17 |
+
# 显示指令库文件
|
18 |
+
def show_skills():
|
19 |
+
with open('skills.json', 'r', encoding='utf-8') as file:
|
20 |
+
skills_data = json.load(file)
|
21 |
+
return json.dumps(skills_data, ensure_ascii=False, indent=4)
|
22 |
+
|
23 |
+
# 添加新的技能
|
24 |
+
def add_new_skill(triggers, action):
|
25 |
+
trigger_list = [trigger.strip() for trigger in triggers.split(',')]
|
26 |
+
new_skill = {
|
27 |
+
"triggers": trigger_list,
|
28 |
+
"action": action
|
29 |
+
}
|
30 |
+
add_skill(new_skill)
|
31 |
+
return show_skills()
|
32 |
+
|
33 |
+
# 删除技能
|
34 |
+
def remove_skill(action):
|
35 |
+
delete_skill(action)
|
36 |
+
return show_skills()
|
37 |
+
|
38 |
+
with gr.Blocks() as demo:
|
39 |
+
with gr.Tab("AI Assistant Response"):
|
40 |
+
skills = load_skills()
|
41 |
+
gr.Markdown("## AI Assistant Response")
|
42 |
+
user_input = gr.Textbox(label="User Input")
|
43 |
+
ai_response = gr.Markdown()
|
44 |
+
action_result = gr.Textbox(label="Action Result")
|
45 |
+
respond_button = gr.Button("Respond")
|
46 |
+
|
47 |
+
respond_button.click(
|
48 |
+
respond,
|
49 |
+
inputs=user_input,
|
50 |
+
outputs=[ai_response, action_result]
|
51 |
+
)
|
52 |
+
|
53 |
+
with gr.Tab("View Skills Library"):
|
54 |
+
gr.Markdown("## Skills Library")
|
55 |
+
skills_output = gr.Code(label="Skills Library")
|
56 |
+
load_skills_button = gr.Button("Load Skills")
|
57 |
+
|
58 |
+
load_skills_button.click(
|
59 |
+
show_skills,
|
60 |
+
outputs=skills_output
|
61 |
+
)
|
62 |
+
|
63 |
+
with gr.Tab("Add Skill"):
|
64 |
+
gr.Markdown("## Add Skill")
|
65 |
+
new_triggers = gr.Textbox(label="Triggers (comma separated)")
|
66 |
+
new_action = gr.Textbox(label="Action")
|
67 |
+
add_skill_output = gr.Code(label="Updated Skills Library")
|
68 |
+
add_skill_button = gr.Button("Add Skill")
|
69 |
+
|
70 |
+
add_skill_button.click(
|
71 |
+
add_new_skill,
|
72 |
+
inputs=[new_triggers, new_action],
|
73 |
+
outputs=add_skill_output
|
74 |
+
)
|
75 |
+
|
76 |
+
with gr.Tab("Delete Skill"):
|
77 |
+
gr.Markdown("## Delete Skill")
|
78 |
+
delete_action = gr.Textbox(label="Action to Delete")
|
79 |
+
delete_skill_output = gr.Code(label="Updated Skills Library")
|
80 |
+
delete_skill_button = gr.Button("Delete Skill")
|
81 |
+
|
82 |
+
delete_skill_button.click(
|
83 |
+
remove_skill,
|
84 |
+
inputs=delete_action,
|
85 |
+
outputs=delete_skill_output
|
86 |
+
)
|
87 |
|
88 |
if __name__ == "__main__":
|
89 |
+
demo.launch()
|
dialogue_management.py
CHANGED
@@ -4,7 +4,6 @@ import json
|
|
4 |
|
5 |
def manage_dialogue(user_input, skills):
|
6 |
client = OpenAI(api_key="sk-6d543a8d079d4cee83f2bda58a6469d1", base_url="https://api.deepseek.com")
|
7 |
-
print(skills)
|
8 |
prompt = f"你是一个具有意图识别能力的助手。你需要仔细判断用户的输入中是否包含命令,当你检测到用户的命令时并且这些命令存在于命令库中时,请严格按照以下格式返回相应的传输指令代码。否则,请进行正常对话。以下是命令库中的全部命令(triggers)及其对应的动作(action)指令代码:{skills} \n严格要求:1. 只有当用户输入匹配命令库中的命令时,才返回相应的指令代码。2. 返回格式必须严格遵守:S:{{指令代码}}。不能有任何拼写或格式错误。3. 当用户输入未包含任何命令时,进行正常对话。\n示例:用户输入:能帮我重启系统吗? \n输出:S:CMD_RESTART \n用户输入:今天天气怎么样? \n 输出:今天天气很好,可能会有阵雨。\n 现在,请根据上述规则严格响应以下用户输入:"
|
9 |
response = client.chat.completions.create(
|
10 |
model="deepseek-chat",
|
|
|
4 |
|
5 |
def manage_dialogue(user_input, skills):
|
6 |
client = OpenAI(api_key="sk-6d543a8d079d4cee83f2bda58a6469d1", base_url="https://api.deepseek.com")
|
|
|
7 |
prompt = f"你是一个具有意图识别能力的助手。你需要仔细判断用户的输入中是否包含命令,当你检测到用户的命令时并且这些命令存在于命令库中时,请严格按照以下格式返回相应的传输指令代码。否则,请进行正常对话。以下是命令库中的全部命令(triggers)及其对应的动作(action)指令代码:{skills} \n严格要求:1. 只有当用户输入匹配命令库中的命令时,才返回相应的指令代码。2. 返回格式必须严格遵守:S:{{指令代码}}。不能有任何拼写或格式错误。3. 当用户输入未包含任何命令时,进行正常对话。\n示例:用户输入:能帮我重启系统吗? \n输出:S:CMD_RESTART \n用户输入:今天天气怎么样? \n 输出:今天天气很好,可能会有阵雨。\n 现在,请根据上述规则严格响应以下用户输入:"
|
8 |
response = client.chat.completions.create(
|
9 |
model="deepseek-chat",
|
flagged/log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
User Input,AI Response,Action Result,flag,username,timestamp
|
2 |
+
,,,,,2024-05-31 16:51:57.320514
|
skill_repository.py
CHANGED
@@ -1,12 +1,26 @@
|
|
1 |
import json
|
2 |
|
3 |
def load_skills():
|
4 |
-
with open('skills.json', 'r') as file:
|
5 |
skills = json.load(file)
|
6 |
return skills
|
7 |
|
8 |
-
def
|
|
|
|
|
|
|
|
|
9 |
for skill in skills:
|
10 |
if any(trigger in user_input for trigger in skill['triggers']):
|
11 |
return skill
|
12 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
|
3 |
def load_skills():
|
4 |
+
with open('skills.json', 'r', encoding='utf-8') as file:
|
5 |
skills = json.load(file)
|
6 |
return skills
|
7 |
|
8 |
+
def save_skills(skills_data):
|
9 |
+
with open('skills.json', 'w', encoding='utf-8') as file:
|
10 |
+
json.dump(skills_data, file, ensure_ascii=False, indent=4)
|
11 |
+
|
12 |
+
def get_skill(user_input, scene, skills):
|
13 |
for skill in skills:
|
14 |
if any(trigger in user_input for trigger in skill['triggers']):
|
15 |
return skill
|
16 |
return None
|
17 |
+
|
18 |
+
def add_skill(new_skill):
|
19 |
+
skills = load_skills()
|
20 |
+
skills.append(new_skill)
|
21 |
+
save_skills(skills)
|
22 |
+
|
23 |
+
def delete_skill(action):
|
24 |
+
skills = load_skills()
|
25 |
+
skills = [skill for skill in skills if skill['triggers'] != action]
|
26 |
+
save_skills(skills)
|
skills.json
CHANGED
@@ -1,38 +1,62 @@
|
|
1 |
[
|
2 |
{
|
3 |
-
"triggers": [
|
|
|
|
|
4 |
"action": "CMD_LIGHT_UP"
|
5 |
},
|
6 |
{
|
7 |
-
"triggers": [
|
|
|
|
|
8 |
"action": "CMD_LIGHT_DOWN"
|
9 |
},
|
10 |
{
|
11 |
-
"triggers": [
|
|
|
|
|
12 |
"action": "CMD_SOUND_UP"
|
13 |
},
|
14 |
{
|
15 |
-
"triggers": [
|
|
|
|
|
16 |
"action": "CMD_SOUND_DOWN"
|
17 |
},
|
18 |
{
|
19 |
-
"triggers": [
|
|
|
|
|
20 |
"action": "CMD_RESTART"
|
21 |
},
|
22 |
{
|
23 |
-
"triggers": [
|
|
|
|
|
24 |
"action": "CMD_LOCK_SCREEN"
|
25 |
},
|
26 |
{
|
27 |
-
"triggers": [
|
|
|
|
|
28 |
"action": "CMD_DARKMODE"
|
29 |
},
|
30 |
{
|
31 |
-
"triggers": [
|
|
|
|
|
32 |
"action": "CMD_SET_BRIGHTNESS_{{level}}"
|
33 |
},
|
34 |
{
|
35 |
-
"triggers": [
|
|
|
|
|
36 |
"action": "CMD_SET_TIMER_{{time}}M"
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|
38 |
-
]
|
|
|
1 |
[
|
2 |
{
|
3 |
+
"triggers": [
|
4 |
+
"调高亮度"
|
5 |
+
],
|
6 |
"action": "CMD_LIGHT_UP"
|
7 |
},
|
8 |
{
|
9 |
+
"triggers": [
|
10 |
+
"调低亮度"
|
11 |
+
],
|
12 |
"action": "CMD_LIGHT_DOWN"
|
13 |
},
|
14 |
{
|
15 |
+
"triggers": [
|
16 |
+
"调高音量"
|
17 |
+
],
|
18 |
"action": "CMD_SOUND_UP"
|
19 |
},
|
20 |
{
|
21 |
+
"triggers": [
|
22 |
+
"调低音量"
|
23 |
+
],
|
24 |
"action": "CMD_SOUND_DOWN"
|
25 |
},
|
26 |
{
|
27 |
+
"triggers": [
|
28 |
+
"重启系统"
|
29 |
+
],
|
30 |
"action": "CMD_RESTART"
|
31 |
},
|
32 |
{
|
33 |
+
"triggers": [
|
34 |
+
"锁定屏幕"
|
35 |
+
],
|
36 |
"action": "CMD_LOCK_SCREEN"
|
37 |
},
|
38 |
{
|
39 |
+
"triggers": [
|
40 |
+
"深色模式"
|
41 |
+
],
|
42 |
"action": "CMD_DARKMODE"
|
43 |
},
|
44 |
{
|
45 |
+
"triggers": [
|
46 |
+
"调节亮度至{level}%"
|
47 |
+
],
|
48 |
"action": "CMD_SET_BRIGHTNESS_{{level}}"
|
49 |
},
|
50 |
{
|
51 |
+
"triggers": [
|
52 |
+
"设置{time}分钟的计时器"
|
53 |
+
],
|
54 |
"action": "CMD_SET_TIMER_{{time}}M"
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"triggers": [
|
58 |
+
"播放{name}音乐"
|
59 |
+
],
|
60 |
+
"action": "CMD_MUSIC_{name}"
|
61 |
}
|
62 |
+
]
|