Skip to main content

Multimodal Large Language Models

Project description


MLLM

Multimodal Large Language Models
Explore the docs »

View Demo · Report Bug · Request Feature


Installation

pip install mllm

Extra dependencies

Some features might require extra dependencies.

For example, for the Gemini models, you can install the extra dependencies like this:

pip install mllm[gemini]

Usage

Create an MLLM router with a list of preferred models

import os
from mllm import Router

os.environ["OPENAI_API_KEY"] = "..."
os.environ["ANTHROPIC_API_KEY"] = "..."
os.environ["GEMINI_API_KEY"] = "..."

router = Router(
    preference=["gpt-4-turbo", "anthropic/claude-3-opus-20240229", "gemini/gemini-1.5-pro-latest"]
)

Create a new role based chat thread

from mllm import RoleThread

thread = RoleThread(owner_id="dolores@agentsea.ai")
thread.post(role="user", msg="Describe the image", images=["data:image/jpeg;base64,..."])

Chat with the MLLM, store the prompt data in the namespace foo

response = router.chat(thread, namespace="foo")
thread.add_msg(response.msg)

Ask for a structured response

from pydantic import BaseModel

class Animal(BaseModel):
    species: str
    color: str

thread.post(
    role="user",
    msg=f"What animal is in this image? Please output as schema {Animal.model_json_schema()}",
    images=["data:image/jpeg;base64,..."]
)

response = router.chat(thread, namespace="animal", expect=Animal)
animal_parsed = response.parsed

assert type(animal_parsed) == Animal

Find a saved thread or a prompt

RoleThread.find(id="123")
Prompt.find(id="456)

To store a raw openai prompt

from mllm import Prompt, RoleThread, RoleMessage

thread = RoleThread()

msg = {
    "role": "user",
    "content": [
        {
            "type": "text",
            "text": "Whats in this image?",
        },
        {
            "type": "image_url",
            "image_url": {"url": f"data:image/jpeg;base64,..."},
        }
    ]
}
role_message = RoleMessage.from_openai(msg)
thread.add_msg(role_message)

response = call_openai(thread.to_openai())
response_msg = RoleMessage.from_openai(response["choices"][0]["message"])

saved_prompt = Prompt(thread, response_msg, namespace="foo")

Add images of any variety to the thread. We support base64, filepath, PIL, and URL

from PIL import Image

img1 = Image.open("img1.png")

thread.post(
  role="user",
  msg="Whats this image?",
  images=["data:image/jpeg;base64,...", "./img1.png", img1, "https://shorturl.at/rVyAS"]
)

Integrations

MLLM is integrated with:

  • Taskara A task management library for AI agents
  • Skillpacks A library to fine tune AI agents on tasks.
  • Surfkit A platform for AI agents
  • Threadmem A thread management library for AI agents

Community

Come join us on Discord.

Backends

Thread and prompt storage can be backed by:

  • Sqlite
  • Postgresql

Sqlite will be used by default. To use postgres simply configure the env vars:

DB_TYPE=postgres
DB_NAME=mllm
DB_HOST=localhost
DB_USER=postgres
DB_PASS=abc123

Thread image storage by default will utilize the db, to configure bucket storage using GCS:

  • Create a bucket with fine grained permissions
  • Create a GCP service account JSON with permissions to write to the bucket
export THREAD_STORAGE_SA_JSON='{
  "type": "service_account",
  ...
}'
export THREAD_STORAGE_BUCKET=my-bucket

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

mllm-0.1.45.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

mllm-0.1.45-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file mllm-0.1.45.tar.gz.

File metadata

  • Download URL: mllm-0.1.45.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/23.4.0

File hashes

Hashes for mllm-0.1.45.tar.gz
Algorithm Hash digest
SHA256 10bf121212aaf14f18f60f66461f9a71ba4bb88f2bbaa49448a710b96045a088
MD5 4d5520ba0e8d4e7cedae58b16dcf5582
BLAKE2b-256 c5321c6d4471a2406f0565adf1f2783158b45c66be079b64aabe89504cbb9445

See more details on using hashes here.

File details

Details for the file mllm-0.1.45-py3-none-any.whl.

File metadata

  • Download URL: mllm-0.1.45-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/23.4.0

File hashes

Hashes for mllm-0.1.45-py3-none-any.whl
Algorithm Hash digest
SHA256 1887e80254adb0898d5a3d5b10fc2a4a89ddc07895d1da427ecd7533f7c82459
MD5 58c89ddf096c7fd7106fe82b49e4e49d
BLAKE2b-256 2dc79a97c4fb7a1f27865ec99eb009efc7b7ab721a2396fecda6ca2c0385c52e

See more details on using hashes here.

Supported by

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