Skip to main content

Module for using AI

Project description

MNNLibr

This repository contains an example of how to use the MNNLib 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 mnnlibr

Usage

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

from mnnlibr 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.1.tar.gz (4.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.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnnai-0.0.1.tar.gz
  • Upload date:
  • Size: 4.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.1.tar.gz
Algorithm Hash digest
SHA256 21a440f0a1edeb989e222bfaf48ec2b484774c7c40468222ee4d14cdd72684d7
MD5 6828bb1cd74036ec9ad6565f9a49fcb5
BLAKE2b-256 ab0d8e357bbb1db1b6e0173b5bd1838b35bc43aab48ccf9e61e7947c777d6d35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnnai-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22def019a6a78e54b5fb9ffce5c41e1b2bcf91506706b7eaecf9b7bef5cab68b
MD5 ac97c971517328977b599e791849679d
BLAKE2b-256 b229c4f8f93743771430cd8551886135331476c0880db63b3ab149ea9fd86637

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