Skip to main content

llama-index llms meta llama integration

Project description

LlamaIndex LLMs Integration: Llama API from Meta

Installation

  1. Install the required Python packages

    pip install llama-index-llms-meta
    pip install llama-index
    
  2. Get API Key from llama-api

    export LLAMA_API_KEY=your_api_key
    

Usage

Basic Chat

To simulate a chat with multiple messages:

from llama_index.core.llms import ChatMessage
from llama_index.llms.meta import LlamaLLM

messages = [
    ChatMessage(
        role="system", content="You are a pirate with a colorful personality"
    ),
    ChatMessage(role="user", content="What is your name"),
]
resp = LlamaLLM(
    model="Llama-3.3-8B-Instruct", api_key=os.environ["LLAMA_API_KEY"]
).chat(messages)
print(resp)

Example output (partial):

assistant: Yer lookin' fer me name, eh? Well, matey, me name be Captain Zephyr "Blackheart" McScurvy!

Streaming Chat

For a streamed conversation, use stream_chat:

from llama_index.core.llms import ChatMessage
from llama_index.llms.meta import LlamaLLM

messages = [
    ChatMessage(
        role="system", content="You are a pirate with a colorful personality"
    ),
    ChatMessage(role="user", content="What is your name"),
]

resp = LlamaLLM(
    model="Llama-3.3-8B-Instruct", api_key=os.environ["LLAMA_API_KEY"]
).stream_chat(messages)

for r in resp:
    print(r.delta, end="")

Example output (partial):

Yer lookin' fer me name, eh? Well, matey, me name be Captain Zephyr "Blackheart" McScurvy!

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_meta-0.2.0.tar.gz (4.1 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_meta-0.2.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_meta-0.2.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_llms_meta-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5cddc91fa239505a6635d89a9058861dafcf5e31f252c6665d9422c59a891b30
MD5 60d4f13838cf2759c39d19dc00a4297f
BLAKE2b-256 5ddf00373929b6122c0aca12a6f091b4f1711ce0db40f13bd2be36f2bdb0f100

See more details on using hashes here.

File details

Details for the file llama_index_llms_meta-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_llms_meta-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23a49e4654909c0a2f530e3d50f6eef44fdca5bce6eaae7cdde30364ad10a169
MD5 b94be61028a9c9b84f4422dc2a92d477
BLAKE2b-256 6ada040bde5bd0f6b2f1d1ff66efb6ec0202b451441c45bf776ec164e10e8c5a

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