Skip to main content

Module for using AI

Project description

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:
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

mnnlibr-3.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

mnnlibr-3.0.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file mnnlibr-3.0.0.tar.gz.

File metadata

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

File hashes

Hashes for mnnlibr-3.0.0.tar.gz
Algorithm Hash digest
SHA256 b709d6c0abb45ef96b4f1e973125585d18d5d191065a40224f66967258951e92
MD5 6561211f8064cfba481e9b60c38726d7
BLAKE2b-256 a32bbaefab7c90fcb1ab80ddd846b220a489fc4ec2bf950e758a6e9cffdbfb53

See more details on using hashes here.

File details

Details for the file mnnlibr-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: mnnlibr-3.0.0-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 mnnlibr-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 318471486a57988bfeba45884b19d2328a0c4fe599d5205556e7df7b990657d1
MD5 181b1a6a26ba1c43094836c688a9641c
BLAKE2b-256 6a42f68705828e1355df3813baff4dc557c64503f53723e9b55de25e8f874634

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