If you've been around the internet recently, you've probably heard about the boom in artificial intelligence and chatbots.
And that's why I got to jump on the bandwagon as well
But as a programming enthusiast, I've always wondered how exactly AI algorithms work, and especially how AI can learn to create art, finish my math homework and even write code!
Created by the "Stable Diffusion" AI |
My first attempts
My AI meme maker (JS) |
AI with ChatBot APIs
In order to use the API, you need a HuggingFace account. You can make one for free at their website, https://huggingface.co/
You will need this account, because you will have to insert your account details into your code in order for it to work:
sign = Login("Put your email in here", "and your password here")
cookies = sign.login()
sign.saveCookies()
Finally, setup the chatbot by using this code snippet:
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
Now it should be working, to test it try something like this:
print(chatbot.chat("Hello"))
Now, if the code and API is working correctly, you'll get a response in your shell that looks like this:
Hello! I am your AI Assistant, ready to assist you. How can I help?
Pretty interesting! Now that you've got the base code ready, you might want to add some other things.
For my first project I decided to make a bot that is a little funny. I ended up using this prompt for it:
Answer this question, except this time, provide an incorrect, funny, sarcastic answer. Here is the question:
As you can see I got some funny responses 😆
This may look daunting, but it's actually just the prompt- and a few lines of code:
messages = input()
print(chatbot.chat("Answer this question, except this time, provide an incorrect, funny, sarcastic answer. Here is the question: " + messages))
Plus you can use chatbot.chat anywhere, so you can do even more things than just make chatbots. For example, I've been working on an AI app that can help you edit documents and more. It connects to your text document and then uses chatbot.chat to give suggestions. (Maybe I'll release it soon 😉)
Hopefully you found this as interesting as I did and I'd love to see what you create!
Also- You may want to check out the full documentation on the Python API - https://github.com/Soulter/hugging-chat-api
There are more options and settings there that I did not cover. I'd like to thank the people that made this API as it is extremely helpful and I'm glad to see more free options coming.
No comments:
Post a Comment