Skip to main content

llama-index llms reka integration

Project description

LlamaIndex Llms Integration: Reka

This package provides integration between the Reka language model and LlamaIndex, allowing you to use Reka's powerful language models in your LlamaIndex applications. Installation To use this integration, you need to install the llama-index-llms-reka package:

pip install llama-index-llms-reka

To obtain API key, please visit https://platform.reka.ai/ Our baseline models always available for public access are:

  • reka-edge
  • reka-flash
  • reka-core

Other models may be available. The Get Models API allows you to list what models you have available to you. Using the Python SDK, it can be accessed as follows:

from reka.client import Reka

client = Reka()
print(client.models.get())

Here are some examples of how to use the Reka LLM integration with LlamaIndex:

import os
from llama_index.llms.reka import RekaLLM

api_key = os.getenv("REKA_API_KEY")
reka_llm = RekaLLM(model="reka-flash", api_key=api_key)

Initialize the Reka LLM client

api_key = os.getenv("REKA_API_KEY")
reka_llm = RekaLLM(model="reka-flash", api_key=api_key)

Chat completion

from llama_index.core.base.llms.types import ChatMessage, MessageRole

messages = [
    ChatMessage(
        role=MessageRole.SYSTEM, content="You are a helpful assistant."
    ),
    ChatMessage(
        role=MessageRole.USER, content="What is the capital of France?"
    ),
]
response = reka_llm.chat(messages)
print(response.message.content)

Text completion

prompt = "The capital of France is"
response = reka_llm.complete(prompt)
print(response.text)

Streaming Responses python

Streaming chat completion

messages = [
    ChatMessage(
        role=MessageRole.SYSTEM, content="You are a helpful assistant."
    ),
    ChatMessage(
        role=MessageRole.USER,
        content="List the first 5 planets in the solar system.",
    ),
]
for chunk in reka_llm.stream_chat(messages):
    print(chunk.delta, end="", flush=True)

Streaming text completion

prompt = "List the first 5 planets in the solar system:"
for chunk in reka_llm.stream_complete(prompt):
    print(chunk.delta, end="", flush=True)

Asynchronous Usage

import asyncio

async def main():
    # Async chat completion
    messages = [
        ChatMessage(role=MessageRole.SYSTEM, content="You are a helpful assistant."),
        ChatMessage(role=MessageRole.USER, content="What is the largest planet in our solar system?"),
    ]
    response = await reka_llm.achat(messages)
    print(response.message.content)

    # Async text completion
    prompt = "The largest planet in our solar system is"
    response = await reka_llm.acomplete(prompt)
    print(response.text)

    # Async streaming chat completion
    messages = [
        ChatMessage(role=MessageRole.SYSTEM, content="You are a helpful assistant."),
        ChatMessage(role=MessageRole.USER, content="Name the first 5 elements in the periodic table."),
    ]
    async for chunk in await reka_llm.astream_chat(messages):
        print(chunk.delta, end="", flush=True)

    # Async streaming text completion
    prompt = "List the first 5 elements in the periodic table:"
    async for chunk in await reka_llm.astream_complete(prompt):
        print(chunk.delta, end="", flush=True)

asyncio.run(main())

Running Tests

To run the tests for this integration, you'll need to have pytest and pytest-asyncio installed. You can install them using pip:

pip install pytest pytest-asyncio

Then, set your Reka API key as an environment variable:

export REKA_API_KEY=your_api_key_here

Now you can run the tests using pytest:

pytest tests/test_reka_llm.py -v

To run only mock integration test without remote connections pytest tests/test_reka_llm.py -v -k "mock" Note: The test file should be named test_reka_llm.py and placed in the appropriate directory.

Contributing

Contributions to improve this integration are welcome. Please ensure that you add or update tests as necessary when making changes. When adding new features or modifying existing ones, please update this README to reflect those changes.

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_reka-0.4.0.tar.gz (6.8 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_reka-0.4.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_reka-0.4.0.tar.gz.

File metadata

  • Download URL: llama_index_llms_reka-0.4.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_reka-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d36c913c3e16872de523e48de9e2174b85e99f5e1c646b8006c0d23a4e2f022b
MD5 dec23819b4803ab218b1d0cf3e2a120c
BLAKE2b-256 61a9e3cabf2c9240cfb125f4882ad681ba370533c6228af8ef24daa53c4ca1bf

See more details on using hashes here.

File details

Details for the file llama_index_llms_reka-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_reka-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_reka-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04c2623c48e4c3f2fc296fee26197a64bdc72f4038ffee6b5d32745a933d4e89
MD5 5601a07f96993316e7edfc04e79a45bd
BLAKE2b-256 3b0aa9643cd7e8822f17f799df73aaf72917fe6b51c269275aca6f5f9f4927c6

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