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

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)

Models

Currently MNN supports:

*GPT 4o* : gpt-4o

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

*GPT 4 Turbo* : gpt-4-turbo

*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 (haiku)* : claude-3-haiku

**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.0.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.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnnai-4.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4b74a597ed5eca75ac7246c2ebcd083e72a7a440af7355fef3e14648674ba7fc
MD5 35ca77d9bb0c47eada85a858f4ed6f25
BLAKE2b-256 6b011f747482bfdd269d9291c17787b39e32c86e602401c8fc6e1e4ae8a84a10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnnai-4.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 414a4af132e1c7b0e6152ec3171f794d9e94c10005e434f81f14610240927a54
MD5 22932b9188af4016e65d5308f5114ad0
BLAKE2b-256 4001ebbb0fe2d9d595ce6f3d33cb82a0eff99c579eacdc950e10a4c2af3584ea

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