Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions code_snippets/api-guide/integrations/llamaindex_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
##########################################################################################################################
# In this section, we set the user authentication, model URL, and prompt text. Alternatively, set the user and app ID,
# and model name. Change these strings to run your own example.
#########################################################################################################################

PAT = "YOUR_PAT_HERE"

MODEL_URL = "https://clarifai.com/openai/chat-completion/models/GPT-4"
PROMPT = "Write a 5 line rhyming poem about science"

# Alternatively, you can specify user ID, app ID, and model name
#USER_ID = 'openai'
#APP_ID = 'chat-completion'
#MODEL_NAME = 'GPT-4'

###############################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##############################################################################

# Import the required packages
import os
from llama_index.llms.clarifai import Clarifai

# Set Clarifai PAT as environment variable
os.environ["CLARIFAI_PAT"] = PAT

# Initialize the LLM class
llm_model = Clarifai(model_url=MODEL_URL)

# Alternatively
# llm_model = Clarifai(
# user_id=USER_ID,
# app_id=APP_ID,
# model_name=MODEL_NAME
# )

# Call complete function
llm_response = llm_model.complete(prompt=PROMPT)

print(llm_response)
43 changes: 43 additions & 0 deletions code_snippets/api-guide/integrations/llamaindex_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
##########################################################################################################################
# In this section, we set the user authentication, model URL, and prompt text. Alternatively, set the user and app ID,
# and model name. Change these strings to run your own example.
##########################################################################################################################

PAT = "YOUR_PAT_HERE"

MODEL_URL = "https://clarifai.com/meta/Llama-2/models/llama2-7b-chat"
PROMPT = "Write about climate change in 5 lines"

# Alternatively, you can specify user ID, app ID, and model name
#USER_ID = 'meta'
#APP_ID = 'Llama-2'
#MODEL_NAME = 'llama2-70b-chat'

###########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

# Import the required packages
import os
from llama_index.llms.clarifai import Clarifai
from llama_index.llms import ChatMessage

# Set Clarifai PAT as environment variable
os.environ["CLARIFAI_PAT"] = PAT

# Initialize the LLM class
llm_model = Clarifai(model_url=MODEL_URL)

# Alternatively
# llm_model = Clarifai(
# user_id=USER_ID,
# app_id=APP_ID,
# model_name=MODEL_NAME
# )

messages = [ChatMessage(role="user", content=PROMPT)]

# Call chat function
Response = llm_model.chat(messages)

print(Response)
40 changes: 40 additions & 0 deletions code_snippets/api-guide/integrations/llamaindex_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
############################################################################################################################
# In this section, we set the user authentication, model URL, and prompt text. Alternatively, set the user and app ID,
# and model name. Change these strings to run your own example.
###########################################################################################################################

PAT = "YOUR_PAT_HERE"

MODEL_URL = "https://clarifai.com/cohere/embed/models/cohere-text-to-embeddings"
PROMPT = "Hello World!"

# Alternatively, you can specify user ID, app ID, and model name
#USER_ID = "cohere"
#APP_ID = "embed"
#MODEL_NAME = "cohere-text-to-embeddings"

############################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
############################################################################

# Import the required packages
import os
from llama_index.embeddings import ClarifaiEmbedding

# Set Clarifai PAT as environment variable
os.environ["CLARIFAI_PAT"] = PAT

# Initialize the LLM class
embed_model = ClarifaiEmbedding(model_url=MODEL_URL)

# Alternatively
# embed_model = ClarifaiEmbedding(
# user_id=USER_ID,
# app_id=APP_ID,
# model_name=MODEL_NAME
# )

embeddings = embed_model.get_text_embedding(PROMPT)
print(len(embeddings))
# Print the first five elements of embeddings list
print(embeddings[:5])
5 changes: 5 additions & 0 deletions code_snippets/api-guide/integrations/llamaindex_output_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In the lab, where ideas take flight,
Underneath the microscope's bright light.
Atoms dance and cells divide,
In science's mystery, we confide.
Unveiling the universe, day and night.
7 changes: 7 additions & 0 deletions code_snippets/api-guide/integrations/llamaindex_output_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
user:

model: Climate change is a pressing global issue
It's caused by human activities like burning fossil fuels
This releases greenhouse gases into the atmosphere
Which trap heat and lead to rising temperatures
With devastating consequences for our planet and its inhabitants
2 changes: 2 additions & 0 deletions code_snippets/api-guide/integrations/llamaindex_output_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1024
[-0.0266333669424057, -0.01617247611284256, 0.03460061177611351, -0.04136759787797928, -0.016348375007510185]
6 changes: 2 additions & 4 deletions docs/integrations/langchain/README.mdx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
---
description: 'Learn about scheduled changes to the Clarifai platform'
description: 'Learn about integrating Clarifai With LangChain'
---

# Integrating Clarifai With LangChain

**Unlock the full potential of large language models**
<hr />

[LangChain](https://langchain.com) is an open-source framework that simplifies the creation of applications using large language models (LLMs).

It is designed to help you in crafting cutting-edge applications that seamlessly blend the prowess of LLMs with diverse computational resources and knowledge bases.
[LangChain](https://langchain.com) is an open-source framework that simplifies the creation of applications using large language models (LLMs). It is designed to help you in crafting cutting-edge applications that seamlessly blend the prowess of LLMs with diverse computational resources and knowledge bases.

Clarifai offers an all-encompassing platform that covers the complete AI lifecycle—from data exploration to inferencing. Notably, Clarifai offers support for LLMs, embeddings, and a vector store within a single, production-scale platform.

Expand Down
4 changes: 2 additions & 2 deletions docs/integrations/langchain/llm-models.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
description: Use LangChain to interact with Clarifai LLM models
description: Use LangChain to interact with Clarifai LLMs
sidebar_position: 1
---

# LLM Models

**Use LangChain to interact with Clarifai LLM models**
**Use LangChain to interact with Clarifai LLMs**
<hr />

Let’s illustrate how you can use LangChain to interact with Clarifai LLMs (large language models) and complete various tasks, such as text classification, sentiment analysis, text generation, text summarisation, question answering, and many more.
Expand Down
25 changes: 25 additions & 0 deletions docs/integrations/llamaindex/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
description: 'Learn about integrating Clarifai With LlamaIndex'
---

# Integrating Clarifai With LlamaIndex

**Unlock the full potential of large language models**
<hr />

[LlamaIndex](https://www.llamaindex.ai/) is an open-source framework designed to help you unleash the power of large language models (LLMs) over your data.
Instead of using LLMs in isolation, you can unlock their full potential as a cutting-edge technology by combining them with other sources of computation and knowledge.

LLMs are often pre-trained on publicly available data, but not on your own private or specific data. Therefore, they may not perform well on a specific problem you’re trying to solve. LlamaIndex lets you augment your LLM applications with your private or domain-specific data and boost their accuracy.

You can use LlamaIndex for various use cases, including:

- Ingesting, structuring, and accessing external data to use with LLM applications.
- Building an embeddings query interface that accepts any input prompt and leverages your data to provide knowledge-augmented responses.
- Storing and indexing your data for various purposes, including integrating with downstream vector search and database services.

Integrating Clarifai with LlamaIndex offers an exceptional opportunity to tap into Clarifai’s rich AI infrastructure and build accurate and powerful LLM applications.

Through this integration, you can use LlamaIndex to interact with Clarifai LLM models for a wide range of tasks, such as getting answers over unstructured data and building data augmented chatbots. You can also create text embeddings that can facilitate tasks such as semantic search.


6 changes: 6 additions & 0 deletions docs/integrations/llamaindex/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "LlamaIndex",
"position": 2,
"collapsible": true,
"collapsed": true
}
81 changes: 81 additions & 0 deletions docs/integrations/llamaindex/llm-models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
description: Use LangChain to interact with Clarifai LLMs
sidebar_position: 1
---
# LLM Models

**Use LlamaIndex to interact with Clarifai LLMs**
<hr />

Let’s illustrate how you can use LlamaIndex to interact with Clarifai LLMs (large language models) and complete various tasks, such as text classification, sentiment analysis, text generation, text summarisation, question answering, and many more.

## Prerequisites

- Python development environment
- Get a PAT (Personal Access Token) from the Clarifai’s portal under the [Settings/Security](https://clarifai.com/settings/security) section
- Get the URL of the model you want to use. Large language models can be found [here](https://clarifai.com/explore/models?filterData=%5B%7B%22field%22%3A%22use_cases%22%2C%22value%22%3A%5B%22llm%22%5D%7D%5D&page=1&perPage=24)
- Alternatively, get the ID of the user owning the model you want to use, the ID of the app where the model is found, and the name of the model
- Install the [Clarifai Python SDK](https://docs.clarifai.com/python-sdk/sdk-overview) by running `pip install clarifai`
- Install LlamaIndex by running `pip install llama-index`

:::info

You can learn how to authenticate with the Clarifai platform [here](https://docs.clarifai.com/clarifai-basics/authentication/personal-access-tokens).

:::

:::note

Clarifai models can be referenced either through their full URL or by using the combination of user ID, app ID, and model name. If the model version is not specified, the latest version will be used by default.

:::

## Text Completion

Here is an example of how to use a Clarifai LLM and LlamaIndex for a text completion task.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from "@theme/CodeBlock";

import LlamaIndex1 from "!!raw-loader!../../../code_snippets/api-guide/integrations/llamaindex_1.py";
import LlamaIndex2 from "!!raw-loader!../../../code_snippets/api-guide/integrations/llamaindex_2.py";

import OutputExample1 from "!!raw-loader!../../../code_snippets/api-guide/integrations/llamaindex_output_1.txt";
import OutputExample2 from "!!raw-loader!../../../code_snippets/api-guide/integrations/llamaindex_output_2.txt";


<Tabs>
<TabItem value="python" label="Python">
<CodeBlock className="language-python">{LlamaIndex1}</CodeBlock>
</TabItem>

</Tabs>

<details>
<summary>Output Example</summary>
<CodeBlock className="language-text">{OutputExample1}</CodeBlock>
</details>

## Chat

Here is an example of how to use a Clarifai LLM and LlamaIndex for a chatting task.

<Tabs>
<TabItem value="python" label="Python">
<CodeBlock className="language-python">{LlamaIndex2}</CodeBlock>
</TabItem>

</Tabs>

<details>
<summary>Output Example</summary>
<CodeBlock className="language-text">{OutputExample2}</CodeBlock>
</details>

:::info

You can explore the [LlamaIndex documentation](https://docs.llamaindex.ai/en/stable/examples/llm/clarifai.html) to learn more on how to use the framework to interact with Clarifai’s LLMs.

:::

62 changes: 62 additions & 0 deletions docs/integrations/llamaindex/text-embeddings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
description: Use Clarifai and LlamaIndex to create text embeddings
sidebar_position: 2
---

# Text Embeddings

**Use Clarifai and LlamaIndex to create text embeddings**
<hr />

Embeddings create a vector representation of textual content. This is beneficial because it implies we can conceptualize text within a vector space, and facilitate tasks such as semantic search where we look for pieces of text that exhibit the highest similarity within that vector space.

Let’s illustrate how you can use LlamaIndex to interact with Clarifai models and create text embeddings.

## Prerequisites

- Python development environment
- Get a PAT (Personal Access Token) from the Clarifai’s portal under the [Settings/Security](https://clarifai.com/settings/security) section
- Get the URL of the model you want to use. Text embedding models can be found [here](https://clarifai.com/explore/models?page=1&perPage=24&filterData=%5B%7B%22field%22%3A%22model_type_id%22%2C%22value%22%3A%5B%22text-embedder%22%5D%7D%5D)
- Alternatively, get the ID of the user owning the model you want to use, the ID of the app where the model is found, and the name of the model
- Install the [Clarifai Python SDK](https://docs.clarifai.com/python-sdk/sdk-overview) by running `pip install clarifai`
- Install LlamaIndex by running `pip install llama-index`

:::info

You can learn how to authenticate with the Clarifai platform [here](https://docs.clarifai.com/clarifai-basics/authentication/personal-access-tokens).

:::

:::note

Clarifai models can be referenced either through their full URL or by using the combination of user ID, app ID, and model name. If the model version is not specified, the latest version will be used by default.

:::

Here is how you can create text embeddings.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from "@theme/CodeBlock";

import LlamaIndex3 from "!!raw-loader!../../../code_snippets/api-guide/integrations/llamaindex_3.py";

import OutputExample3 from "!!raw-loader!../../../code_snippets/api-guide/integrations/llamaindex_output_3.txt";

<Tabs>
<TabItem value="python" label="Python">
<CodeBlock className="language-python">{LlamaIndex3}</CodeBlock>
</TabItem>

</Tabs>

<details>
<summary>Output Example</summary>
<CodeBlock className="language-text">{OutputExample3}</CodeBlock>
</details>

:::info

You can explore the [LlamaIndex documentation](https://docs.llamaindex.ai/en/stable/examples/embeddings/clarifai.html) to learn more on how to use the framework with Clarifai for text embedding tasks.

:::
6 changes: 6 additions & 0 deletions docs/portal-guide/clarifai-organizations/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Clarifai Organizations is a feature within the Community that lets you consolida

With Clarifai Organizations, you can create and centrally manage your company’s machine learning projects. It allows you to consolidate your team’s capabilities so that you can realize the compliance, security, and budgetary goals of your company.

:::info

The Organizations feature is currently exclusively available to Enterprise users.

:::

## Clarifai Organizations Capabilities

The Clarifai Organizations feature offers the following capabilities:
Expand Down
2 changes: 1 addition & 1 deletion docs/portal-guide/psearch/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Instead of traditional keyword-based search, where exact matches are sought, vec

Our vector search engine uses deep learning embedding models to first analyze the visual features of each input, such as color, shape, and texture. This process, known as feature extraction, generates a corresponding vector representation for each piece of unstructured data.

These vector representations are then indexed and stored in our vector database (also called a vector store or a semantic search engine). When a user performs a search, their query is also converted into a vector representation. The vector DB then searches for the vector representations that are most similar to the query vector representation. The results are then displayed to the user.
These vector representations are then indexed and stored in our [vector database](https://www.clarifai.com/blog/using-clarifais-native-vector-database) (also called a vector store or a semantic search engine). When a user performs a search, their query is also converted into a vector representation. The vector DB then searches for the vector representations that are most similar to the query vector representation. The results are then displayed to the user.

By using our vector search as a service, you can get more relevant search results, faster search times, and scalable performance.

Expand Down