alen commited on
Commit
b877de0
·
verified ·
1 Parent(s): bbe6faa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from langchain_community.llms import LlamaCpp
 
3
 
4
  vector_db_path = "vectorstores/db_faiss"
5
 
@@ -11,24 +12,23 @@ llm = LlamaCpp(
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
- respons = llm.create_chat_completion(
19
- messages = [
20
- {"role": "system", "content": "Bạn là trợ lý ảo tên là Aleni."},
21
- {
22
- "role": "user",
23
- "content": message
24
- }
25
- ]
26
- )
27
- print(respons)
28
- for chunk in llm.stream(message):
29
  respon += chunk
30
  # print(chunk.content, end="", flush=True)
31
  yield respon
 
 
32
  demo = gr.ChatInterface(
33
  respond,
34
  additional_inputs=[
 
1
  import gradio as gr
2
  from langchain_community.llms import LlamaCpp
3
+ from langchain.prompts import ChatPromptTemplate
4
 
5
  vector_db_path = "vectorstores/db_faiss"
6
 
 
12
  # callback_manager=callback_manager,
13
  verbose=True, # Verbose is required to pass to the callback manager
14
  )
15
+ template = """Bạn là trợ lý ảo của Linh tên là Aleni. bạn hãy sử dụng dữ liệu dưới đây để trả lời câu hỏi,
16
+ 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 hoặc tự suy luận
17
+ Question: {question}
18
+ Chỉ đưa ra các câu trả lời hữu ích.
19
+ Helpful answer:
20
+ """
21
+ # Content: {content}
22
  def respond(message, history, system_message, path_document):
23
+ prompt = ChatPromptTemplate.from_template(template)
24
+ llm_chain = prompt | llm
25
  respon = ''
26
+ for chunk in llm_chain.stream(message):
 
 
 
 
 
 
 
 
 
 
27
  respon += chunk
28
  # print(chunk.content, end="", flush=True)
29
  yield respon
30
+
31
+
32
  demo = gr.ChatInterface(
33
  respond,
34
  additional_inputs=[