diff --git a/akulai/akulai.py b/akulai/akulai.py index 150a669..48767eb 100755 --- a/akulai/akulai.py +++ b/akulai/akulai.py @@ -10,7 +10,7 @@ import vosk import sys from fastapi import FastAPI -import webbrowser +import time class JSPlugin: @@ -132,12 +132,17 @@ def stop(self): akulai = AkulAI() if __name__ == '__main__': + + # Run API server + os.system("uvicorn akulai:app --reload") + time.sleep(5) + # Create the listening thread akulai.stop_listening = threading.Event() akulai.listening_thread = threading.Thread(target=akulai.listen) akulai.listening_thread.start() - @app.get("/speak/{text}") + @app.post("/speak/{text}") async def speak(text: str): akulai.speak(text) return {"message": "Text synthesized"} @@ -146,8 +151,5 @@ async def speak(text: str): async def listen(): akulai.listen() return {"message": "Listening..."} - - # Run the server for the API - os.system("uvicorn akulai:app --reload") - webbrowser.open("http://127.0.0.1:8000") + akulai.speak("Hello, I am AkulAI. How can I help you today?") diff --git a/docs/create_plugins.md b/docs/create_plugins.md index da16bc2..9777b8a 100644 --- a/docs/create_plugins.md +++ b/docs/create_plugins.md @@ -12,7 +12,7 @@ Next, create a file in your sub-directory called `plugin.info`. It should look s ``` author: John Doe dependencies: requests, pandas -description: Lorem ipsum di olor nulla quis lorem ut libero malesuada feugiat. This plugin.info file is an example. See the akulai_plugins repository for more examples. +description: Lorem ipsum di olor nulla quis lorem ut libero malesuada feugiat. This plugin.info file is an example. ``` The dependencies may vary based on your project. Note that when listing the dependencies, list them by the name you installed them. For example, if you installed a dependency with `pip install py-example`(note that this is an example, and applies to all languages), but imported it with `import example`, you would still list the dependency `as py-example`. If you have no dependencies required to be installed, just leave it blank. @@ -30,7 +30,7 @@ import requests response = requests.get('http://127.0.0.1:8000/speak') def handle(command): if "hello" in command: - speak("Hello there!") + response.speak("Hello there!") ``` ## Javascript Plugins JavaScript plugins should read from the commandline and write to stdout using console.log(). diff --git a/plugins/calendar/main.js b/plugins/calendar/main.js index f7078a1..586d19f 100644 --- a/plugins/calendar/main.js +++ b/plugins/calendar/main.js @@ -1,6 +1,8 @@ const fs = require("fs"); const events = []; +fetch('http://127.0.0.1:8000/speak') + const addEvent = (event, date) => { events.push({event, date}); fs.writeFileSync("events.json", JSON.stringify(events)); @@ -14,7 +16,7 @@ const checkEvents = () => { const eventDate = new Date(event.date); if (now.getTime() >= eventDate.getTime()) { console.log("Reminder: " + event.event); - akulAI.speak("Reminder: " + event.event); + speak("Reminder: " + event.event); } }); }, 60000); diff --git a/plugins/stock_prices/main.pl b/plugins/stock_prices/main.pl deleted file mode 100644 index 7e8c815..0000000 --- a/plugins/stock_prices/main.pl +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/perl - -use LWP::UserAgent; - -sub fetch_stock_price { - my $ticker = shift; - - # Get stock information from Google Finance - my $url = "https://www.google.com/finance?q=$ticker"; - my $ua = LWP::UserAgent->new; - my $response = $ua->get($url); - - # Check if request was successful - if ($response->is_success) { - my $html = $response->decoded_content; - - # Extract the stock price - if ($html =~ /ref_.*_l">(.*?)<\/span>/i) { - return "The current stock price for $ticker is $1."; - } else { - return "Unable to find stock price for $ticker."; - } - } else { - return "Error fetching stock price for $ticker: " . $response->status_line; - } -} - -sub handle { - my $command = shift; - if ($command =~ /stock price for (.*)/i) { - return fetch_stock_price($1); - } - return "Invalid command."; -} - -1; diff --git a/plugins/stock_prices/plugin.info b/plugins/stock_prices/plugin.info deleted file mode 100644 index 3c1df57..0000000 --- a/plugins/stock_prices/plugin.info +++ /dev/null @@ -1,3 +0,0 @@ -author: Akul Goel -dependencies: LWP::UserAgent -description: This plugin tells you the stock prices when you ask it to. diff --git a/plugins/time_date/main.py b/plugins/time_date/main.py index c6c5382..ca08fd8 100644 --- a/plugins/time_date/main.py +++ b/plugins/time_date/main.py @@ -1,12 +1,16 @@ +import requests import datetime # define all commonly used variables here now = datetime.datetime.now() +response = requests.get('http://127.0.0.1:8000/speak') def handle(command): + if "time" in command: time_now = now.strftime("%H:%M:%S") - akulai.speak(f"The current time is{time_now}") + speak(f"The current time is{time_now}") + if "date" in command: date_now = now.strftime("%Y-%m-%d") - akulai.speak(f"The current date is{date_now}") + speak(f"The current date is{date_now}") \ No newline at end of file