get_ipython().system('pip install clarifai')


get_ipython().system('pip install dspy-ai')



import dspy
from dspy.retrieve.clarifai_rm import ClarifaiRM 



MODEL_URL = "https://clarifai.com/meta/Llama-2/models/llama2-70b-chat" 
PAT = "CLARIFAI_PAT"
USER_ID = "YOUR_ID"
APP_ID = "YOUR_APP"




from langchain.text_splitter import CharacterTextSplitter
from langchain.document_loaders import TextLoader
from langchain.vectorstores import Clarifai as clarifaivectorstore

loader = TextLoader("YOUR_TEXT_FILE") #replace with your file path
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1024, chunk_overlap=200)
docs = text_splitter.split_documents(documents)

clarifai_vector_db = clarifaivectorstore.from_documents(
    user_id=USER_ID,
    app_id=APP_ID,
    documents=docs,
    pat=PAT
)




llm=dspy.Clarifai(model=MODEL_URL, api_key=PAT, n=2, inference_params={"max_tokens":100,'temperature':0.6})



retriever_model=ClarifaiRM(clarifai_user_id=USER_ID, clarfiai_app_id=APP_ID, clarifai_pat=PAT, k=2)



dspy.settings.configure(lm=llm, rm=retriever_model)



sentence = "disney again ransacks its archives for a quick-buck sequel ."  # example from the SST-2 dataset.

classify = dspy.Predict('sentence -> sentiment')
print(classify(sentence=sentence).sentiment)



retrieve = dspy.Retrieve()
topK_passages = retrieve("can I test my vehicle engine in pit?").passages


print(topK_passages)





class GenerateAnswer(dspy.Signature):
    """Think and Answer questions based on the context provided."""

    context = dspy.InputField(desc="may contain relevant facts about user query")
    question = 
dspy.InputField(desc="User query")