In this ever-evolving world, AI has become a must-have on your resume, and using AI in our side projects can surely give us an advantage over those who don’t. but AI is expensive? or is it?
First and foremost, let me clarify that by side projects I don’t necessarily mean weird, dumb projects made just for fun, but projects that actually solve a problem.
Sure, you can have fun along the way, but make it in such a way that it always has the potential to become a successful SaaS.
I have seen many programmers build a successful SaaS business by accident. They started it as a side project, but it later turned out to be a profitable business, allowing them to make lots of money.
So be cautious — you never know when your chance will come.
How AI can make our application better?
Using an AI API can significantly enhance our application’s capabilities. For instance, you can create a Personalized Content Recommendation Engine, an Automated Language Translation and Summarization Tool, or explore countless other possibilities limited only by the breadth of AI itself.
Which AI model to choose?
Once you’ve finalized the idea on which the application is going to be based, we can then proceed to choosing the right model.
There are numerous options available, including the well-known OpenAI API, although it’s not free.
We need to find an AI API that is not only powerful but also free of charge. However, many AI APIs are expensive.
One alternative is to use AI locally, which is free, but if you tried to host it on the internet you will most likely go bankrupt.
I also hustled a lot to find a perfect API that aligns with both my needs and budget, and my search ended when I found out about the Gemini ecosystem.
Google’s Gemini is another well-known AI provider, made by google and fortunately, they offer a free-forever plan.
Pricing of Google gemini
Like I mentioned earlier, unlike other AI API providers, Google Gemini provides a free forever plan, which is perfect for us developers to create side projects using AI.
Gemini offers free access to three models under their free tier.
And maximum 15 RPM (requests per minute) and 1,500 RPD (requests per day) which is more than enough to get started and you can always pay to get more once your app scales larger.
Getting things ready to start working
First of all you need a Google account (obviously), and then you can just simply head over to Aistudio.google.com, and on the left sidebar hit the “Get API key” button and that's it, you got the api key!
you can test how AI will respond by clicking on “create new prompt” and then “chat prompt” .
Using the API in the code
Start by creating a project in your desired language, i will use JavaScript for this purpose.
1- Install the Generative AI SDK
npm install @google/generative-ai
2- Import/Require the dependencies
const {
GoogleGenerativeAI,
HarmCategory,
HarmBlockThreshold,
} = require("@google/generative-ai")`;
3- Store your API key in a variable, and initialize Google Generative AI
const apiKey = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenerativeAI(apiKey);
4- Select a model and few configuration
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
});
const generationConfig = {
temperature: 1,
topP: 0.95,
topK: 64,
maxOutputTokens: 8192,
responseMimeType: "text/plain",
};
5- Initialize chat session
const chatSession = model.startChat({
generationConfig,
// safetySettings: Adjust safety settings
// See https://ai.google.dev/gemini-api/docs/safety-settings
history: [
{
role: "user",
parts: [
{text: "hey there\n"},
],
},
{
role: "model",
parts: [
{text: "Hey there! What can I do for you today? \n"},
],
},
],
});
6- finally start calling the “chatSession” function to talk to the model
const results = await chatSession.sendMessage("Is javascript enough to takeover the world?")
console.log(results) //That's a fun question! While JavaScript is incredibly powerful and plays a huge role in the digital world..
and that's it! you have successfully created (a very basic) AI powered application, now there’s one to keep in mind that: the only thats limited here is your imagination!
Stay updated with the latest trends in the world of code! Sign up for Code Whispers and never miss out on the latest insights, tips, and updates.
Top comments (0)