captain-awesome commited on
Commit
7d9fec0
1 Parent(s): adbfb07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -5
app.py CHANGED
@@ -3,18 +3,30 @@ from langchain_core.messages import AIMessage, HumanMessage
3
  from langchain_community.document_loaders import WebBaseLoader
4
  from langchain.text_splitter import RecursiveCharacterTextSplitter
5
  from langchain_community.vectorstores import Chroma
6
- from langchain_openai import OpenAIEmbeddings, ChatOpenAI
7
  from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
8
  from langchain.chains import create_history_aware_retriever, create_retrieval_chain
9
  from langchain.chains.combine_documents import create_stuff_documents_chain
10
- from dotenv import load_dotenv
 
 
 
11
 
12
- load_dotenv()
13
 
14
  def get_response(user_input):
15
  return "I dont know"
16
 
17
  def get_vector_store_from_url(url):
 
 
 
 
 
 
 
 
 
18
  loader = WebBaseLoader(url)
19
  document = loader.load()
20
 
@@ -23,13 +35,24 @@ def get_vector_store_from_url(url):
23
  document_chunks = text_splitter.split_documents(document)
24
 
25
  # create a vectorstore from the chunks
26
- vector_store = Chroma.from_documents(document_chunks, OpenAIEmbeddings())
 
27
 
28
  return vector_store
29
 
30
 
31
  def get_context_retriever_chain(vector_store):
32
- llm = ChatOpenAI()
 
 
 
 
 
 
 
 
 
 
33
 
34
  retriever = vector_store.as_retriever()
35
 
 
3
  from langchain_community.document_loaders import WebBaseLoader
4
  from langchain.text_splitter import RecursiveCharacterTextSplitter
5
  from langchain_community.vectorstores import Chroma
6
+ # from langchain_openai import OpenAIEmbeddings, ChatOpenAI
7
  from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
8
  from langchain.chains import create_history_aware_retriever, create_retrieval_chain
9
  from langchain.chains.combine_documents import create_stuff_documents_chain
10
+ from langchain_community.embeddings import HuggingFaceBgeEmbeddings
11
+ from langchain_community.llms import CTransformers
12
+ from ctransformers import AutoModelForCausalLM
13
+ # from dotenv import load_dotenv
14
 
15
+ # load_dotenv()
16
 
17
  def get_response(user_input):
18
  return "I dont know"
19
 
20
  def get_vector_store_from_url(url):
21
+ model_name = "BAAI/bge-large-en"
22
+ model_kwargs = {'device': 'cpu'}
23
+ encode_kwargs = {'normalize_embeddings': False}
24
+ embeddings = HuggingFaceBgeEmbeddings(
25
+ model_name=model_name,
26
+ model_kwargs=model_kwargs,
27
+ encode_kwargs=encode_kwargs
28
+ )
29
+
30
  loader = WebBaseLoader(url)
31
  document = loader.load()
32
 
 
35
  document_chunks = text_splitter.split_documents(document)
36
 
37
  # create a vectorstore from the chunks
38
+ # vector_store = Chroma.from_documents(document_chunks, OpenAIEmbeddings())
39
+ vector_store = Chroma.from_documents(document_chunks, embeddings)
40
 
41
  return vector_store
42
 
43
 
44
  def get_context_retriever_chain(vector_store):
45
+ # llm = ChatOpenAI()
46
+ llm = CTransformers(
47
+ # model = "TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
48
+ model= "TheBloke/Llama-2-7B-Chat-GGUF",
49
+ model_file = "llama-2-7b-chat.Q3_K_S.gguf",
50
+ model_type="llama",
51
+ max_new_tokens = 300,
52
+ temperature = 0.3,
53
+ lib="avx2", # for CPU
54
+ )
55
+
56
 
57
  retriever = vector_store.as_retriever()
58