Skip to main content

LlamaIndex Llms Integration: Clarifai

Installation

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

Basic Usage

# Set Clarifai PAT as an environment variable
import os

os.environ["CLARIFAI_PAT"] = "<YOUR CLARIFAI PAT>"

# Import Clarifai package
from llama_index.llms.clarifai import Clarifai

# Example parameters
params = dict(
    user_id="clarifai",
    app_id="ml",
    model_name="llama2-7b-alternative-4k",
    model_url="https://clarifai.com/clarifai/ml/models/llama2-7b-alternative-4k",
)

# Initialize the LLM
# Method:1 using model_url parameter
llm_model = Clarifai(model_url=params["model_url"])

# Method:2 using model_name, app_id & user_id parameters
llm_model = Clarifai(
    model_name=params["model_name"],
    app_id=params["app_id"],
    user_id=params["user_id"],
)

# Call complete function
llm_response = llm_model.complete(
    prompt="write a 10 line rhyming poem about science"
)
print(llm_response)

# Output
# Science is fun, it's true!
# From atoms to galaxies, it's all new!
# With experiments and tests, we learn so fast,
# And discoveries come from the past.
# It helps us understand the world around,
# And makes our lives more profound.
# So let's embrace this wondrous art,
# And see where it takes us in the start!

Call chat function

from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(role="user", content="write about climate change in 50 lines")
]
response = llm_model.chat(messages)
print(response)

# Output
# user: or less.
# Climate change is a serious threat to our planet and its inhabitants.
# Rising temperatures are causing extreme weather events, such as hurricanes,
# droughts, and wildfires. Sea levels are rising, threatening coastal
# communities and ecosystems. The melting of polar ice caps is disrupting
# global navigation and commerce. Climate change is also exacerbating air
# pollution, which can lead to respiratory problems and other health issues.
# It's essential that we take action now to reduce greenhouse gas emissions
# and transition to renewable energy sources to mitigate the worst effects
# of climate change.

Using Inference parameters

# Alternatively, you can call models with inference parameters.

# Here is an inference parameter example for GPT model.
inference_params = dict(temperature=str(0.3), max_tokens=20)

llm_response = llm_model.complete(
    prompt="What is nuclear fission and fusion?",
    inference_params=inference_params,
)

messages = [ChatMessage(role="user", content="Explain about the big bang")]
response = llm_model.chat(messages, inference_params=inference_params)

print(response)

LLM Implementation example

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

Metadata

Release files for llama-index-llms-clarifai 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-llms-clarifai 0.7.0
File Size Uploaded Provenance Actions
llama_index_llms_clarifai-0.7.0.tar.gz 6.0 kB Without provenance Details for llama_index_llms_clarifai-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-llms-clarifai 0.7.0
File Interpreter ABI Platform Actions
llama_index_llms_clarifai-0.7.0-py3-none-any.whl Python 3 none any Details for llama_index_llms_clarifai-0.7.0-py3-none-any.whl

Total release size: 11.5 kB

Release files / llama_index_llms_clarifai-0.7.0.tar.gz

Download URL llama_index_llms_clarifai-0.7.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0c689751fe07ce0a61ad69f5d7bc30e54f1def6a0dd3383143e581fb6b11879d
BLAKE2b-256 checksum
How to use checksums
03fbab77fc6286ba8c8a8f4afb760f84589785fe6a45922f234a5a4228d8d63b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_llms_clarifai-0.7.0-py3-none-any.whl

Download URL llama_index_llms_clarifai-0.7.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00086e51e481ac5ba25d297ef4e2d1f32bfd2f72983b1f1a3dedc2ae44d07963
BLAKE2b-256 checksum
How to use checksums
d960671e7b8afd1a12598fe3354c4d408e0a406228146faea6a168bbc08468b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-llms-clarifai 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page