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/

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_clarifai-0.6.0.tar.gz (6.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_clarifai-0.6.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_clarifai-0.6.0.tar.gz.

File metadata

  • Download URL: llama_index_llms_clarifai-0.6.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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_clarifai-0.6.0.tar.gz
Algorithm Hash digest
SHA256 4aa3c0ec6e89e3b385ec784a62168964b83209c8dbc7ecf5c43498a6ceb747c1
MD5 02e36f12fab3849980a7b37cc3d19abc
BLAKE2b-256 190c00e8833785f923c4a3e56ee8288872f43172ae692defd3e6041102732f43

See more details on using hashes here.

File details

Details for the file llama_index_llms_clarifai-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_clarifai-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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_clarifai-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62d8847864e7ea39dc3ef9c9136983599e959d6a0ef270568f2fd4a64e96f057
MD5 55149a50f3470fb6ffdcadb1b88893a8
BLAKE2b-256 e1f1b1e81fa62894735740d8e8f08baa669dad5df83911ae0c3f052912bffa63

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

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