import streamlit as st from langchain.llms import LlamaCpp from langchain.embeddings import LlamaCppEmbeddings,OpenAIEmbeddings from langchain.prompts import PromptTemplate from langchain.chains import LLMChain from langchain.document_loaders import TextLoader from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import Chroma from datetime import datetime from langchain.chains import LLMChain, RetrievalQA from langchain.vectorstores import Chroma, FAISS from functions import * prompt_template = """Use the following pieces of context to answer the question at the end. You are a helpful,highly skilled AI writer made by greatidea. your purpose is to answer my questions in the most precise way possible. If you don't know the answer, just say that you don't know, don't try to make up an answer. {context} Question: {question} Answer:""" prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"]) model='quinto.bin' llm = LlamaCpp(model_path=model) embeddings = LlamaCppEmbeddings(model_path=model) llm_chain = LLMChain(llm=llm, prompt=prompt) new_db = Chroma(embedding_function=embeddings) qa = RetrievalQA.from_chain_type( retriever = new_db.as_retriever(), llm=llm, chain_type="stuff",) #retriever=retriever) question = st.text_input("Ask me") start=today() result = qa({"query": question}) end = today() st.write(result['result']) print('question: ',question) print('inizio: ', start) print('fine: ', end)