# Simple Wrapper For The Gemini AI API
This module is designed for asynchronous usage and provides a simple interface to the Google Gemini API.
It also provides a command-line interface for interactive usage.
## **NOTICE**
Images are not tested and may not work as expected.
## Installation
```bash
pip install -U gemnine
```
## Usage
### Command Line
#### Configuration
`gemnine` requires a model and an API key to be set.
You can use config file, command parameters or interactive input to set these values.
By default, `gemnine` will look for files named `config.json` and `session.json` in the user config and cache directory.
```bash
gemnine -c /path/to/config.json # Use a config file
gemnine -m "models/gemini-pro" # Set model, input API key interactively
gemnine -l # list available models
```
#### Parameters
- `-c`, `--config`: Path to a JSON file
- `-m`, `--model`: Model name
- `-s`, `--session`: Session history file
- `-V`, `--version`: Show version
**_Precedence_**: Interactive input > Command parameters > Config file
#### Interactive Mode
This mode mimics a chat interface. You can type your message and get a response.
Commands are started with a `/` and are **case-sensitive**.
- `/exit`: Exit the program
- `/save <path>`: Save the session history to a file
- `/load`: Load a session history from a file
- `/rollback <step>`: Rollback to the previous state
- `/clear`: Clear the session history
- `/role`: Switch role
- `/model`: Switch model
- `/help`: Show help
To embed an image, insert `#image(<url>)` in your message.
Use double `#` to escape embedding.
```Python
await bot.send("""
What are these?
#image(https://example.com/image.png)
#image(file:///path/to/image.png)
#image(base64://<base64-encoded-image>)
""")
```
All URLs will be downloaded and embedded as base64-encoded images.
### API
```python
import asyncio
import gemnine
bot = gemnine.Bot(model="models/gemini-pro", api_key="your-api-key")
async def main():
response = await bot.send("Hello, how are you?")
print(response)
async for r in bot.stream("I'm fine, thank you."):
print(r, end='')
# `Bot` instance it self doesn't track the session history
# To keep track of the session history, use `Session` instance
sess = bot.new_session()
print(await sess.send("Hello, how are you?"))
async for r in sess.stream("What was my last question?"):
print(r, end='')
asyncio.run(main())
```
#### Save and load session history
`Session` and `Bot` use `pydantic` models under the hood. You can save and load the session history using `model_dump_json` and `model_validate_json` or pass arguments to `new_session` methods.
```python
import json
from pathlib import Path
sess_path = Path("session.json")
sess = bot.new_session()
data = sess.model_dump_json()
sess_path.write_text(data)
sess = bot.new_session(**json.loads(sess_path.read_text()))
```
Raw data
{
"_id": null,
"home_page": "https://github.com/VermiIIi0n/Gemnine",
"name": "gemnine",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.12,<4.0",
"maintainer_email": "",
"keywords": "utilities,gemini,async,api",
"author": "VermiIIi0n",
"author_email": "dungeon.behind0t@icloud.com",
"download_url": "https://files.pythonhosted.org/packages/2b/ba/409495d0f0ff0928b80bb2d87532fab58e06e7409686959786996c89d84c/gemnine-0.1.10.tar.gz",
"platform": null,
"description": "# Simple Wrapper For The Gemini AI API\n\nThis module is designed for asynchronous usage and provides a simple interface to the Google Gemini API.\n\nIt also provides a command-line interface for interactive usage.\n\n## **NOTICE**\n\nImages are not tested and may not work as expected.\n\n## Installation\n\n```bash\npip install -U gemnine\n```\n\n## Usage\n\n### Command Line\n\n#### Configuration\n\n`gemnine` requires a model and an API key to be set.\n\nYou can use config file, command parameters or interactive input to set these values.\n\nBy default, `gemnine` will look for files named `config.json` and `session.json` in the user config and cache directory.\n\n```bash\ngemnine -c /path/to/config.json # Use a config file\ngemnine -m \"models/gemini-pro\" # Set model, input API key interactively\ngemnine -l # list available models\n```\n\n#### Parameters\n\n- `-c`, `--config`: Path to a JSON file\n- `-m`, `--model`: Model name\n- `-s`, `--session`: Session history file\n- `-V`, `--version`: Show version\n\n**_Precedence_**: Interactive input > Command parameters > Config file\n\n#### Interactive Mode\n\nThis mode mimics a chat interface. You can type your message and get a response.\n\nCommands are started with a `/` and are **case-sensitive**.\n\n- `/exit`: Exit the program\n- `/save <path>`: Save the session history to a file\n- `/load`: Load a session history from a file\n- `/rollback <step>`: Rollback to the previous state\n- `/clear`: Clear the session history\n- `/role`: Switch role\n- `/model`: Switch model\n- `/help`: Show help\n\nTo embed an image, insert `#image(<url>)` in your message.\nUse double `#` to escape embedding.\n\n```Python\nawait bot.send(\"\"\"\nWhat are these?\n#image(https://example.com/image.png)\n#image(file:///path/to/image.png)\n#image(base64://<base64-encoded-image>)\n\"\"\")\n```\n\nAll URLs will be downloaded and embedded as base64-encoded images.\n\n### API\n\n```python\nimport asyncio\nimport gemnine\n\nbot = gemnine.Bot(model=\"models/gemini-pro\", api_key=\"your-api-key\")\n\nasync def main():\n response = await bot.send(\"Hello, how are you?\")\n print(response)\n\n async for r in bot.stream(\"I'm fine, thank you.\"):\n print(r, end='')\n \n # `Bot` instance it self doesn't track the session history\n # To keep track of the session history, use `Session` instance\n sess = bot.new_session()\n\n print(await sess.send(\"Hello, how are you?\"))\n\n async for r in sess.stream(\"What was my last question?\"):\n print(r, end='')\n\nasyncio.run(main())\n```\n\n#### Save and load session history\n\n`Session` and `Bot` use `pydantic` models under the hood. You can save and load the session history using `model_dump_json` and `model_validate_json` or pass arguments to `new_session` methods.\n\n```python\nimport json\nfrom pathlib import Path\nsess_path = Path(\"session.json\")\n\nsess = bot.new_session()\n\ndata = sess.model_dump_json()\n\nsess_path.write_text(data)\n\nsess = bot.new_session(**json.loads(sess_path.read_text()))\n\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Wrapper for Gemini AI API",
"version": "0.1.10",
"project_urls": {
"Homepage": "https://github.com/VermiIIi0n/Gemnine",
"Issues": "https://github.com/VermiIIi0n/Gemnine/issues"
},
"split_keywords": [
"utilities",
"gemini",
"async",
"api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f9c7048fd569781c33f9286101586faae82fdcd3aabc346b387bfb9d0379900d",
"md5": "a50476dce4f22e2385db5a40b31fef97",
"sha256": "70133274e4b7a4842e3212daa20c9aa4a109388aca0d328bd593f5d026ff2d67"
},
"downloads": -1,
"filename": "gemnine-0.1.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a50476dce4f22e2385db5a40b31fef97",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12,<4.0",
"size": 10950,
"upload_time": "2024-03-06T14:12:12",
"upload_time_iso_8601": "2024-03-06T14:12:12.845256Z",
"url": "https://files.pythonhosted.org/packages/f9/c7/048fd569781c33f9286101586faae82fdcd3aabc346b387bfb9d0379900d/gemnine-0.1.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2bba409495d0f0ff0928b80bb2d87532fab58e06e7409686959786996c89d84c",
"md5": "67d773e9bdb67706f0f5e7218797d178",
"sha256": "0a0325dcdcc0f0377c80997c5e218548420b231f7ec15b40bac02bb42e154df0"
},
"downloads": -1,
"filename": "gemnine-0.1.10.tar.gz",
"has_sig": false,
"md5_digest": "67d773e9bdb67706f0f5e7218797d178",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12,<4.0",
"size": 11846,
"upload_time": "2024-03-06T14:12:14",
"upload_time_iso_8601": "2024-03-06T14:12:14.883460Z",
"url": "https://files.pythonhosted.org/packages/2b/ba/409495d0f0ff0928b80bb2d87532fab58e06e7409686959786996c89d84c/gemnine-0.1.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-06 14:12:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "VermiIIi0n",
"github_project": "Gemnine",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "gemnine"
}