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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.1.2.tar.gz
Algorithm Hash digest
SHA256 98cd02cb36b5395224176cdfc7215ea1da9ac3e8ab9fcf9690e194f7c2d8cefa
MD5 9654be9a8f53409cb82f458bf074995d
BLAKE2b-256 c63534f265a6b94350f871a0ca6292993005c84465b0017049571bb0f54c6285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0325ad861e2e2d34a7c58d910390af84fdfed6d970109fe0fb7fbec666632f7a
MD5 e5496fb01c6030fb3b5839605183d7f0
BLAKE2b-256 1455b889bd8013cb927c6735535cf6610e873b729a9c2d2724df5a1dd8732857

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