Name | llama-index-llms-clarifai JSON |
Version |
0.2.2
JSON |
| download |
home_page | None |
Summary | llama-index llms clarifai integration |
upload_time | 2024-10-08 22:23:10 |
maintainer | None |
docs_url | None |
author | Your Name |
requires_python | <4.0,>=3.8.1 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# LlamaIndex Llms Integration: Clarifai
### Installation
```bash
%pip install llama-index-llms-clarifai
!pip install llama-index
!pip install clarifai
```
### Basic Usage
```py
# 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
```py
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
```py
# 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/
Raw data
{
"_id": null,
"home_page": null,
"name": "llama-index-llms-clarifai",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8.1",
"maintainer_email": null,
"keywords": null,
"author": "Your Name",
"author_email": "you@example.com",
"download_url": "https://files.pythonhosted.org/packages/d8/c5/c723fcf0601c72efdccff64f7c9de2eef612378056dc1938c7d0fdb289aa/llama_index_llms_clarifai-0.2.2.tar.gz",
"platform": null,
"description": "# LlamaIndex Llms Integration: Clarifai\n\n### Installation\n\n```bash\n%pip install llama-index-llms-clarifai\n!pip install llama-index\n!pip install clarifai\n```\n\n### Basic Usage\n\n```py\n# Set Clarifai PAT as an environment variable\nimport os\n\nos.environ[\"CLARIFAI_PAT\"] = \"<YOUR CLARIFAI PAT>\"\n\n# Import Clarifai package\nfrom llama_index.llms.clarifai import Clarifai\n\n# Example parameters\nparams = dict(\n user_id=\"clarifai\",\n app_id=\"ml\",\n model_name=\"llama2-7b-alternative-4k\",\n model_url=\"https://clarifai.com/clarifai/ml/models/llama2-7b-alternative-4k\",\n)\n\n# Initialize the LLM\n# Method:1 using model_url parameter\nllm_model = Clarifai(model_url=params[\"model_url\"])\n\n# Method:2 using model_name, app_id & user_id parameters\nllm_model = Clarifai(\n model_name=params[\"model_name\"],\n app_id=params[\"app_id\"],\n user_id=params[\"user_id\"],\n)\n\n# Call complete function\nllm_response = llm_model.complete(\n prompt=\"write a 10 line rhyming poem about science\"\n)\nprint(llm_response)\n\n# Output\n# Science is fun, it's true!\n# From atoms to galaxies, it's all new!\n# With experiments and tests, we learn so fast,\n# And discoveries come from the past.\n# It helps us understand the world around,\n# And makes our lives more profound.\n# So let's embrace this wondrous art,\n# And see where it takes us in the start!\n```\n\n### Call chat function\n\n```py\nfrom llama_index.core.llms import ChatMessage\n\nmessages = [\n ChatMessage(role=\"user\", content=\"write about climate change in 50 lines\")\n]\nresponse = llm_model.chat(messages)\nprint(response)\n\n# Output\n# user: or less.\n# Climate change is a serious threat to our planet and its inhabitants.\n# Rising temperatures are causing extreme weather events, such as hurricanes,\n# droughts, and wildfires. Sea levels are rising, threatening coastal\n# communities and ecosystems. The melting of polar ice caps is disrupting\n# global navigation and commerce. Climate change is also exacerbating air\n# pollution, which can lead to respiratory problems and other health issues.\n# It's essential that we take action now to reduce greenhouse gas emissions\n# and transition to renewable energy sources to mitigate the worst effects\n# of climate change.\n```\n\n### Using Inference parameters\n\n```py\n# Alternatively, you can call models with inference parameters.\n\n# Here is an inference parameter example for GPT model.\ninference_params = dict(temperature=str(0.3), max_tokens=20)\n\nllm_response = llm_model.complete(\n prompt=\"What is nuclear fission and fusion?\",\n inference_params=inference_params,\n)\n\nmessages = [ChatMessage(role=\"user\", content=\"Explain about the big bang\")]\nresponse = llm_model.chat(messages, inference_params=inference_params)\n\nprint(response)\n```\n\n### LLM Implementation example\n\nhttps://docs.llamaindex.ai/en/stable/examples/llm/clarifai/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "llama-index llms clarifai integration",
"version": "0.2.2",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "314ab60da363566e04bf2f3854a6175cbaf1f97f49a4cf3b601b4977e68c569b",
"md5": "1afb25661f9a5cb37ea83c17c1a812ae",
"sha256": "24b45b42fccf38bb135fae6a644952afe86c99f1ee6b5ab2764e9a2c86cb4775"
},
"downloads": -1,
"filename": "llama_index_llms_clarifai-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1afb25661f9a5cb37ea83c17c1a812ae",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8.1",
"size": 4756,
"upload_time": "2024-10-08T22:23:08",
"upload_time_iso_8601": "2024-10-08T22:23:08.358972Z",
"url": "https://files.pythonhosted.org/packages/31/4a/b60da363566e04bf2f3854a6175cbaf1f97f49a4cf3b601b4977e68c569b/llama_index_llms_clarifai-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d8c5c723fcf0601c72efdccff64f7c9de2eef612378056dc1938c7d0fdb289aa",
"md5": "2691764b676df6563fa69addbb85c069",
"sha256": "9ffd80836173f0957ebc8925702ffc9710a301ca555358c8da54916f4d16013a"
},
"downloads": -1,
"filename": "llama_index_llms_clarifai-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "2691764b676df6563fa69addbb85c069",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8.1",
"size": 4418,
"upload_time": "2024-10-08T22:23:10",
"upload_time_iso_8601": "2024-10-08T22:23:10.154874Z",
"url": "https://files.pythonhosted.org/packages/d8/c5/c723fcf0601c72efdccff64f7c9de2eef612378056dc1938c7d0fdb289aa/llama_index_llms_clarifai-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-08 22:23:10",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-llms-clarifai"
}