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.1.tar.gz (4.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_meta-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5add7f9acc9e1d28df6eacff5030b0881474b510299dd00729eca4c5c3a7efce
MD5 de6925d797728db5939e1ce228b184cb
BLAKE2b-256 b2d9353e3d328aed0d7fdb2fd7404bd645b24f1f6fbe73e36937a3dca28ba164

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_llms_meta-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b62b197c413375458c3b84a2eca6c9632d41a16c5dfc219cd93847b589ab62b9
MD5 9acbe52dd29d8d419040fbd6a9589f2f
BLAKE2b-256 fcca7541ada04c71897f45970c0c6b292ba2c8b85c3cb2c75a0ac43b3a97d4b9

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