-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapps.py
99 lines (94 loc) · 4.01 KB
/
apps.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
import os
import json
import subprocess
from groq import Groq
# Set up the Groq API client
client = Groq()
MODEL = 'llama3-70b-8192'
# Define the function to open an application
def open_app(app_name):
app_map = {
"chrome": "chrome.exe",
"firefox": "firefox.exe",
"obs": r"C:\Program Files\obs-studio\bin\64bit\obs64.exe", # Full path to OBS Studio executable
"geforce experience": r"C:\Program Files\NVIDIA Corporation\NVIDIA GeForce Experience\NVIDIA GeForce Experience.exe",
"vs code": r"C:\Users\Hari Prezadu\AppData\Local\Programs\Microsoft VS Code\Code.exe",
"vlc": "vlc.exe",
"windows media player": "wmplayer.exe",
"notepad": "notepad.exe",
"localsend": r"C:\Program Files\LocalSend\localsend_app.exe",
"proton vpn": r"C:\Program Files\Proton\VPN\v3.2.11\ProtonVPN.exe",
"excel": "EXCEL.EXE",
"outlook": "OUTLOOK.EXE",
"word": "WINWORD.EXE",
"powerpoint": "POWERPNT.EXE",
"onenote": "ONENOTE.EXE",
"access": "MSACCESS.EXE",
"publisher": "MSPUB.EXE",
"telegram": r"C:\Program Files\WindowsApps\TelegramMessengerLLP.TelegramDesktop_5.0.1.0_x64__t4vj0pshhgkwm\Telegram.exe",
"whatsapp": r"C:\Program Files\WindowsApps\5319275A.WhatsAppDesktop_2.2423.7.0_x64__cv1g1gvanyjgm\WhatsApp.exe",
"obsidian": r"C:\Users\Hari Prezadu\AppData\Local\Programs\obsidian\Obsidian.exe",
"spotify": "Spotify.exe"
# Add more apps as needed
}
if app_name.lower() in app_map:
executable_path = app_map[app_name.lower()]
try:
if app_name.lower() == "obs":
subprocess.Popen([executable_path], cwd=os.path.dirname(executable_path))
elif app_name.lower() == "geforce experience":
subprocess.Popen([executable_path], cwd=os.path.dirname(executable_path))
else:
os.startfile(executable_path)
return f"Opened {app_name} successfully!"
except Exception as e:
return f"Error opening {app_name}: {str(e)}"
else:
return f"Unsupported app: {app_name}"
# Define the conversation function that takes a user prompt as an argument
def run_conversation(user_prompt):
conversation_history = [{"role": "user", "content": user_prompt}]
messages = conversation_history.copy()
tools = [
{
"type": "function",
"function": {
"name": "open_app",
"description": "Open an application",
"parameters": {
"type": "object",
"properties": {
"app_name": {
"type": "string",
"description": "The name of the application to open",
}
},
"required": ["app_name"],
},
}
}
]
response = client.chat.completions.create(
model=MODEL,
messages=messages,
tools=tools,
tool_choice="auto",
max_tokens=4096
)
if hasattr(response.choices[0].message, 'tool_calls') and response.choices[0].message.tool_calls:
tool_call = response.choices[0].message.tool_calls[0]
arguments = json.loads(tool_call.function.arguments) # Parse the arguments string as JSON
app_name = arguments["app_name"]
result = open_app(app_name)
print(result)
conversation_history.append({"role": "assistant", "content": response.choices[0].message.content})
else:
print("No tool call was made in the response.")
conversation_history.append({"role": "assistant", "content": "No tool call was made in the response."})
# Note: No need for a main loop here since it's handled by main.py
# # Modify to get user_query from sys.argv[1] if available
# if len(sys.argv) > 1:
# user_query = sys.argv[1]
# # Return the result of run_conversation
# result = run_conversation(user_query)
# print(result) # Print the result for demonstration