jarvis-ai-assistant 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of jarvis-ai-assistant might be problematic. Click here for more details.

Files changed (42) hide show
  1. jarvis_ai_assistant-0.1.0/MANIFEST.in +4 -0
  2. jarvis_ai_assistant-0.1.0/PKG-INFO +125 -0
  3. jarvis_ai_assistant-0.1.0/README.md +94 -0
  4. jarvis_ai_assistant-0.1.0/pyproject.toml +45 -0
  5. jarvis_ai_assistant-0.1.0/setup.cfg +4 -0
  6. jarvis_ai_assistant-0.1.0/setup.py +41 -0
  7. jarvis_ai_assistant-0.1.0/src/jarvis/.jarvis +1 -0
  8. jarvis_ai_assistant-0.1.0/src/jarvis/__init__.py +3 -0
  9. jarvis_ai_assistant-0.1.0/src/jarvis/__pycache__/agent.cpython-313.pyc +0 -0
  10. jarvis_ai_assistant-0.1.0/src/jarvis/__pycache__/models.cpython-313.pyc +0 -0
  11. jarvis_ai_assistant-0.1.0/src/jarvis/__pycache__/tools.cpython-313.pyc +0 -0
  12. jarvis_ai_assistant-0.1.0/src/jarvis/__pycache__/utils.cpython-313.pyc +0 -0
  13. jarvis_ai_assistant-0.1.0/src/jarvis/agent.py +100 -0
  14. jarvis_ai_assistant-0.1.0/src/jarvis/main.py +161 -0
  15. jarvis_ai_assistant-0.1.0/src/jarvis/models.py +112 -0
  16. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__init__.py +22 -0
  17. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/__init__.cpython-313.pyc +0 -0
  18. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/base.cpython-313.pyc +0 -0
  19. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/file_ops.cpython-313.pyc +0 -0
  20. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/python_script.cpython-313.pyc +0 -0
  21. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/rag.cpython-313.pyc +0 -0
  22. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/search.cpython-313.pyc +0 -0
  23. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/shell.cpython-313.pyc +0 -0
  24. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc +0 -0
  25. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/user_interaction.cpython-313.pyc +0 -0
  26. jarvis_ai_assistant-0.1.0/src/jarvis/tools/__pycache__/webpage.cpython-313.pyc +0 -0
  27. jarvis_ai_assistant-0.1.0/src/jarvis/tools/base.py +155 -0
  28. jarvis_ai_assistant-0.1.0/src/jarvis/tools/file_ops.py +106 -0
  29. jarvis_ai_assistant-0.1.0/src/jarvis/tools/python_script.py +150 -0
  30. jarvis_ai_assistant-0.1.0/src/jarvis/tools/rag.py +154 -0
  31. jarvis_ai_assistant-0.1.0/src/jarvis/tools/search.py +48 -0
  32. jarvis_ai_assistant-0.1.0/src/jarvis/tools/shell.py +67 -0
  33. jarvis_ai_assistant-0.1.0/src/jarvis/tools/user_confirmation.py +58 -0
  34. jarvis_ai_assistant-0.1.0/src/jarvis/tools/user_interaction.py +86 -0
  35. jarvis_ai_assistant-0.1.0/src/jarvis/tools/webpage.py +90 -0
  36. jarvis_ai_assistant-0.1.0/src/jarvis/utils.py +105 -0
  37. jarvis_ai_assistant-0.1.0/src/jarvis_ai_assistant.egg-info/PKG-INFO +125 -0
  38. jarvis_ai_assistant-0.1.0/src/jarvis_ai_assistant.egg-info/SOURCES.txt +40 -0
  39. jarvis_ai_assistant-0.1.0/src/jarvis_ai_assistant.egg-info/dependency_links.txt +1 -0
  40. jarvis_ai_assistant-0.1.0/src/jarvis_ai_assistant.egg-info/entry_points.txt +2 -0
  41. jarvis_ai_assistant-0.1.0/src/jarvis_ai_assistant.egg-info/requires.txt +13 -0
  42. jarvis_ai_assistant-0.1.0/src/jarvis_ai_assistant.egg-info/top_level.txt +1 -0
@@ -0,0 +1,4 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include src/jarvis *
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.1
2
+ Name: jarvis-ai-assistant
3
+ Version: 0.1.0
4
+ Summary: Jarvis: An AI assistant that uses tools to interact with the system
5
+ Home-page: https://github.com/skyfireitdiy/Jarvis
6
+ Author: skyfire
7
+ Author-email: Your Name <your.email@example.com>
8
+ Project-URL: Homepage, https://github.com/skyfireitdiy/Jarvis
9
+ Keywords: jarvis,ai,assistant,tools,automation
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: requests>=2.25.1
20
+ Requires-Dist: beautifulsoup4>=4.9.3
21
+ Requires-Dist: duckduckgo-search>=3.0.0
22
+ Requires-Dist: pyyaml>=5.1
23
+ Requires-Dist: ollama>=0.1.6
24
+ Requires-Dist: sentence-transformers>=2.5.1
25
+ Requires-Dist: chromadb>=0.4.24
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest; extra == "dev"
28
+ Requires-Dist: black; extra == "dev"
29
+ Requires-Dist: isort; extra == "dev"
30
+ Requires-Dist: mypy; extra == "dev"
31
+
32
+ <div align="center">
33
+
34
+ # 🤖 Jarvis AI Assistant
35
+
36
+ <p align="center">
37
+ <img src="docs/images/jarvis-logo.png" alt="Jarvis Logo" width="200"/>
38
+ </p>
39
+
40
+ [![PyPI version](https://badge.fury.io/py/jarvis-ai.svg)](https://badge.fury.io/py/jarvis-ai)
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
42
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
43
+
44
+ *Your intelligent assistant for development and system interaction*
45
+
46
+ [Installation](#installation) •
47
+ [Features](#features) •
48
+ [Usage](#usage) •
49
+ [Tools](#tools) •
50
+ [Documentation](https://jarvis-ai.readthedocs.io/)
51
+
52
+ </div>
53
+
54
+ ---
55
+
56
+ ## 🌟 Features
57
+
58
+ 🤖 **Multiple AI Models**
59
+ - Ollama integration (llama3.2, qwen2.5:14b)
60
+ - DuckDuckGo AI search capabilities
61
+
62
+ 🛠️ **Rich Tool Integration**
63
+ - RAG (Retrieval-Augmented Generation)
64
+ - File operations & Shell commands
65
+ - Web search & content extraction
66
+ - Python code execution with dependency management
67
+
68
+ 🔄 **Interactive Experience**
69
+ - Natural language understanding
70
+ - Context-aware responses
71
+ - User-friendly interface
72
+
73
+ ## 🚀 Installation
74
+
75
+ ```bash
76
+ pip install jarvis-ai-assistant
77
+ ```
78
+
79
+ ## 💡 Usage
80
+
81
+ ```bash
82
+ # Quick Start
83
+ jarvis
84
+
85
+ # Using Specific Model
86
+ jarvis --platform ollama --model qwen2.5:14b
87
+
88
+ # Custom Ollama API
89
+ jarvis --platform ollama --model llama3.2 --api-base http://localhost:11434
90
+ ```
91
+
92
+ ## 🧰 Tools
93
+
94
+ | Tool | Description | Example |
95
+ |------|-------------|---------|
96
+ | 🔍 Search | Web search using DuckDuckGo | Search latest tech news |
97
+ | 📚 RAG | Document querying with embeddings | Query your documentation |
98
+ | 🐍 Python | Execute Python code | Run data analysis |
99
+ | 🖥️ Shell | Execute system commands | Manage files and processes |
100
+ | 📂 Files | Read/write operations | Handle configuration files |
101
+ | 🌐 Web | Extract webpage content | Gather information |
102
+ | 👤 User | Interactive input/confirmation | Get user preferences |
103
+
104
+
105
+ ## 🤝 Contributing
106
+
107
+ Contributions are welcome! Please feel free to submit a Pull Request.
108
+
109
+ 1. Fork the repository
110
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
111
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
112
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
113
+ 5. Open a Pull Request
114
+
115
+ ## 📄 License
116
+
117
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
118
+
119
+ ---
120
+
121
+ <div align="center">
122
+
123
+ Made with ❤️ by [Your Name]
124
+
125
+ </div>
@@ -0,0 +1,94 @@
1
+ <div align="center">
2
+
3
+ # 🤖 Jarvis AI Assistant
4
+
5
+ <p align="center">
6
+ <img src="docs/images/jarvis-logo.png" alt="Jarvis Logo" width="200"/>
7
+ </p>
8
+
9
+ [![PyPI version](https://badge.fury.io/py/jarvis-ai.svg)](https://badge.fury.io/py/jarvis-ai)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
12
+
13
+ *Your intelligent assistant for development and system interaction*
14
+
15
+ [Installation](#installation) •
16
+ [Features](#features) •
17
+ [Usage](#usage) •
18
+ [Tools](#tools) •
19
+ [Documentation](https://jarvis-ai.readthedocs.io/)
20
+
21
+ </div>
22
+
23
+ ---
24
+
25
+ ## 🌟 Features
26
+
27
+ 🤖 **Multiple AI Models**
28
+ - Ollama integration (llama3.2, qwen2.5:14b)
29
+ - DuckDuckGo AI search capabilities
30
+
31
+ 🛠️ **Rich Tool Integration**
32
+ - RAG (Retrieval-Augmented Generation)
33
+ - File operations & Shell commands
34
+ - Web search & content extraction
35
+ - Python code execution with dependency management
36
+
37
+ 🔄 **Interactive Experience**
38
+ - Natural language understanding
39
+ - Context-aware responses
40
+ - User-friendly interface
41
+
42
+ ## 🚀 Installation
43
+
44
+ ```bash
45
+ pip install jarvis-ai-assistant
46
+ ```
47
+
48
+ ## 💡 Usage
49
+
50
+ ```bash
51
+ # Quick Start
52
+ jarvis
53
+
54
+ # Using Specific Model
55
+ jarvis --platform ollama --model qwen2.5:14b
56
+
57
+ # Custom Ollama API
58
+ jarvis --platform ollama --model llama3.2 --api-base http://localhost:11434
59
+ ```
60
+
61
+ ## 🧰 Tools
62
+
63
+ | Tool | Description | Example |
64
+ |------|-------------|---------|
65
+ | 🔍 Search | Web search using DuckDuckGo | Search latest tech news |
66
+ | 📚 RAG | Document querying with embeddings | Query your documentation |
67
+ | 🐍 Python | Execute Python code | Run data analysis |
68
+ | 🖥️ Shell | Execute system commands | Manage files and processes |
69
+ | 📂 Files | Read/write operations | Handle configuration files |
70
+ | 🌐 Web | Extract webpage content | Gather information |
71
+ | 👤 User | Interactive input/confirmation | Get user preferences |
72
+
73
+
74
+ ## 🤝 Contributing
75
+
76
+ Contributions are welcome! Please feel free to submit a Pull Request.
77
+
78
+ 1. Fork the repository
79
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
80
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
81
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
82
+ 5. Open a Pull Request
83
+
84
+ ## 📄 License
85
+
86
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
87
+
88
+ ---
89
+
90
+ <div align="center">
91
+
92
+ Made with ❤️ by [Your Name]
93
+
94
+ </div>
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["setuptools>=45", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "jarvis-ai-assistant"
7
+ version = "0.1.0"
8
+ description = "Jarvis: An AI assistant that uses tools to interact with the system"
9
+ readme = "README.md"
10
+ authors = [{ name = "Your Name", email = "your.email@example.com" }]
11
+ license = { file = "LICENSE" }
12
+ classifiers = [
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.8",
17
+ "Programming Language :: Python :: 3.9",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ ]
21
+ keywords = ["jarvis", "ai", "assistant", "tools", "automation"]
22
+ dependencies = [
23
+ "requests>=2.25.1",
24
+ "beautifulsoup4>=4.9.3",
25
+ "duckduckgo-search>=3.0.0",
26
+ "pyyaml>=5.1",
27
+ "ollama>=0.1.6",
28
+ "sentence-transformers>=2.5.1",
29
+ "chromadb>=0.4.24",
30
+ ]
31
+ requires-python = ">=3.8"
32
+
33
+ [project.optional-dependencies]
34
+ dev = [
35
+ "pytest",
36
+ "black",
37
+ "isort",
38
+ "mypy",
39
+ ]
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/skyfireitdiy/Jarvis"
43
+
44
+ [project.scripts]
45
+ jarvis = "jarvis.main:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,41 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="jarvis-ai-assistant",
5
+ version="0.1.0",
6
+ author="skyfire",
7
+ author_email="skyfireitdiy@hotmail.com",
8
+ description="An AI assistant that uses various tools to interact with the system",
9
+ long_description=open("README.md").read(),
10
+ long_description_content_type="text/markdown",
11
+ url="https://github.com/skyfireitdiy/Jarvis",
12
+ packages=find_packages(where="src"),
13
+ package_dir={"": "src"},
14
+ include_package_data=True,
15
+ install_requires=[
16
+ "requests>=2.25.1",
17
+ "beautifulsoup4>=4.9.3",
18
+ "duckduckgo-search>=3.0.0",
19
+ "pyyaml>=5.1",
20
+ "ollama>=0.1.6",
21
+ "sentence-transformers>=2.5.1",
22
+ "chromadb>=0.4.24",
23
+ ],
24
+ entry_points={
25
+ "console_scripts": [
26
+ "jarvis=jarvis.main:main",
27
+ ],
28
+ },
29
+ python_requires=">=3.8",
30
+ classifiers=[
31
+ "Development Status :: 3 - Alpha",
32
+ "Intended Audience :: Developers",
33
+ "License :: OSI Approved :: MIT License",
34
+ "Operating System :: OS Independent",
35
+ "Programming Language :: Python :: 3",
36
+ "Programming Language :: Python :: 3.8",
37
+ "Programming Language :: Python :: 3.9",
38
+ "Programming Language :: Python :: 3.10",
39
+ "Programming Language :: Python :: 3.11",
40
+ ],
41
+ )
@@ -0,0 +1 @@
1
+ - 查看当前git仓库状态,如果有未提交的变更,自动根据当前仓库的文件修改内容总结生成一个git commit,然后执行git push推送到远端仓库,全流程不要询问用户
@@ -0,0 +1,3 @@
1
+ """Jarvis AI Assistant"""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,100 @@
1
+ import json
2
+ import subprocess
3
+ from typing import Dict, Any, List, Optional
4
+ from .tools import ToolRegistry
5
+ from .utils import Spinner, PrettyOutput, OutputType, get_multiline_input
6
+ from .models import BaseModel, OllamaModel
7
+ import re
8
+ import os
9
+ from datetime import datetime
10
+
11
+ class Agent:
12
+ def __init__(self, model: BaseModel, tool_registry: ToolRegistry):
13
+ self.model = model
14
+ self.tool_registry = tool_registry
15
+ # 编译正则表达式
16
+ self.tool_call_pattern = re.compile(r'<tool_call>\s*({[^}]+})\s*</tool_call>')
17
+ self.messages = [
18
+ {
19
+ "role": "system",
20
+ "content": """You are a rigorous AI assistant, all data must be obtained through tools, and no fabrication or speculation is allowed. """ + "\n" + self.tool_registry.tool_help_text()
21
+ }
22
+ ]
23
+ self.spinner = Spinner()
24
+
25
+ def _call_model(self, messages: List[Dict], use_tools: bool = True) -> Dict:
26
+ """调用模型获取响应"""
27
+ self.spinner.start()
28
+ try:
29
+ return self.model.chat(
30
+ messages=messages,
31
+ tools=self.tool_registry.get_all_tools() if use_tools else None
32
+ )
33
+ except Exception as e:
34
+ raise Exception(f"模型调用失败: {str(e)}")
35
+ finally:
36
+ self.spinner.stop()
37
+
38
+
39
+ def run(self, user_input: str) :
40
+ """处理用户输入并返回响应"""
41
+ # 检查是否是结束命令
42
+ self.clear_history()
43
+ self.messages.append({
44
+ "role": "user",
45
+ "content": user_input
46
+ })
47
+ while True:
48
+ try:
49
+ # 获取初始响应
50
+ response = self._call_model(self.messages)
51
+ current_response = response
52
+
53
+ # 将工具执行结果添加到对话
54
+ self.messages.append({
55
+ "role": "assistant",
56
+ "content": response["message"].get("content", ""),
57
+ "tool_calls": current_response["message"]["tool_calls"]
58
+ })
59
+
60
+ # 处理可能的多轮工具调用
61
+ if len(current_response["message"]["tool_calls"]) > 0:
62
+ # 添加当前助手响应到输出(如果有内容)
63
+ if current_response["message"].get("content"):
64
+ PrettyOutput.print(current_response["message"]["content"], OutputType.SYSTEM)
65
+
66
+ # 使用 ToolRegistry 的 handle_tool_calls 方法处理工具调用
67
+ tool_result = self.tool_registry.handle_tool_calls(current_response["message"]["tool_calls"])
68
+ PrettyOutput.print(tool_result, OutputType.RESULT)
69
+
70
+ self.messages.append({
71
+ "role": "tool",
72
+ "content": tool_result
73
+ })
74
+ continue
75
+
76
+ # 添加最终响应到对话历史和输出
77
+ final_content = current_response["message"].get("content", "")
78
+
79
+ if final_content:
80
+ PrettyOutput.print(final_content, OutputType.SYSTEM)
81
+
82
+
83
+ # 如果没有工具调用且响应很短,可能需要继续对话
84
+ user_input = get_multiline_input("您可以继续输入,或输入空行结束当前任务")
85
+ if not user_input:
86
+ PrettyOutput.print("===============任务结束===============", OutputType.INFO)
87
+ break
88
+
89
+ self.messages.append({
90
+ "role": "user",
91
+ "content": user_input
92
+ })
93
+
94
+ except Exception as e:
95
+ error_msg = f"处理响应时出错: {str(e)}"
96
+ PrettyOutput.print(error_msg, OutputType.ERROR)
97
+
98
+ def clear_history(self):
99
+ """清除对话历史,只保留系统提示"""
100
+ self.messages = [self.messages[0]]
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env python3
2
+ """Command line interface for Jarvis."""
3
+
4
+ import argparse
5
+ import yaml
6
+ import os
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ # 添加父目录到Python路径以支持导入
11
+ sys.path.insert(0, str(Path(__file__).parent.parent))
12
+
13
+ from jarvis.agent import Agent
14
+ from jarvis.tools import ToolRegistry
15
+ from jarvis.models import DDGSModel, OllamaModel
16
+ from jarvis.utils import PrettyOutput, OutputType, get_multiline_input
17
+
18
+ # 定义支持的平台和模型
19
+ SUPPORTED_PLATFORMS = {
20
+ "ollama": {
21
+ "models": ["llama3.2", "qwen2.5:14b"],
22
+ "default": "qwen2.5:14b"
23
+ },
24
+ "ddgs": {
25
+ "models": ["gpt-4o-mini", "claude-3-haiku", "llama-3.1-70b", "mixtral-8x7b"],
26
+ "default": "gpt-4o-mini"
27
+ }
28
+ }
29
+
30
+ def load_tasks() -> list:
31
+ """Load tasks from .jarvis file if it exists."""
32
+ if not os.path.exists(".jarvis"):
33
+ return []
34
+
35
+ try:
36
+ with open(".jarvis", "r", encoding="utf-8") as f:
37
+ tasks = yaml.safe_load(f)
38
+
39
+ if not isinstance(tasks, list):
40
+ PrettyOutput.print("Warning: .jarvis file should contain a list of tasks", OutputType.ERROR)
41
+ return []
42
+
43
+ return [str(task) for task in tasks if task] # Convert all tasks to strings and filter out empty ones
44
+ except Exception as e:
45
+ PrettyOutput.print(f"Error loading .jarvis file: {str(e)}", OutputType.ERROR)
46
+ return []
47
+
48
+ def select_task(tasks: list) -> str:
49
+ """Let user select a task from the list or skip."""
50
+ if not tasks:
51
+ return ""
52
+
53
+ PrettyOutput.print("\nFound predefined tasks:", OutputType.INFO)
54
+ for i, task in enumerate(tasks, 1):
55
+ PrettyOutput.print(f"[{i}] {task}", OutputType.INFO)
56
+ PrettyOutput.print("[0] Skip predefined tasks", OutputType.INFO)
57
+
58
+ while True:
59
+ try:
60
+ choice = input("\nSelect a task number (0 to skip): ").strip()
61
+ if not choice:
62
+ return ""
63
+
64
+ choice = int(choice)
65
+ if choice == 0:
66
+ return ""
67
+ elif 1 <= choice <= len(tasks):
68
+ return tasks[choice - 1]
69
+ else:
70
+ PrettyOutput.print("Invalid choice. Please try again.", OutputType.ERROR)
71
+ except ValueError:
72
+ PrettyOutput.print("Please enter a valid number.", OutputType.ERROR)
73
+
74
+ def main():
75
+ """Main entry point for Jarvis."""
76
+ parser = argparse.ArgumentParser(description="Jarvis AI Assistant")
77
+
78
+ # 添加平台选择参数
79
+ parser.add_argument(
80
+ "--platform",
81
+ choices=list(SUPPORTED_PLATFORMS.keys()),
82
+ default="ollama",
83
+ help="选择运行平台 (默认: ollama)"
84
+ )
85
+
86
+ # 添加模型选择参数
87
+ parser.add_argument(
88
+ "--model",
89
+ help="选择模型 (默认: 根据平台自动选择)"
90
+ )
91
+
92
+ # 添加API基础URL参数
93
+ parser.add_argument(
94
+ "--api-base",
95
+ default="http://localhost:11434",
96
+ help="Ollama API基础URL (仅用于Ollama平台, 默认: http://localhost:11434)"
97
+ )
98
+
99
+ args = parser.parse_args()
100
+
101
+ # 验证并设置默认模型
102
+ if args.model:
103
+ if args.model not in SUPPORTED_PLATFORMS[args.platform]["models"]:
104
+ supported_models = ", ".join(SUPPORTED_PLATFORMS[args.platform]["models"])
105
+ PrettyOutput.print(
106
+ f"错误: 平台 {args.platform} 不支持模型 {args.model}\n"
107
+ f"支持的模型: {supported_models}",
108
+ OutputType.ERROR
109
+ )
110
+ return 1
111
+ else:
112
+ args.model = SUPPORTED_PLATFORMS[args.platform]["default"]
113
+
114
+ try:
115
+ # 根据平台创建相应的模型实例
116
+ if args.platform == "ollama":
117
+ model = OllamaModel(
118
+ model_name=args.model,
119
+ api_base=args.api_base
120
+ )
121
+ platform_name = f"Ollama ({args.model})"
122
+ else: # ddgs
123
+ model = DDGSModel(model_name=args.model)
124
+ platform_name = f"DuckDuckGo Search ({args.model})"
125
+
126
+ tool_registry = ToolRegistry()
127
+ agent = Agent(model, tool_registry)
128
+
129
+ # 欢迎信息
130
+ PrettyOutput.print(f"Jarvis 已初始化 - {platform_name}", OutputType.SYSTEM)
131
+
132
+ # 加载预定义任务
133
+ tasks = load_tasks()
134
+ if tasks:
135
+ selected_task = select_task(tasks)
136
+ if selected_task:
137
+ PrettyOutput.print(f"\n执行任务: {selected_task}", OutputType.INFO)
138
+ agent.run(selected_task)
139
+ return 0
140
+
141
+ # 如果没有选择预定义任务,进入交互模式
142
+ while True:
143
+ try:
144
+ user_input = get_multiline_input("请输入您的任务(输入空行退出):")
145
+ if not user_input:
146
+ break
147
+ agent.run(user_input)
148
+ except KeyboardInterrupt:
149
+ print("\n正在退出...")
150
+ break
151
+ except Exception as e:
152
+ PrettyOutput.print(f"错误: {str(e)}", OutputType.ERROR)
153
+
154
+ except Exception as e:
155
+ PrettyOutput.print(f"初始化错误: {str(e)}", OutputType.ERROR)
156
+ return 1
157
+
158
+ return 0
159
+
160
+ if __name__ == "__main__":
161
+ exit(main())