-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcmd_agent.py
180 lines (171 loc) · 9.97 KB
/
cmd_agent.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
import platform
import google.generativeai as genai
import config
genai.configure(api_key=config.GEMINI_API_KEY)
# Create the model
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 40,
"max_output_tokens": 8192,
}
model = genai.GenerativeModel(
model_name="gemini-2.0-flash-exp",
generation_config=generation_config,
# system_instruction = f"""
#You are a helpful command line expert for {platform.system()} systems. You should only reply with JSON that contains two keys: "run" and "speak" to answer the user's question. The "run" key will contain the command to execute, and the "speak" key will contain any verbal response.
# """
)
def ask_agent_cmd(input):
response = model.generate_content([
"input: input",
"output: output",
"input: list all dir",
"output: { \"run\": \"dir\", \"speak\": \"listing all dir\" }",
"input: make python conda env",
"output: { \"run\": \"\", \"speak\": \"sir, what name should I keep for the environment?\" }",
"input: yes jarvis is the name",
"output: { \"run\": \"conda create -n jarvis python=3.9\", \"speak\": \"creating conda env sir\" }",
"input: how do I activate the environment?",
"output: { \"run\": \"conda activate jarvis\", \"speak\": \"activating conda env sir\" }",
"input: install numpy in the jarvis environment",
"output: { \"run\": \"conda install -n jarvis numpy\", \"speak\": \"installing numpy sir\" }",
"input: how to list all conda environments?",
"output: { \"run\": \"conda env list\", \"speak\": \"listing env\" }",
"input: deactivate the environment",
"output: { \"run\": \"conda deactivate\", \"speak\": \"deactivating the env instiated\" }",
"input: make a new folder named 'projects' in the current directory",
"output: { \"run\": \"mkdir projects\", \"speak\": \"making a new folder\" }",
"input: move to the projects folder",
"output: { \"run\": \"cd projects\", \"speak\": \"changing the location\" }",
"input: check system information",
"output: { \"run\": \"systeminfo\", \"speak\": \"fetching system information\" }",
"input: list all drives",
"output: { \"run\": \"wmic logicaldisk get name\", \"speak\": \"listing all drives\" }",
"input: create a new text file",
"output: { \"run\": \"echo. > newfile.txt\", \"speak\": \"creating a new text file\" }",
"input: open Notepad",
"output: { \"run\": \"start notepad\", \"speak\": \"opening Notepad\" }",
"input: check IP address",
"output: { \"run\": \"ipconfig\", \"speak\": \"checking IP address\" }",
"input: restart the computer",
"output: { \"run\": \"shutdown /r /f\", \"speak\": \"restarting the system\" }",
"input: shut down the computer",
"output: { \"run\": \"shutdown /s /f\", \"speak\": \"shutting down the system\" }",
"input: check system disk usage",
"output: { \"run\": \"dir\", \"speak\": \"checking disk usage in current directory\" }",
"input: list installed programs",
"output: { \"run\": \"wmic product get name\", \"speak\": \"listing installed programs\" }",
"input: set environment variable",
"output: { \"run\": \"setx VAR_NAME value\", \"speak\": \"setting environment variable\" }",
"input: check for running processes",
"output: { \"run\": \"tasklist\", \"speak\": \"listing running processes\" }",
"input: kill a process by name",
"output: { \"run\": \"taskkill /im process_name.exe /f\", \"speak\": \"killing the process\" }",
"input: create a new directory",
"output: { \"run\": \"mkdir newfolder\", \"speak\": \"creating a new directory\" }",
"input: change directory",
"output: { \"run\": \"cd path_to_directory\", \"speak\": \"changing directory\" }",
"input: check if a file exists",
"output: { \"run\": \"if exist filename.txt echo File exists\", \"speak\": \"checking if file exists\" }",
"input: delete a file",
"output: { \"run\": \"del filename.txt\", \"speak\": \"deleting the file\" }",
"input: copy a file",
"output: { \"run\": \"copy sourcefile.txt destinationfile.txt\", \"speak\": \"copying the file\" }",
"input: move a file",
"output: { \"run\": \"move sourcefile.txt destinationfolder\", \"speak\": \"moving the file\" }",
"input: rename a file",
"output: { \"run\": \"ren oldfilename.txt newfilename.txt\", \"speak\": \"renaming the file\" }",
"input: search for a file",
"output: { \"run\": \"dir /s /b filename.txt\", \"speak\": \"searching for the file\" }",
"input: display the system date and time",
"output: { \"run\": \"date /t && time /t\", \"speak\": \"displaying the date and time\" }",
"input: list services running",
"output: { \"run\": \"services.msc\", \"speak\": \"listing all services\" }",
"input: ping a website",
"output: { \"run\": \"ping www.example.com\", \"speak\": \"pinging the website\" }",
"input: create a Python virtual environment",
"output: { \"run\": \"python -m venv env_name\", \"speak\": \"creating a new Python virtual environment\" }",
"input: activate the Python virtual environment",
"output: { \"run\": \"env_name/Scripts/activate\", \"speak\": \"activating Python virtual environment\" }",
"input: install a package using pip",
"output: { \"run\": \"pip install package_name\", \"speak\": \"installing the package using pip\" }",
"input: list installed Python packages",
"output: { \"run\": \"pip list\", \"speak\": \"listing installed Python packages\" }",
"input: run a Python script",
"output: { \"run\": \"python script_name.py\", \"speak\": \"running the Python script\" }",
"input: create a new C++ file",
"output: { \"run\": \"echo. > program.cpp\", \"speak\": \"creating a new C++ file\" }",
"input: compile the C++ program",
"output: { \"run\": \"g++ program.cpp -o program.exe\", \"speak\": \"compiling the C++ program\" }",
"input: run the C++ program",
"output: { \"run\": \"program.exe\", \"speak\": \"running the compiled C++ program\" }",
"input: check if Node.js is installed",
"output: { \"run\": \"node -v\", \"speak\": \"checking if Node.js is installed\" }",
"input: install a package using npm",
"output: { \"run\": \"npm install package_name\", \"speak\": \"installing package using npm\" }",
"input: create a new Node.js application",
"output: { \"run\": \"npm init -y\", \"speak\": \"creating a new Node.js application\" }",
"input: start a React project",
"output: { \"run\": \"npx create-react-app project_name\", \"speak\": \"starting a new React project\" }",
"input: run a React app",
"output: { \"run\": \"npm start\", \"speak\": \"running the React application\" }",
"input: create a new Java file",
"output: { \"run\": \"echo. > Program.java\", \"speak\": \"creating a new Java file\" }",
"input: compile the Java program",
"output: { \"run\": \"javac Program.java\", \"speak\": \"compiling the Java program\" }",
"input: run the Java program",
"output: { \"run\": \"java Program\", \"speak\": \"running the Java program\" }",
"input: create a new HTML file",
"output: { \"run\": \"echo. > index.html\", \"speak\": \"creating a new HTML file\" }",
"input: open the HTML file in a browser",
"output: { \"run\": \"start index.html\", \"speak\": \"opening the HTML file in browser\" }",
"input: check if Git is installed",
"output: { \"run\": \"git --version\", \"speak\": \"checking if Git is installed\" }",
"input: initialize a new Git repository",
"output: { \"run\": \"git init\", \"speak\": \"initializing a new Git repository\" }",
"input: clone a Git repository",
"output: { \"run\": \"git clone repo_url\", \"speak\": \"cloning the Git repository\" }",
"input: check the status of a Git repository",
"output: { \"run\": \"git status\", \"speak\": \"checking the status of the Git repository\" }",
"input: add files to a Git repository",
"output: { \"run\": \"git add .\", \"speak\": \"adding files to the Git repository\" }",
"input: commit changes to a Git repository",
"output: { \"run\": \"git commit -m \"message\"\", \"speak\": \"committing changes to the Git repository\" }",
"input: push changes to a Git repository",
"output: { \"run\": \"git push\", \"speak\": \"pushing changes to the Git repository\" }",
"input: pull changes from a Git repository",
"output: { \"run\": \"git pull\", \"speak\": \"pulling changes from the Git repository\" }",
"input: check if Docker is installed",
"output: { \"run\": \"docker --version\", \"speak\": \"checking if Docker is installed\" }",
"input: build a Docker image",
"output: { \"run\": \"docker build -t image_name .\", \"speak\": \"building a Docker image\" }",
"input: run a Docker container",
"output: { \"run\": \"docker run -d -p 80:80 image_name\", \"speak\": \"running the Docker container\" }",
"input: stop a Docker container",
"output: { \"run\": \"docker stop container_id\", \"speak\": \"stopping the Docker container\" }",
"input: check if MySQL is installed",
"output: { \"run\": \"mysql --version\", \"speak\": \"checking if MySQL is installed\" }",
"input: start MySQL server",
"output: { \"run\": \"mysql.server start\", \"speak\": \"starting MySQL server\" }",
"input: connect to MySQL database",
"output: { \"run\": \"mysql -u root -p\", \"speak\": \"connecting to MySQL database\" }",
"input: create a new MySQL database",
"output: { \"run\": \"CREATE DATABASE db_name;\", \"speak\": \"creating a new MySQL database\" }",
"input: run a MySQL query",
"output: { \"run\": \"SELECT * FROM table_name;\", \"speak\": \"running the MySQL query\" }",
"input: check if PostgreSQL is installed",
"output: { \"run\": \"psql --version\", \"speak\": \"checking if PostgreSQL is installed\" }",
"input: start PostgreSQL server",
"output: { \"run\": \"pg_ctl start\", \"speak\": \"starting PostgreSQL server\" }",
"input: connect to PostgreSQL database",
"output: { \"run\": \"psql -U username -d db_name\", \"speak\": \"connecting to PostgreSQL database\" }",
"input: create a new PostgreSQL database",
"output: { \"run\": \"CREATE DATABASE db_name;\", \"speak\": \"creating a new PostgreSQL database\" }",
f"input: {input}",
"output: ",
])
print(f"Raw response: {response.text}")
return response.text
#response = ask_agent_cmd("hello")