alen commited on
Commit
316655e
·
verified ·
1 Parent(s): 3f32d06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -5,8 +5,10 @@ from langchain_community.embeddings import GPT4AllEmbeddings
5
  from langchain.prompts import ChatPromptTemplate
6
  from langchain.schema.runnable import RunnablePassthrough
7
  from langchain_community.vectorstores import FAISS
8
- import os
9
- os.system("ollama pull alen_ox/llama_3_fin")
 
 
10
  vector_db_path = "vectorstores/db_faiss"
11
 
12
  # embeddings = OllamaEmbeddings(model="nomic-embed-text", show_progress=False)
@@ -17,9 +19,9 @@ db = FAISS.load_local(vector_db_path, embeddings, allow_dangerous_deserializatio
17
  # # Create retriever
18
  retriever = db.as_retriever(
19
  search_type="similarity",
20
- search_kwargs= {"k": 256}
21
  )
22
- local_llm = 'alen_ox/llama_3_fin'
23
 
24
  llm = ChatOllama(model=local_llm,
25
  keep_alive="3h",
@@ -32,10 +34,13 @@ def respond(message, history, system_message, path_document):
32
  print(message, history, system_message, path_document)
33
  respon = ''
34
  print("Answer:\n\n", end=" ", flush=True)
35
- template = f"""{system_message}"""+"""
36
- {context}
37
- Question: {question}
38
- """
 
 
 
39
  prompt = ChatPromptTemplate.from_template(template)
40
 
41
  rag_chain = (
@@ -51,7 +56,7 @@ def respond(message, history, system_message, path_document):
51
  demo = gr.ChatInterface(
52
  respond,
53
  additional_inputs=[
54
- gr.Textbox(value="Trả lời câu hỏi CHỈ dựa trên ngữ cảnh sau không có thì bảo không có câu trả lời:", label="System message"),
55
  gr.UploadButton("Upload a file", file_count="single"),
56
  # gr.DownloadButton("Download the file")
57
  ],
 
5
  from langchain.prompts import ChatPromptTemplate
6
  from langchain.schema.runnable import RunnablePassthrough
7
  from langchain_community.vectorstores import FAISS
8
+ # import os
9
+ # os.system("ollama pull alen_ox/llama_3_fin")
10
+ import ollama
11
+ ollama.pull("llama3.1")
12
  vector_db_path = "vectorstores/db_faiss"
13
 
14
  # embeddings = OllamaEmbeddings(model="nomic-embed-text", show_progress=False)
 
19
  # # Create retriever
20
  retriever = db.as_retriever(
21
  search_type="similarity",
22
+ search_kwargs= {"k": 3}
23
  )
24
+ local_llm = 'llama3.1'
25
 
26
  llm = ChatOllama(model=local_llm,
27
  keep_alive="3h",
 
34
  print(message, history, system_message, path_document)
35
  respon = ''
36
  print("Answer:\n\n", end=" ", flush=True)
37
+ 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,
38
+ 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
39
+ Content: {content}
40
+ Question: {question}
41
+ Chỉ đưa ra các câu trả lời hữu ích.
42
+ Helpful answer:
43
+ """
44
  prompt = ChatPromptTemplate.from_template(template)
45
 
46
  rag_chain = (
 
56
  demo = gr.ChatInterface(
57
  respond,
58
  additional_inputs=[
59
+ # gr.Textbox(value="Trả lời câu hỏi CHỈ dựa trên ngữ cảnh sau không có thì bảo không có câu trả lời:", label="System message"),
60
  gr.UploadButton("Upload a file", file_count="single"),
61
  # gr.DownloadButton("Download the file")
62
  ],