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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b925111159b8a4216e0d4eca765e2e764d40609110960b5c3d915e3332aed939
MD5 51029b839c40ff15b55f24ad387b0ada
BLAKE2b-256 9cbe561249b5b0d55a4a5766686f60febd337cda4d6bd8dcb284391348200d55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 de4d6dbae79fb4e3e1f0143391c3664d7e4c5be97564ccf03076184cc2b83686
MD5 06c458f1bd4b19d211544e23f22e2100
BLAKE2b-256 1cf0e81213491a400257aefb4c07300b4f8ab849bee6d61a2e4d9de3c07df791

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