wangzhibo
10 天以前 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
from typing import TYPE_CHECKING
 
from plugins_func.register import register_function, ToolType, ActionResponse, Action
 
if TYPE_CHECKING:
    from core.connection import ConnectionHandler
 
switch_app_function_desc = {
    "type": "function",
    "function": {
        "name": "switch_app",
        "description": (
            "切换设备当前 App。"
            "chat=对话;english_translation=翻译;english_conversation=中英对话;"
            "english_learning 需配合 task_id:repeater=泛听,shadowing=跟读。"
            "语音切换泛听/跟读时执行家长上次下发的课文,没有上次课文则提示先选课。"
            "退出当前模式、回到聊天时 app_id=chat。"
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "app_id": {
                    "type": "string",
                    "description": "chat、english_learning、english_translation、english_conversation",
                },
                "task_id": {
                    "type": "string",
                    "description": "可选。english_learning 下 repeater 或 shadowing;其它 App 可空",
                },
            },
            "required": ["app_id"],
        },
    },
}
 
 
@register_function("switch_app", switch_app_function_desc, ToolType.SYSTEM_CTL)
async def switch_app(conn: "ConnectionHandler", app_id: str, task_id: str = ""):
    from core.app_runtime.runtime import switch_app as runtime_switch
 
    result = await runtime_switch(conn, app_id, source="voice", task_id=task_id or "")
    if result.action == Action.ERROR:
        return ActionResponse(
            action=Action.RESPONSE,
            result=result.response,
            response=result.response or "打不开这个应用",
        )
    if str(result.result or "").startswith("chat/"):
        return ActionResponse(action=Action.NONE, result=result.result, response=result.response)
    name = result.response or "已切换"
    return ActionResponse(action=Action.RESPONSE, result=result.result, response=name)