Back to Mem0

Cookbook for using Clarifai LLM and Embedders with Embedchain

embedchain/notebooks/clarifai.ipynb

2.0.12.0 KB
Original Source

Cookbook for using Clarifai LLM and Embedders with Embedchain

Step-1: Install embedchain-clarifai package

python
!pip install embedchain[clarifai]

Step-2: Set Clarifai PAT as env variable.

Sign-up to Clarifai platform and you can obtain CLARIFAI_PAT by following this link.

optionally you can also pass api_key in config of llm/embedder class.

python
import os
from embedchain import App

os.environ["CLARIFAI_PAT"]="xxx"

Step-3 Create embedchain app using clarifai LLM and embedder and define your config.

Browse through Clarifai community page to get the URL of different LLM and embedding models available.

python
# Use model_kwargs to pass all model specific parameters for inference.
app = App.from_config(config={
    "llm": {
        "provider": "clarifai",
        "config": {
            "model": "https://clarifai.com/mistralai/completion/models/mistral-7B-Instruct",
            "model_kwargs": {
            "temperature": 0.5,
            "max_tokens": 1000
            }
        }
    },
    "embedder": {
        "provider": "clarifai",
        "config": {
            "model": "https://clarifai.com/openai/embed/models/text-embedding-ada",
        }
}
})

Step-4: Add data sources to your app

python
app.add("https://www.forbes.com/profile/elon-musk")
python
while(True):
    question = input("Enter question: ")
    if question in ['q', 'exit', 'quit']:
        break
    answer = app.query(question)
    print(answer)