Unleash the power of Google's Gemini in your Python projects! 🚀
Features • Installation • Usage • Documentation • Contributing
🔐 Secure Authentication |
🔄 Dynamic Sessions |
💬 Multi-Conversation Support |
🌐 Context Preservation |
🖼️ Image Response Handling |
⏱️ Customizable Timeouts |
🎭 User-Agent Randomization |
🔍 Conversation Tracking |
Click to expand detailed setup instructions
-
Clone the Repository:
git clone https://github.com/OE-LUCIFER/Gemini-Chat-API.git cd Gemini-Chat-API
-
Set Up Virtual Environment (Recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
-
Cookie Configuration:
- Install Cookie-Editor extension
- Visit gemini.google.com
- Export cookies and save as
cookie.json
in the project root
-
Verify Installation:
python -c "from gemini import Gemini; print('Setup successful!')"
from gemini import Gemini
# Initialize Gemini client
gemini = Gemini('cookie.json')
# Create a new conversation
chat = gemini.create_conversation("AI_Ethics")
# Ask a question
response = gemini.ask("What are the key ethical considerations in AI development?", chat)
print(f"Gemini says: {response['content']}")
# Handle image responses
if response['images']:
print(f"Related images: {response['images']}")
Expand for API details and advanced usage
class Gemini:
def __init__(self, cookie_path: str, timeout: int = 30)
create_conversation(name: str) -> str
switch_conversation(name: str) -> None
list_conversations() -> list
delete_conversation(name: str) -> None
ask(question: str, conversation: str = None) -> dict
gemini.create_conversation("Science")
gemini.create_conversation("Philosophy")
gemini.switch_conversation("Science")
science_response = gemini.ask("Explain quantum entanglement")
gemini.switch_conversation("Philosophy")
philosophy_response = gemini.ask("Discuss the trolley problem")
response = gemini.ask("Show me a diagram of a black hole")
if response['images']:
for img_url in response['images']:
# Process or display the image
print(f"Image URL: {img_url}")
Our robust error handling system ensures smooth operation:
- 🔒 Authentication Issues
- 🌐 Network Connectivity Problems
- ⏱️ Timeout Management
- 🧩 Response Parsing Errors
Implement try-except blocks for graceful error management in your applications.
Tailor the Gemini API to your needs:
- ⚙️ Adjust timeout settings
- 🔀 Implement custom conversation management
- 🎨 Extend functionality with additional methods
Tips for optimal performance:
- 🚀 Use async operations for concurrent requests
- 💾 Implement caching for frequent queries
- 🔍 Optimize conversation context management
We welcome contributions! Here's how you can help:
- 🍴 Fork the repository
- 🌿 Create a feature branch (
git checkout -b feature/AmazingFeature
) - 🖊️ Commit your changes (
git commit -m 'Add some AmazingFeature'
) - 🚀 Push to the branch (
git push origin feature/AmazingFeature
) - 🎉 Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.