# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

PortGroup           github 1.0
PortGroup           python 1.0

github.setup        containers ramalama 0.23.0 v
github.tarball_from archive
revision            0
checksums           rmd160  837588a776601f1b41634453d5dfa62ac835d7b4 \
                    sha256  715d8496697d56f4cef061b0ed11de8978bba0f649eba5e38181faf7a3ed1568 \
                    size    1464108

homepage            https://ramalama.ai/
license             MIT
description         A tool to simplify the use of local AI models
long_description    \
    Ramalama is an open-source developer tool that simplifies the local serving \
    of AI models from any source and facilitates their use for inference in \
    production, all through the familiar language of containers.

maintainers         {cal @neverpanic} openmaintainer
categories          llm science
supported_archs     noarch

python.default_version  313

depends_run-append  \
                    port:krunkit \
                    port:podman \
                    port:py${python.version}-jinja2 \
                    port:py${python.version}-yaml

variant mlx description {Support Apple MLX for local model inference} {
    depends_run-append \
                    port:py${python.version}-mlx-lm

    post-patch {
        reinplace "s|\"mlx_lm.server\"|\"mlx_lm.server-${python.branch}\"|g" \
            ${worksrcpath}/ramalama/plugins/runtimes/inference/mlx.py
    }

    notes-append \
        "\n\nTo use MLX as the default inference runtime (Apple Silicon only),\
        set 'runtime = \"mlx\"' under the '\[ramalama]' section of\
        '\$HOME/.config/ramalama/ramalama.conf', or export the\
        RAMALAMA_RUNTIME=mlx environment variable, or pass --runtime=mlx on\
        the command line. If podman is installed, ${name} will default to\
        using it. To use MLX, either pass the --nocontainer flag to ${name}\
        or set 'container = false' under the '\[machine]' section of\
        '\$HOME/.config/ramalama/ramalama.conf'."
}

platform darwin arm {
    default_variants-append \
                    +mlx
}

notes \
    "${name} defaults to running AI models in podman containers in a podman\
    machine (i.e., VM) started by libkrun. This is not the podman default, so\
    you will have to change it, either by exporting the\
    CONTAINERS_MACHINE_PROVIDER=libkrun environment variable, or by adding\
    'provider = \"libkrun\"' to the '\[machine]' section of\
    '\$HOME/.config/containers/containers.conf'. See man 7 ramalama-macos for\
    more information."
