Skip to main content

Module for using AI

Project description

MNN AI

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:
pip install mnnai

Usage

Image Generation The following code demonstrates how to generate an image based on a prompt using the MNN API.

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

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mnnai-0.0.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mnnai-0.0.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file mnnai-0.0.2.tar.gz.

File metadata

  • Download URL: mnnai-0.0.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for mnnai-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fdd6f3a5edabd276b6c2d4ed1bf8fa097c8e7cba193d76221be8b8f5830e0f75
MD5 ae4f85bd69267f26bde0416f89f6a232
BLAKE2b-256 c1a6df503888eccd0b4036bb0826a7f8a676cf9325d04474e41a8e47d3699564

See more details on using hashes here.

File details

Details for the file mnnai-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mnnai-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for mnnai-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7ee1dea55a482706103cc7155fcbdd2ca63e972a02c92936b71d36933dc8a991
MD5 9adb454990b3c34070f41828e4f13718
BLAKE2b-256 7078c7f8976485c1b7ece0be9ee738d811501589a6303513b60141eb975cc2b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page