@@ -27,45 +27,65 @@ class OllamaService {
2727
2828 /// 识别用户意图
2929 Future <Map <String , dynamic >> recognizeIntent (String userInput) async {
30- final prompt = '''
31- 你是一个智能助手,负责识别用户的指令意图。
32-
33- 用户输入:$userInput
34-
35- 请分析用户的意图,并返回 JSON 格式的结果:
36- {
37- "intent": "意图名称",
38- "confidence": 0.0-1.0,
39- "parameters": {参数}
40- }
41-
42- 可用的意图类型:
43- - screenshot: 截屏、截图
44- - open_app: 打开应用(参数:app_name)
45- 示例:"打开 Chrome" → {"intent": "open_app", "parameters": {"app_name": "Chrome"}}
46- - close_app: 关闭应用(参数:app_name)
47- - open_url: 打开网址(参数:url)
48- - web_search: 网络搜索(参数:query)
49- - system_info: 获取系统信息
50- - open_file: 打开文件(参数:path)
51- - run_command: 运行 shell 命令(参数:command, args)
52- - check_process: 检查进程是否运行(参数:process_name)
53- 示例:"检查 chrome 是否运行" → {"intent": "check_process", "parameters": {"process_name": "chrome"}}
54- - list_processes: 列出运行中的进程
55- - file_operation: 文件操作(参数:operation, directory)
56- 示例:"查看桌面的文件" → {"intent": "file_operation", "parameters": {"operation": "list", "directory": "~/Desktop"}}
57- 示例:"搜索文档文件夹的PDF" → {"intent": "file_operation", "parameters": {"operation": "search", "directory": "~/Documents", "pattern": "pdf"}}
58- - ai_query: AI 问答(参数:query)
59-
60- 重要识别规则:
61- 1. 检查进程/程序是否运行 → check_process(不是 system_info)
62- 2. 列出运行中的程序 → list_processes(不是 file_operation)
63- 3. 查看/列出/浏览文件 → file_operation(不是 list_processes)
64- 4. 搜索文件 → file_operation(operation: search)
65- 5. 需要执行 shell 命令 → run_command
66- 6. 获取系统信息(版本、CPU等)→ system_info
67-
68- 只返回 JSON,不要其他内容。
30+ final prompt = '''You are an intent classifier for a macOS automation assistant. Analyze the user's input and return JSON.
31+
32+ User input: $userInput
33+
34+ Return JSON format:
35+ {"intent": "intent_name", "confidence": 0.0-1.0, "parameters": {params}}
36+
37+ Available intents:
38+
39+ 1. **open_url** - Open a website (params: url)
40+ "open twitter" → {"intent": "open_url", "parameters": {"url": "https://twitter.com"}}
41+ "send message on twitter" → {"intent": "open_url", "parameters": {"url": "https://twitter.com"}}
42+ "check my email" → {"intent": "open_url", "parameters": {"url": "https://mail.google.com"}}
43+
44+ 2. **open_app** - Open a macOS application (params: app_name)
45+ "open Chrome" → {"intent": "open_app", "parameters": {"app_name": "Google Chrome"}}
46+ "launch Terminal" → {"intent": "open_app", "parameters": {"app_name": "Terminal"}}
47+
48+ 3. **close_app** - Close/quit an application (params: app_name)
49+ "close Safari" → {"intent": "close_app", "parameters": {"app_name": "Safari"}}
50+ "kill Chrome" → {"intent": "close_app", "parameters": {"app_name": "Google Chrome"}}
51+
52+ 4. **run_command** - Execute a shell command (params: command, args)
53+ Simple commands:
54+ "what's my IP" → {"intent": "run_command", "parameters": {"command": "curl", "args": ["-s", "ifconfig.me"]}}
55+ "check disk space" → {"intent": "run_command", "parameters": {"command": "df", "args": ["-h"]}}
56+ "git status" → {"intent": "run_command", "parameters": {"command": "git", "args": ["status"]}}
57+
58+ Multi-step scripts (use bash -c for chained commands):
59+ "show largest files" → {"intent": "run_command", "parameters": {"command": "bash", "args": ["-c", "du -ah ~ -d 3 2>/dev/null | sort -rh | head -20"]}}
60+ "kill process on port 3000" → {"intent": "run_command", "parameters": {"command": "bash", "args": ["-c", "lsof -t -i:3000 | xargs kill -9"]}}
61+ "compress downloads" → {"intent": "run_command", "parameters": {"command": "bash", "args": ["-c", "cd ~/Downloads && zip -r ~/Desktop/archive.zip ."]}}
62+ "show open ports" → {"intent": "run_command", "parameters": {"command": "bash", "args": ["-c", "lsof -i -P -n | grep LISTEN"]}}
63+ "backup documents" → {"intent": "run_command", "parameters": {"command": "bash", "args": ["-c", "rsync -av ~/Documents/ ~/Desktop/backup/"]}}
64+
65+ macOS automation via AppleScript (use osascript -e):
66+ "create a note about shopping" → {"intent": "run_command", "parameters": {"command": "osascript", "args": ["-e", "tell application \\ "Notes\\ " to make new note with properties {name:\\ "shopping\\ "}"]}}
67+ "set volume to 50" → {"intent": "run_command", "parameters": {"command": "osascript", "args": ["-e", "set volume output volume 50"]}}
68+ "empty trash" → {"intent": "run_command", "parameters": {"command": "osascript", "args": ["-e", "tell application \\ "Finder\\ " to empty the trash"]}}
69+ "toggle dark mode" → {"intent": "run_command", "parameters": {"command": "osascript", "args": ["-e", "tell application \\ "System Events\\ " to tell appearance preferences to set dark mode to not dark mode"]}}
70+
71+ 5. **web_search** - Search the web (params: query)
72+ 6. **screenshot** - Take a screenshot (no params)
73+ 7. **system_info** - Get system information (no params)
74+ 8. **check_process** - Check if a process is running (params: process_name)
75+ 9. **list_processes** - List running processes (no params)
76+ 10. **file_operation** - Browse/list/search files (params: operation, directory, pattern)
77+ 11. **ai_query** - General questions needing AI (params: query)
78+
79+ RULES:
80+ 1. Social media actions → open_url with the platform URL
81+ 2. Multi-step operations → run_command with command: "bash", args: ["-c", "cmd1 && cmd2"]
82+ 3. macOS app automation → run_command with command: "osascript", args: ["-e", "applescript"]
83+ 4. args MUST be a JSON array of strings
84+ 5. run_command is the UNIVERSAL FALLBACK
85+ 6. NEVER return "unknown"
86+ 7. confidence >= 0.7
87+
88+ Return ONLY JSON.
6989''' ;
7090
7191 try {
0 commit comments