# MNN AI
!!! Currently the api can only be tested via @mnnaibot
This repository contains an example of how to use the library to interact with the MNN API for image generation and text chat functionalities.
## Prerequisites
- Python 3.x
- MNNLib library installed. You can install it using pip:
```bash
pip install mnnai
```
## Usage
Image Generation
The following code demonstrates how to generate an image based on a prompt using the MNN API.
```python
from mnnai import MNN
client = MNN(
key='MNN API KEY',
id='MNN ID',
# max_retries=2,
# timeout=60
)
response = client.Image_create(
prompt="Draw a cute red panda",
model='sdxl'
)
image_url = response['data'][0]['url']
print(image_url)
```
## Text Chat
The following code demonstrates how to create a chat session with the MNN API, both with streaming and without streaming.
**Streaming Chat**
```python
import asyncio
stream = client.async_chat_create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hi"}],
stream=True,
temperature=0.5
)
async def generate():
async for chunk in stream:
if 'result' in chunk:
print(chunk['result'], end='')
else:
print(f"\n{chunk}")
asyncio.run(generate())
```
**Non-Streaming Chat**
```python
chat_completion = client.chat_create(
messages=[
{
"role": "user",
"content": "Hi",
}
],
model="gpt-4o",
)
print(chat_completion)
```
### Configuration
Replace the key and id parameters in the MNN client initialization with your own API key and user ID.
Adjust the prompt, model, and other parameters as needed for your specific use case.
### License
This project is licensed under the MIT License. See the LICENSE file for details.
### Discord
https://discord.gg/Ku2haNjFvj
Raw data
{
"_id": null,
"home_page": "https://github.com/mkshustov/MNNLibr",
"name": "mnnlibr",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "ai MNN chatgpt",
"author": "mkshustov",
"author_email": "mkshustov@mail.ru",
"download_url": "https://files.pythonhosted.org/packages/a3/2b/baefab7c90fcb1ab80ddd846b220a489fc4ec2bf950e758a6e9cffdbfb53/mnnlibr-3.0.0.tar.gz",
"platform": null,
"description": "# MNN AI\n\n!!! Currently the api can only be tested via @mnnaibot\n\nThis repository contains an example of how to use the library to interact with the MNN API for image generation and text chat functionalities.\n\n## Prerequisites\n\n- Python 3.x\n- MNNLib library installed. You can install it using pip:\n\n```bash\npip install mnnai\n```\n\n## Usage\nImage Generation\nThe following code demonstrates how to generate an image based on a prompt using the MNN API.\n\n```python\nfrom mnnai import MNN\n\nclient = MNN(\n key='MNN API KEY',\n id='MNN ID',\n # max_retries=2, \n # timeout=60\n)\n\nresponse = client.Image_create(\n prompt=\"Draw a cute red panda\",\n model='sdxl'\n)\n\nimage_url = response['data'][0]['url']\nprint(image_url)\n```\n\n## Text Chat\nThe following code demonstrates how to create a chat session with the MNN API, both with streaming and without streaming.\n\n**Streaming Chat**\n```python\nimport asyncio\n\nstream = client.async_chat_create(\n model=\"gpt-4o\",\n messages=[{\"role\": \"user\", \"content\": \"Hi\"}],\n stream=True,\n temperature=0.5\n)\n\nasync def generate():\n async for chunk in stream:\n if 'result' in chunk:\n print(chunk['result'], end='')\n else:\n print(f\"\\n{chunk}\")\n\nasyncio.run(generate())\n```\n\n**Non-Streaming Chat**\n```python\nchat_completion = client.chat_create(\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Hi\",\n }\n ],\n model=\"gpt-4o\",\n)\nprint(chat_completion)\n```\n\n### Configuration\nReplace the key and id parameters in the MNN client initialization with your own API key and user ID.\nAdjust the prompt, model, and other parameters as needed for your specific use case.\n\n### License\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n### Discord \nhttps://discord.gg/Ku2haNjFvj\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Module for using AI",
"version": "3.0.0",
"project_urls": {
"Documentation": "https://github.com/mkshustov/MNNLibr",
"Homepage": "https://github.com/mkshustov/MNNLibr"
},
"split_keywords": [
"ai",
"mnn",
"chatgpt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6a42f68705828e1355df3813baff4dc557c64503f53723e9b55de25e8f874634",
"md5": "181b1a6a26ba1c43094836c688a9641c",
"sha256": "318471486a57988bfeba45884b19d2328a0c4fe599d5205556e7df7b990657d1"
},
"downloads": -1,
"filename": "mnnlibr-3.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "181b1a6a26ba1c43094836c688a9641c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 6037,
"upload_time": "2024-09-15T14:09:53",
"upload_time_iso_8601": "2024-09-15T14:09:53.648803Z",
"url": "https://files.pythonhosted.org/packages/6a/42/f68705828e1355df3813baff4dc557c64503f53723e9b55de25e8f874634/mnnlibr-3.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a32bbaefab7c90fcb1ab80ddd846b220a489fc4ec2bf950e758a6e9cffdbfb53",
"md5": "6561211f8064cfba481e9b60c38726d7",
"sha256": "b709d6c0abb45ef96b4f1e973125585d18d5d191065a40224f66967258951e92"
},
"downloads": -1,
"filename": "mnnlibr-3.0.0.tar.gz",
"has_sig": false,
"md5_digest": "6561211f8064cfba481e9b60c38726d7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5193,
"upload_time": "2024-09-15T14:09:55",
"upload_time_iso_8601": "2024-09-15T14:09:55.497367Z",
"url": "https://files.pythonhosted.org/packages/a3/2b/baefab7c90fcb1ab80ddd846b220a489fc4ec2bf950e758a6e9cffdbfb53/mnnlibr-3.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-15 14:09:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mkshustov",
"github_project": "MNNLibr",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "mnnlibr"
}