Skip to main content

llama-index llms anyscale integration

Project description

LlamaIndex Llms Integration: Anyscale

Installation

%pip install llama-index-llms-anyscale
!pip install llama-index

Basic Usage

from llama_index.llms.anyscale import Anyscale
from llama_index.core.llms import ChatMessage

# Call chat with ChatMessage List
# You need to either set env var ANYSCALE_API_KEY or set api_key in the class constructor

# Example of setting API key through environment variable
# import os
# os.environ['ANYSCALE_API_KEY'] = '<your-api-key>'

# Initialize the Anyscale LLM with your API key
llm = Anyscale(api_key="<your-api-key>")

# Chat Example
message = ChatMessage(role="user", content="Tell me a joke")
resp = llm.chat([message])
print(resp)

# Expected Output:
# assistant: Sure, here's a joke for you:
#
# Why couldn't the bicycle stand up by itself?
#
# Because it was two-tired!
#
# I hope that brought a smile to your face! Is there anything else I can assist you with?

Streaming Example

message = ChatMessage(role="user", content="Tell me a story in 250 words")
resp = llm.stream_chat([message])
for r in resp:
    print(r.delta, end="")

# Output Example:
# Once upon a time, there was a young girl named Maria who lived in a small village surrounded by lush green forests.
# Maria was a kind and gentle soul, loved by everyone in the village. She spent most of her days exploring the forests,
# discovering new species of plants and animals, and helping the villagers with their daily chores...
# (Story continues until it reaches the word limit.)

Completion Example

resp = llm.complete("Tell me a joke")
print(resp)

# Expected Output:
# assistant: Sure, here's a joke for you:
#
# Why couldn't the bicycle stand up by itself?
#
# Because it was two-tired!

Streaming Completion Example

resp = llm.stream_complete("Tell me a story in 250 words")
for r in resp:
    print(r.delta, end="")

# Example Output:
# Once upon a time, there was a young girl named Maria who lived in a small village...
# (Stream continues as the story is generated.)

Model Configuration

llm = Anyscale(model="codellama/CodeLlama-34b-Instruct-hf")
resp = llm.complete("Show me the c++ code to send requests to HTTP Server")
print(resp)

LLM Implementation example

https://docs.llamaindex.ai/en/stable/examples/llm/anyscale/

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_anyscale-0.5.1.tar.gz (5.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_anyscale-0.5.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_anyscale-0.5.1.tar.gz.

File metadata

  • Download URL: llama_index_llms_anyscale-0.5.1.tar.gz
  • Upload date:
  • Size: 5.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_anyscale-0.5.1.tar.gz
Algorithm Hash digest
SHA256 4c5265d2c0591d43299fabd0fbefd1d134c57a797cfea53d9f062d4e79c6ebda
MD5 78c91377f1bf1abdf62cb88f295d919b
BLAKE2b-256 ccb8ff04960d35d74d0203913a59e12b5559782d79601b04ecb8fa3fab7dc95a

See more details on using hashes here.

File details

Details for the file llama_index_llms_anyscale-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_anyscale-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 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_anyscale-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3dca413a226b85d91c6d12f0caba52642b3a8cc8ebd4acf9261807b408643369
MD5 06160663fc0e181d6ffd0f092d155ba2
BLAKE2b-256 7da00eba66b1da5855f9e251133cc02fdb4d36b9b553235c0ac278bba49e40a7

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