Skip to main content

llama-index llms heroku managed inference integration

Project description

Heroku Managed Inference

The llama-index-llms-heroku package contains LlamaIndex integrations for building applications with models on Heroku's Managed Inference platform. This integration allows you to easily connect to and use AI models deployed on Heroku's infrastructure.

Installation

pip install llama-index-llms-heroku

Setup

1. Create a Heroku App

First, create an app in Heroku:

heroku create $APP_NAME

2. Create and Attach AI Models

Create and attach a chat model to your app:

heroku ai:models:create -a $APP_NAME claude-3-5-haiku

3. Export Configuration Variables

Export the required configuration variables:

export INFERENCE_KEY=$(heroku config:get INFERENCE_KEY -a $APP_NAME)
export INFERENCE_MODEL_ID=$(heroku config:get INFERENCE_MODEL_ID -a $APP_NAME)
export INFERENCE_URL=$(heroku config:get INFERENCE_URL -a $APP_NAME)

Usage

Basic Usage

from llama_index.llms.heroku import Heroku
from llama_index.core.llms import ChatMessage, MessageRole

# Initialize the Heroku LLM
llm = Heroku()

# Create chat messages
messages = [
    ChatMessage(
        role=MessageRole.SYSTEM, content="You are a helpful assistant."
    ),
    ChatMessage(
        role=MessageRole.USER,
        content="What are the most popular house pets in North America?",
    ),
]

# Get response
response = llm.chat(messages)
print(response)

Using Environment Variables

The integration automatically reads from environment variables:

import os

# Set environment variables
os.environ["INFERENCE_KEY"] = "your-inference-key"
os.environ["INFERENCE_URL"] = "https://us.inference.heroku.com"
os.environ["INFERENCE_MODEL_ID"] = "claude-3-5-haiku"

# Initialize without parameters
llm = Heroku()

Using Parameters

You can also pass parameters directly:

import os

llm = Heroku(
    model=os.getenv("INFERENCE_MODEL_ID", "claude-3-5-haiku"),
    api_key=os.getenv("INFERENCE_KEY", "your-inference-key"),
    inference_url=os.getenv(
        "INFERENCE_URL", "https://us.inference.heroku.com"
    ),
    max_tokens=1024,
)

Text Completion

# Simple text completion
response = llm.complete("Explain the importance of open source LLMs")
print(response.text)

Available Models

For a complete list of available models, see the Heroku Managed Inference documentation.

Error Handling

The integration includes proper error handling for common issues:

  • Missing API key
  • Invalid inference URL
  • Missing model configuration

Additional Information

For more information about Heroku Managed Inference, visit the official documentation.

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

llama_index_llms_heroku-0.1.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

llama_index_llms_heroku-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_heroku-0.1.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_llms_heroku-0.1.1.tar.gz
Algorithm Hash digest
SHA256 45ccb0a08fa70bec0819daa100c5d7164fc7c76a441d8cb66469b7026564b082
MD5 3aec75fa108cfb8e78d3953c893cc36f
BLAKE2b-256 04361250d9985d555033cda0a7f5bab6d3be67edf425148db3e51b2de817a486

See more details on using hashes here.

File details

Details for the file llama_index_llms_heroku-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_llms_heroku-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d630b055fab5a5073e32701e0ec0867ddfafbf6055b531d88e56cff351308de5
MD5 46d8823ba409a5b3d2b72e52d65f0492
BLAKE2b-256 c48147175f704605797bec36537f94f7a9b16482f2e7fda0678f972571434e0b

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