Skip to main content

Module for using MNN API

Project description

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

Usage

Image Generation

from mnnai import MNN
import base64
import os


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='dall-e-3'
)

image_base64 = response['data'][0]['urls']

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!")

Non-Streaming Chat

chat_completion = client.chat_create(
    messages=[
        {
            "role": "user",
            "content": "Hi",
        }
    ],
    model="gpt-4o-mini",
)
print(chat_completion)

Streaming Chat (Beta)

import asyncio

stream = client.async_chat_create(
    model="gpt-4o-mini",
    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())

Models

Currently MNN supports:

**Text**:

*GPT 4o* : gpt-4o

*GPT 4o Mini* : gpt-4o-mini

*GPT 4* : gpt-4

*GPT 3.5 Turbo* : gpt-3.5-turbo

*GPT 3.5 Turbo (16k)* : gpt-3.5-turbo-16k

*Llama 3.1 (70b)* : llama-3.1-70b

*Claude 3 (sonnet)* : claude-3-5-sonnet

*Claude 3 (haiku)* : claude-3-haiku

*Gemini flash* : gemini-flash

**Image**:

*Stable diffusion (3)* : sd-3

*Flux (schnell)* : flux-schnell

*Dall-e (3)* : dall-e-3

**Are being tested**:

gemma-2b-it

Mixtral-8x7B-Instruct-v0.1

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-4.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

mnnai-4.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mnnai-4.0.1.tar.gz
Algorithm Hash digest
SHA256 c0b6464291d76ede01f65227955817227c711477f67ea9d40dea39751243573a
MD5 eb36601ae5e0309a5bf48a1e8f194dfe
BLAKE2b-256 8f4441222ec1a84dca7ebbdd5f19f74888ac23035523b31a543a2a6c9d625c5e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mnnai-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2268986fc7174b133d11edc952aa8e379cf4f0be6f7eb1b210416dee549ad06
MD5 da9baf7f0d535ffcbd0ac90957b2a5c6
BLAKE2b-256 fbf1daad10a23ef01252f515fefde628869bd084e49b5ef7a11c22184b1ec848

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