mnnai


Namemnnai JSON
Version 5.1.0 PyPI version JSON
download
home_pagehttps://github.com/mkshustov/MNNAI
SummaryModule for using MNN API
upload_time2025-02-18 17:30:38
maintainerNone
docs_urlNone
authormkshustov
requires_python>=3.7
licenseNone
keywords ai mnn chatgpt mnnai mnn
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MNNAI

This repository contains an example of how to use the mnnai library.

## Prerequisites

- Python 3.x
- MNNAI library installed. You can install it using pip:

```bash
pip install mnnai
```

## Usage

**Non-Streaming Chat**

```python
from mnnai import MNN

client = MNN(
    key='MNN API KEY' # This is the default and can be omitted
)

chat_completion = client.chat.create(
    messages=[
        {
            "role": "user",
            "content": "What's the weather like in New York?",
        }
    ],
    model="gpt-4o-mini",
    web_search=True # Internet search
)
print(chat_completion.choices[0].message.content)
```

**Streaming Chat**

```python
stream = client.chat.create(
    messages=[
        {
            "role": "user",
            "content": "Will the neural networks capture the world?",
        }
    ],
    model="gpt-4o-mini",
    stream=True
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
```

**Image Generation**

```python
import base64
import os

response = client.images.create(
    prompt="Draw a cute red panda",
    model='dall-e-3'
)

image_base64 = response.data[0].url

os.makedirs('images', exist_ok=True)

for i, image_base64 in enumerate(image_base64):
    image_data = base64.b64decode(image_base64)

    with open(f'images/image_{i}.png', 'wb') as f:
        f.write(image_data)

print("Images have been successfully downloaded!")
```

## Async usage

**Non-Streaming Chat**

```python
import asyncio

async def main():
    chat_completion = await client.chat.async_create(
        messages=[
            {
                "role": "user",
                "content": "Say this is a test",
            }
        ],
        model="gpt-4o-mini",
    )
    print(chat_completion.choices[0].message.content)


asyncio.run(main())
```

**Streaming Chat**

```python
import asyncio

async def main():
    stream = await client.chat.async_create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Say this is a test"}],
        stream=True,
    )
    async for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="")


asyncio.run(main())
```

**Image Generation**

```python
import asyncio
import base64
import os

async def main():
    response = await client.images.async_create(
        prompt="Draw a cute red panda",
        model='dall-e-3'
    )

    image_base64 = response.data[0].url

    os.makedirs('images', exist_ok=True)

    for i, image_base64 in enumerate(image_base64):
        image_data = base64.b64decode(image_base64)

        with open(f'images/image_{i}.png', 'wb') as f:
            f.write(image_data)

    print("Images have been successfully downloaded!")


asyncio.run(main())
```

## Auxiliary functions 

**Get models**

```python
print(client.GetModels())
```

**Configuring the client**

```python
from mnnai import MNN

client = MNN(
    key='MNN API KEY',
    max_retries=2, # Number of retries in case of failure
    timeout=60, # Maximum amount of time the request will be processed
    debug=True # Whether the application needs to be debugged
)
```

## 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/MNNAI",
    "name": "mnnai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "ai MNN chatgpt mnnai mnn",
    "author": "mkshustov",
    "author_email": "reverse.api.mnn@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/14/21/8d372ef49c6d4047969f5a4700c34b82551c3780be78f9756c0499f02a1e/mnnai-5.1.0.tar.gz",
    "platform": null,
    "description": "# MNNAI\n\nThis repository contains an example of how to use the mnnai library.\n\n## Prerequisites\n\n- Python 3.x\n- MNNAI library installed. You can install it using pip:\n\n```bash\npip install mnnai\n```\n\n## Usage\n\n**Non-Streaming Chat**\n\n```python\nfrom mnnai import MNN\n\nclient = MNN(\n    key='MNN API KEY' # This is the default and can be omitted\n)\n\nchat_completion = client.chat.create(\n    messages=[\n        {\n            \"role\": \"user\",\n            \"content\": \"What's the weather like in New York?\",\n        }\n    ],\n    model=\"gpt-4o-mini\",\n    web_search=True # Internet search\n)\nprint(chat_completion.choices[0].message.content)\n```\n\n**Streaming Chat**\n\n```python\nstream = client.chat.create(\n    messages=[\n        {\n            \"role\": \"user\",\n            \"content\": \"Will the neural networks capture the world?\",\n        }\n    ],\n    model=\"gpt-4o-mini\",\n    stream=True\n)\n\nfor chunk in stream:\n    print(chunk.choices[0].delta.content or \"\", end=\"\")\n```\n\n**Image Generation**\n\n```python\nimport base64\nimport os\n\nresponse = client.images.create(\n    prompt=\"Draw a cute red panda\",\n    model='dall-e-3'\n)\n\nimage_base64 = response.data[0].url\n\nos.makedirs('images', exist_ok=True)\n\nfor i, image_base64 in enumerate(image_base64):\n    image_data = base64.b64decode(image_base64)\n\n    with open(f'images/image_{i}.png', 'wb') as f:\n        f.write(image_data)\n\nprint(\"Images have been successfully downloaded!\")\n```\n\n## Async usage\n\n**Non-Streaming Chat**\n\n```python\nimport asyncio\n\nasync def main():\n    chat_completion = await client.chat.async_create(\n        messages=[\n            {\n                \"role\": \"user\",\n                \"content\": \"Say this is a test\",\n            }\n        ],\n        model=\"gpt-4o-mini\",\n    )\n    print(chat_completion.choices[0].message.content)\n\n\nasyncio.run(main())\n```\n\n**Streaming Chat**\n\n```python\nimport asyncio\n\nasync def main():\n    stream = await client.chat.async_create(\n        model=\"gpt-4o-mini\",\n        messages=[{\"role\": \"user\", \"content\": \"Say this is a test\"}],\n        stream=True,\n    )\n    async for chunk in stream:\n        print(chunk.choices[0].delta.content or \"\", end=\"\")\n\n\nasyncio.run(main())\n```\n\n**Image Generation**\n\n```python\nimport asyncio\nimport base64\nimport os\n\nasync def main():\n    response = await client.images.async_create(\n        prompt=\"Draw a cute red panda\",\n        model='dall-e-3'\n    )\n\n    image_base64 = response.data[0].url\n\n    os.makedirs('images', exist_ok=True)\n\n    for i, image_base64 in enumerate(image_base64):\n        image_data = base64.b64decode(image_base64)\n\n        with open(f'images/image_{i}.png', 'wb') as f:\n            f.write(image_data)\n\n    print(\"Images have been successfully downloaded!\")\n\n\nasyncio.run(main())\n```\n\n## Auxiliary functions \n\n**Get models**\n\n```python\nprint(client.GetModels())\n```\n\n**Configuring the client**\n\n```python\nfrom mnnai import MNN\n\nclient = MNN(\n    key='MNN API KEY',\n    max_retries=2, # Number of retries in case of failure\n    timeout=60, # Maximum amount of time the request will be processed\n    debug=True # Whether the application needs to be debugged\n)\n```\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",
    "bugtrack_url": null,
    "license": null,
    "summary": "Module for using MNN API",
    "version": "5.1.0",
    "project_urls": {
        "Documentation": "https://github.com/mkshustov/MNNAI",
        "Homepage": "https://github.com/mkshustov/MNNAI",
        "Site": "http://mnnai.ru"
    },
    "split_keywords": [
        "ai",
        "mnn",
        "chatgpt",
        "mnnai",
        "mnn"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "64136d33d086c4a7d9d826b963fef323c6981c7d2822467f4ef90875cfabd79c",
                "md5": "f044d9c8803073398769c1f2989a51bc",
                "sha256": "cac433b7f3fa637e980e64150588e3b4aeec02a6df61eb3f605153bc8cae4c7b"
            },
            "downloads": -1,
            "filename": "mnnai-5.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f044d9c8803073398769c1f2989a51bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6538,
            "upload_time": "2025-02-18T17:30:34",
            "upload_time_iso_8601": "2025-02-18T17:30:34.821587Z",
            "url": "https://files.pythonhosted.org/packages/64/13/6d33d086c4a7d9d826b963fef323c6981c7d2822467f4ef90875cfabd79c/mnnai-5.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14218d372ef49c6d4047969f5a4700c34b82551c3780be78f9756c0499f02a1e",
                "md5": "8378ba11e962c99831e86ef55ebba6fe",
                "sha256": "c11b3e01f68b7726397a4cb74f4f7f4e288483a5ac09e238fcb6f3b40222786a"
            },
            "downloads": -1,
            "filename": "mnnai-5.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8378ba11e962c99831e86ef55ebba6fe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5786,
            "upload_time": "2025-02-18T17:30:38",
            "upload_time_iso_8601": "2025-02-18T17:30:38.048844Z",
            "url": "https://files.pythonhosted.org/packages/14/21/8d372ef49c6d4047969f5a4700c34b82551c3780be78f9756c0499f02a1e/mnnai-5.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-18 17:30:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mkshustov",
    "github_project": "MNNAI",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mnnai"
}
        
Elapsed time: 0.41886s