Skip to main content

Zrb LLM plugin

Project description

Zrb Ollama

Zrb Ollama is a Pypi package that acts as LiteLLM's wrapper, allowing you to incorporate LLM into your workflow.

Zrb Ollama is a part of the Zrb ecosystem, but you can install it independently from Zrb.

Installation

You can install Zrb Ollama by invoking any of the following commands:

# From pypi
pip install zrb-ollama[chromadb,aws]

# From github
pip install git+https://github.com/state-alchemists/zrb-ollama.git@main

# From directory
pip install --use-feature=in-tree-build path/to/this/directory

By default, Zrb Ollama uses Ollama-based LLM. You can install Ollama by visiting the official website: https://ollama.ai/.

The default LLM is ollama/mistral:7b-instruct, while the default embedding LLM is ollama/nomic-embed-text.

You can change this by setting the model parameter on LLMTask or the create_rag function. See LiteLLM provider to use custom LLM.

CLI Command

Zrb Ollama provides a simple CLI command so you can interact with the LLM immediately. The LLM has two tools:

  • query_internet
  • run_shell_command

To interact with the LLM, you can invoke the following command.

zrb-ollama

Using LLMTask

Zrb Ollama provides a task named LLMTask, allowing you to create a Zrb Task with a custom model or tools.

from zrb import runner, StrInput
from zrb_ollama import LLMTask
from zrb_ollama.tools import query_internet, create_rag

import os

_CURRENT_DIR = os.path.dirname(__file__)
with open(os.path.join(_CURRENT_DIR, "john-titor.md")) as f:
    john_titor_article = f.read()

ask = LLMTask(
    name="ask",
    inputs=[
        StrInput(name="user-prompt", default="How John Titor introduce himself?"),
    ],
    model="gpt-4o",
    user_message="{{input.user_prompt}}",
    tools=[
        create_rag(
            tool_name="retrieve",
            tool_description="Look for anything related to John Titor"
            documents=[john_titor_article],
            model="text-embedding-ada-002",
        ),
        query_internet,
    ]
)
runner.register(ask)

Assuming there is a file named john-titor.md, you can invoke the Task by invoking the following command.

zrb ask

The LLM can browse the article or look for anything on the internet.

Using Agent

Under the hood, LLMTask makes use of Agent. You can create and interact with the agent programmatically as follows.

from zrb_ollama import agent
from zrb_ollama.tools import create_rag, query_internet

import asyncio
import os

_CURRENT_DIR = os.path.dirname(__file__)
with open(os.path.join(_CURRENT_DIR, "john-titor.md")) as f:
    john_titor_article = f.read()


agent = Agent(
    model="gpt-4o",
    tools=[
        create_rag(
            tool_name="retrieve",
            tool_description="Look for anything related to John Titor"
            documents=[john_titor_article],
            model="text-embedding-ada-002",
        ),
        query_internet,
    ]
)
result = asyncio.run(agent.add_user_message("How John Titor introduce himself?"))
print(result)

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

zrb_ollama-0.2.2.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

zrb_ollama-0.2.2-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file zrb_ollama-0.2.2.tar.gz.

File metadata

  • Download URL: zrb_ollama-0.2.2.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.0 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for zrb_ollama-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5b80b5fd8a2e82306d2457711d57ebbdb44ac9f990d5d106c8e21d7c5a678af6
MD5 f8000496c6201cb7bcd5a59c37cd8174
BLAKE2b-256 4b24479b0f8d36bb16c3921e693d5fe7e0cfcde991d7a758109c13120ce6d72c

See more details on using hashes here.

File details

Details for the file zrb_ollama-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: zrb_ollama-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.0 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for zrb_ollama-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 27093a25f9c1d1fb5fdcb27f9656042b191d094f18e260826d57ffa28b560c75
MD5 04e0b1a1424b3fdc410b7852be1cc9b5
BLAKE2b-256 2b3a47090a44d406fa65383fef6da419dd44ecfe13840f4a599964f863631008

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