alen commited on
Commit
9332631
·
verified ·
1 Parent(s): ac59785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -50
app.py CHANGED
@@ -1,66 +1,20 @@
1
  import gradio as gr
2
- # from langchain_community.chat_models import ChatOllama
3
- # from langchain_community.embeddings import GPT4AllEmbeddings
4
-
5
- # from langchain.prompts import ChatPromptTemplate
6
- # from langchain.schema.runnable import RunnablePassthrough
7
- # from langchain_community.vectorstores import FAISS
8
  from langchain_community.llms import LlamaCpp
9
 
10
- # import os
11
- # os.system("ollama pull alen_ox/llama_3_fin")
12
-
13
  vector_db_path = "vectorstores/db_faiss"
14
 
15
  llm = LlamaCpp(
16
- model_path="Llama-3.1-8B-Instruct.Q3_K_L.gguf",
17
- temperature=0.75,
18
- max_tokens=2000,
19
  top_p=1,
20
  # callback_manager=callback_manager,
21
  verbose=True, # Verbose is required to pass to the callback manager
22
  )
23
- # embeddings = OllamaEmbeddings(model="nomic-embed-text", show_progress=False)
24
- # embeddings = GPT4AllEmbeddings(model_name = "all-MiniLM-L6-v2.gguf2.f16.gguf", gpt4all_kwargs = {'allow_download': 'True'})
25
-
26
- # db = FAISS.load_local(vector_db_path, embeddings, allow_dangerous_deserialization=True)
27
-
28
- # # # Create retriever
29
- # retriever = db.as_retriever(
30
- # search_type="similarity",
31
- # search_kwargs= {"k": 3}
32
- # )
33
- # local_llm = 'llama3.1'
34
-
35
- # llm = ChatOllama(model=local_llm,
36
- # keep_alive="3h",
37
- # max_tokens=512,
38
- # temperature=0)
39
-
40
- # Create prompt template
41
 
42
  def respond(message, history, system_message, path_document):
43
- # print(message, history, system_message, path_document)
44
- respon = ''
45
- # print("Answer:\n\n", end=" ", flush=True)
46
- # template = """Bạn là trợ lý ảo vì vậy bạn hãy sử dụng dữ liệu dưới đây để trả lời câu hỏi,
47
- # nếu không có thông tin hãy đưa ra câu trả lời sát nhất với câu hỏi từ các thông tin tìm được
48
- # Content: {content}
49
- # Question: {question}
50
- # Chỉ đưa ra các câu trả lời hữu ích.
51
- # Helpful answer:
52
- # """
53
- # prompt = ChatPromptTemplate.from_template(template)
54
 
55
- # rag_chain = (
56
- # {"content": retriever, "question": RunnablePassthrough()}
57
- # | prompt
58
- # | llm
59
- # )
60
- # for chunk in rag_chain.stream(message):
61
- # respon += chunk.content
62
- # print(chunk.content, end="", flush=True)
63
- # yield respon
64
 
65
  for chunk in llm.stream(message):
66
  respon += chunk
 
1
  import gradio as gr
 
 
 
 
 
 
2
  from langchain_community.llms import LlamaCpp
3
 
 
 
 
4
  vector_db_path = "vectorstores/db_faiss"
5
 
6
  llm = LlamaCpp(
7
+ model_path="Llama-3.1-8B-Instruct.Q5_K_M.gguf",
8
+ temperature=0,
9
+ max_tokens=512,
10
  top_p=1,
11
  # callback_manager=callback_manager,
12
  verbose=True, # Verbose is required to pass to the callback manager
13
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  def respond(message, history, system_message, path_document):
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ respon = ''
 
 
 
 
 
 
 
 
18
 
19
  for chunk in llm.stream(message):
20
  respon += chunk