Skip to content

Commit

Permalink
Merge pull request #78 from PavanTeja2005/PavanTeja2005-patch-1
Browse files Browse the repository at this point in the history
Final file opener code
  • Loading branch information
suryanshsk authored Oct 9, 2024
2 parents 7a3a896 + 6c7cc23 commit 6a63233
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gemini_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import google.generativeai as genai

# Configure the API key
genai.configure(api_key="API_Key") # Replace with your actual API key
genai.configure(api_key="API Key") # Replace with your actual API key

# Set up the model configuration
generation_config = {
Expand Down
23 changes: 20 additions & 3 deletions main_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from news_info import get_news
from jokes import tell_joke
from open_app import open_application
from open_files import *
from gemini_info import get_gemini_response
from song_data import SONGS
from website_data import WEBSITES
Expand Down Expand Up @@ -54,6 +55,10 @@ def abort(message):
RUNNING = False
print(message)

def openfile(file):
logging.info("openinig....", file)
return open_file(file)

def play_music(song_name=""):
if song_name == "":
response = "Which song would you like to play?"
Expand Down Expand Up @@ -87,9 +92,13 @@ def open_website(website_name = ""):
speak(response)
webbrowser.open(website_url)
else:
response = "Website not found in the database."
response = "Website not found in the database.Searching in google."
logging.warning(response)
speak(response)
from googlesearch import search
webs = search(website_name, advanced=True)
webbrowser.open(list(webs)[0].url)


TOOLS = [
{
Expand Down Expand Up @@ -151,7 +160,14 @@ def open_website(website_name = ""):
'description': 'Aborts',
'inputs': ['message'],
'action': abort
}
},
{
'name': 'openfile',
'description': 'Opens files',
'inputs': ['file'],
'action': openfile
},

]


Expand Down Expand Up @@ -246,7 +262,8 @@ def main():
7. "open_website": Requires "website_name" ( return an empty string if no website if specified )
8. "open_application": Requires "app_name".
9. "get_news": Requires no inputs.
9. "abort" : Requires a "message" . Call this if the user wants to leave.
10. "openfile": Requires "file" (If path is there give file name if there is location description please build file path from description)
10. "abort" : Requires a "message" . Call this if the user wants to leave.
If the tool requires no inputs, leave the "inputs" field empty.
Query: "{query}"
Expand Down
22 changes: 22 additions & 0 deletions open_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FILES = {
"file1": "path1",

}


import os

def open_file(file):
file_path = FILES.get(file)
if file_path:
os.open(file_path)
else:
if os.exists(file):
os.open(file)
else:
print("Please specify file path coorectly")
file = input("Enter file path:")
try:
os.open(file)
except:
print("Error opening file!.")

0 comments on commit 6a63233

Please sign in to comment.