Daily Python Projects

Daily Python Projects

Share this post

Daily Python Projects
Daily Python Projects
Build a Calculator Chatbot with Gemini and LangChain

Build a Calculator Chatbot with Gemini and LangChain

Ardit Sulce's avatar
Ardit Sulce
Jul 24, 2025
∙ Paid
3

Share this post

Daily Python Projects
Daily Python Projects
Build a Calculator Chatbot with Gemini and LangChain
Share

Project Task

Your task for today is to build a calculator chatbot using LangChain and Gemini. This project combines the power of LLMs with custom system prompts to simulate tools — in this case, a simple command-line calculator.

The program should:

  • Load your Gemini API key from an .env file using dotenv.

  • Create a Gemini-based chatbot using the ChatGoogleGenerativeAI class from LangChain.

  • Use a system prompt that instructs the model to act as a calculator.

  • Accept user input (e.g., 45 + 12) repeatedly.

  • Let the Gemini model respond with the answer.

  • Keep track of conversation history to maintain context.

  • Exit the loop when the user types "exit".

This project introduces you to LangChain’s Gemini integration, environment variables, and basic conversational AI applications with a practical utility flavor.

📌 Expected Output

When you run the program, it should prompt the user to type a math expression. Each expression is passed to the Gemini API, and the response is printed as a "Calculator" reply.

Example interaction:

The assistant will behave like a calculator, returning results based on the prompt you’ve given.

▶️ Start Coding Now in Colab

Jump straight into this project’s interactive notebook with full instructions, hints, and full runnable solutions.

🔒 Click below to access:

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Ardit Sulce
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share