llama-index llms clarifai integration
Project description
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
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
Built Distribution
File details
Details for the file llama_index_llms_clarifai-0.3.0.tar.gz
.
File metadata
- Download URL: llama_index_llms_clarifai-0.3.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7af718fee7d66196d5b8bd9fadf9c938941bfda6cbc4ec023152a8b6d4a341f |
|
MD5 | a2abc29efb1e8c4f3ab448bbd660c7a6 |
|
BLAKE2b-256 | 9e16579d731eee1530ca599f2926681863b4b865aa396d939e1d6aa3129b4855 |
File details
Details for the file llama_index_llms_clarifai-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_llms_clarifai-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe824fec73105a0125c5f84636d6d013ee19f2b2babd09d0c545c304b1155353 |
|
MD5 | 642bb42e9a2afefa2860559b3ef19b8b |
|
BLAKE2b-256 | 3218c69a4e5f3beefbda3bf32f5c4b2ce2a5a172c6b8bca8e0e9568c6fd29bb4 |