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.1.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.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2260d5f71634514c41ca165269a03a60db91ba542b70d31dbab1ab5da55346be
MD5 47edcf378d89cd1488a3c34d5b411c72
BLAKE2b-256 36484f9d964b0ad89a70b81d07af5e5713b3fefea37b098ef03325713c471b3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ddab1d7325fb0e4e316628195133342fd0ca3f5af0e3a55a23b7a2d686425eda
MD5 ba689002d5bcf1772aa6ce91b2c644cd
BLAKE2b-256 6de55d409863aff2bda11d462746bcd044852b6e6653d24fa5e678c750b82b9d

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