Skip to content

dennisGustavsson/ai-codegenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Code Generator with Memory

A powerful AI-powered code generation tool that leverages Google's Gemini AI to generate code from natural language prompts. The application features conversation memory, allowing it to remember and build upon previous instructions for iterative code development.

🌟 Features

  • AI-Powered Code Generation: Uses Google's Gemini 2.5 Flash Lite model to generate code from natural language descriptions
  • Conversational Memory: Maintains conversation history to understand context and handle follow-up instructions
  • Interactive Chat Interface: User-friendly chat-based UI built with Streamlit
  • Multiple Language Support: Can generate code in various programming languages (Python, JavaScript, HTML, CSS, etc.)
  • Code Syntax Highlighting: Automatically displays generated code with proper syntax highlighting
  • Iterative Development: Refine and modify code through natural conversation

🚀 Prerequisites

Before you begin, ensure you have the following installed:

  • Python 3.8 or higher
  • pip (Python package installer)
  • A Google AI API key (Get one at Google AI Studio)

📦 Installation

  1. Clone the repository

    git clone https://github.com/dennisGustavsson/agent-testproject.git
    cd agent-testproject
  2. Create a virtual environment (recommended)

    python -m venv venv
    
    # On Linux/macOS:
    source venv/bin/activate
    
    # On Windows:
    venv\Scripts\activate
  3. Install required dependencies

    pip install -r requirements.txt

    Or install manually:

    pip install streamlit google-generativeai python-dotenv

⚙️ Configuration

  1. Create a .env file in the project root directory:

    touch .env
  2. Add your Google AI API key to the .env file:

    GOOGLE_API_KEY=your_api_key_here
    

    Security Note: Never commit your .env file to version control. It's already included in .gitignore.

  3. Alternative: Set the API key as an environment variable:

    # On Linux/macOS:
    export GOOGLE_API_KEY='your_api_key_here'
    
    # On Windows:
    set GOOGLE_API_KEY=your_api_key_here

🎯 Usage

  1. Start the application

    streamlit run app.py
  2. Access the web interface

    • The application will automatically open in your default browser
    • If not, navigate to http://localhost:8501
  3. Generate code

    • Type your code generation request in the chat input
    • Press Enter to submit
    • The AI will generate code based on your request
    • Continue the conversation to refine or modify the code

💡 Example Prompts

Here are some example prompts to get you started:

Python Examples

"Write a Python function to calculate the factorial of a number."
"Now, modify that function to handle negative inputs by raising a ValueError."
"Add type hints and docstrings to the factorial function."

Web Development Examples

"Generate a simple HTML page with a heading 'My Page' and a paragraph 'Welcome!'."
"Create a JavaScript snippet to change the background color to blue when a button is clicked."
"Refactor the previous JavaScript to use an event listener instead of inline onclick."

Data Processing Examples

"Write a Python function to read a CSV file and calculate the average of a specific column."
"Add error handling for missing files and invalid data."

🛠️ Technology Stack

📁 Project Structure

agent-testproject/
├── app.py              # Main application file
├── INSTRUCTIONS.md     # Detailed implementation guide
├── requirements.txt    # Python dependencies
├── .env               # Environment variables (not tracked)
├── .gitignore         # Git ignore rules
└── README.md          # This file

🔒 Security Considerations

  • API Keys: Always store API keys in environment variables or .env files, never in source code
  • Code Review: Always review and test AI-generated code before using it in production
  • Rate Limits: Be mindful of API rate limits and costs associated with AI model usage
  • Input Validation: The AI may generate code that needs validation and testing

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is open source and available for educational and commercial use.

🐛 Troubleshooting

Common Issues

Issue: "API key not found" error

  • Solution: Ensure your .env file exists and contains GOOGLE_API_KEY=your_key
  • Verify the .env file is in the same directory as app.py

Issue: "Module not found" errors

  • Solution: Make sure all dependencies are installed: pip install streamlit google-generativeai python-dotenv

Issue: Streamlit won't start

  • Solution: Check if port 8501 is already in use. You can specify a different port:
    streamlit run app.py --server.port 8502

📚 Additional Resources

👨‍💻 Author

Dennis Gustavsson

🙏 Acknowledgments

  • Google AI for providing the Gemini API
  • Streamlit team for the excellent UI framework
  • The AI/ML community for inspiration and best practices

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages