akulai
akulai copied to clipboard
Add an API for plugins
The previous PR, #12, was discontinued because I messed up somewhere and wasn't able to do anything about it. But, I have ported the same changes to this new version with less messy commits.
This basically gives all plugins access to the speak and listen functions when run, so they too can speak and listen when needed rather than printing output in CMD or listening once without follow-up questions.
Hi @aaronchantrill, I have made some changes and would like you to review them as I am not as experienced with Perl/JS as I am with Python, so I'm not sure if I got anything wrong. Please try to doit as soon as possible so that I can update the plugins in the akulai-plugins repository when finished.
Okay, I think I understand what the problem was. I had to move the api setup stuff above the if name == main but below the AkulAI() class definition. Then I changed it to use different paths for speak and listen:
@app.get("/speak/{text}")
async def speak(text: str):
akulai.speak(text)
return {"message": "Text synthesized"}
@app.post("/listen")
async def listen():
akulai.listen()
return {"message": "Listening..."}
At that point I was able to start the program and then navigate to http://localhost:8000/speak/Hello+There to get it to say "Hello plus There". I guess it does not automatically urldecode the query string values.
I will add your proposed changes right now. I'm not sure how I would implement urldecode, however.
I'm still having some issues with this. I'll try to submit a pull request. I'm trying to figure out why it won't shut down when I ask it to right now. Are you running this code on your system?
Yes, I just pressed Ctrl+C and ignored it, because I considered it a trivial problem. I'll look into it now, though.
There seems to be a problem where the plugins can't access the FastAPI server. I'm not sure what is causing this, any ideas?
Rather than calling through a server, I'm thinking we could just wrap the functions into a command line interface, through which the respective languages will have their own functions for. (for example, JS listen function will run a command in js to run the listen function)