Skip to main content

Input and output processing for IBM Granite models

Project description

Granite IO Processing

Introduction

Granite IO Processing is a framework which enables you to transform how a user calls or infers an IBM Granite model and how the output from the model is returned to the user. In other words, the framework allows you to extend the functionality of calling the model.

Getting Started

Requirements

  • Python 3.10+

Installation

We recommend using a Python virtual environment with Python 3.10+. Here is how to setup a virtual environment using Python venv:

python3 -m venv granite_io_venv
source granite_io_venv/bin/activate

[!TIP] If you use pyenv, Conda Miniforge or other such tools for Python version management, create the virtual environment with that tool instead of venv. Otherwise, you may have issues with installed packages not being found as they are linked to your Python version management tool and not venv.

There are 2 ways to install the Granite IO Processor as follows:

From Release

To install from release (PyPi package):

python3 -m venv granite_io_venv
source granite_io_venv/bin/activate
pip install granite-io

From Source

To install from source(GitHub Repository):

python3 -m venv granite_io_venv
source granite_io_venv/bin/activate
git clone https://github.com/ibm-granite/granite-io
cd granite-io
pip install -e .

Framework Example

Sample code snippet showing how to use the framework:

from granite_io import make_backend, make_io_processor
from granite_io.types import ChatCompletionInputs, UserMessage

model_name = "granite3.2:8b"
io_processor = make_io_processor(
    model_name, backend=make_backend("openai", {"model_name": model_name})
)
messages=[
    UserMessage(
        content="What's the fastest way for a seller to visit all the cities in their region?",
    )
]

# Without Thinking
outputs = io_processor.create_chat_completion(ChatCompletionInputs(messages=messages))
print("------ WITHOUT THINKING ------")
print(outputs.results[0].next_message.content)

# With Thinking
outputs = io_processor.create_chat_completion(
    ChatCompletionInputs(messages=messages, thinking=True)
)
print("------ WITH THINKING ------")
print(">> Thoughts:")
print(outputs.results[0].next_message.reasoning_content)
print(">> Response:")
print(outputs.results[0].next_message.content)

[!IMPORTANT] To get started with the examples, make sure you have followed the Installation steps first. You will need additional packages to be able to run the OpenAI example. They can be installed by running pip install -e "granite-io[openai]". Replace package name granite-io with . if installing from source.

To be able to run the above code snippet, you will need an Ollama server running locally and IBM Granite 3.2 model cached (ollama pull granite3.2:8b).

Try It Out!

To help you get up and running as quickly as possible with the Granite IO Processing framework, check out the following resources which demonstrate further how to use the framework:

  1. Python script examples:

[!IMPORTANT] To get started with the examples, make sure you have followed the Installation steps first. You will need additional packages to be able to run the examples. They can be installed by running pip install -e "granite-io[openai]" and pip install -e "granite-io[litellm]. Replace package name granite-io with . if installing from source.

You will also need an Ollama server running locally and IBM Granite 3.2 model cached (ollama pull granite3.2:8b).

  1. Jupyter notebook tutorials:

[!IMPORTANT] To get started with the examples, make sure you have followed the Installation steps first. You will also need additional packages to be able to run the Jupyter notebook. They can be installed by running pip install -e "granite-io[transformers]" and pip install -e "granite-io[notebook]". Replace package name granite-io with . if installing from source. The notebooks can be then run with following command jupyter notebook <path_to_notebook>.

Architecture

For more information about architecture and design decisions, refer to docs/design.md.

Contributing

Check out our contributing guide to learn how to contribute.

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

granite_io-0.4.1.tar.gz (987.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

granite_io-0.4.1-py3-none-any.whl (101.7 kB view details)

Uploaded Python 3

File details

Details for the file granite_io-0.4.1.tar.gz.

File metadata

  • Download URL: granite_io-0.4.1.tar.gz
  • Upload date:
  • Size: 987.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for granite_io-0.4.1.tar.gz
Algorithm Hash digest
SHA256 bfa8bf951c1e16b67cd65617720fde01c928f532efb249e1d89c60f6b59e1b0e
MD5 15cc31ff15d3cdf97307d3a12e7b5029
BLAKE2b-256 586ffb844ba2cca2f7569dafe42c19105e55252ea1dabf2bd06ee09805c291fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for granite_io-0.4.1.tar.gz:

Publisher: pypi.yml on ibm-granite/granite-io

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file granite_io-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: granite_io-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 101.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for granite_io-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6aa8b29a742135affdd098fe258fc630cebbbf023f5a79f6e4c0dd01899c8ab2
MD5 e9335b19feff4ac937047c9c4b3bda4a
BLAKE2b-256 9a639b2ce5cdf668f63798a409c4098864304dd18458e0c4a65562e37ee2cd9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for granite_io-0.4.1-py3-none-any.whl:

Publisher: pypi.yml on ibm-granite/granite-io

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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