# 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": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": "utilities, gemini, async, api",
"author": "VermiIIi0n",
"author_email": "dungeon.behind0t@icloud.com",
"download_url": "https://files.pythonhosted.org/packages/a2/77/259e5185b075aece75c267f4597c99786f12b391d2b4a40a50ff7a8f4a63/gemnine-0.1.12.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.12",
"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": "e3f633c5d921b6d301b4f581ca55f1ddce8774d9e63a641645396f50c1f7569c",
"md5": "cff64eeb72bde256f2bafa6be70f57f2",
"sha256": "eeda33b2950051c99e9a6f3b384f50079d755732abc3cfa8a87b9dd8570127fd"
},
"downloads": -1,
"filename": "gemnine-0.1.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cff64eeb72bde256f2bafa6be70f57f2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 11794,
"upload_time": "2024-07-03T11:11:19",
"upload_time_iso_8601": "2024-07-03T11:11:19.225809Z",
"url": "https://files.pythonhosted.org/packages/e3/f6/33c5d921b6d301b4f581ca55f1ddce8774d9e63a641645396f50c1f7569c/gemnine-0.1.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a277259e5185b075aece75c267f4597c99786f12b391d2b4a40a50ff7a8f4a63",
"md5": "83e4aa181877b4fcf2bed81513460d07",
"sha256": "350b0d7210d0495457560caa81540b4dc295bf5e018bbd5258096151916858fa"
},
"downloads": -1,
"filename": "gemnine-0.1.12.tar.gz",
"has_sig": false,
"md5_digest": "83e4aa181877b4fcf2bed81513460d07",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 12503,
"upload_time": "2024-07-03T11:11:21",
"upload_time_iso_8601": "2024-07-03T11:11:21.169282Z",
"url": "https://files.pythonhosted.org/packages/a2/77/259e5185b075aece75c267f4597c99786f12b391d2b4a40a50ff7a8f4a63/gemnine-0.1.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-03 11:11:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "VermiIIi0n",
"github_project": "Gemnine",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "gemnine"
}