File size: 1,749 Bytes
9b2f45b
57a65f9
b877de0
9b2f45b
 
 
eb3b40c
 
 
 
 
 
 
 
 
 
 
57a65f9
9332631
 
 
57a65f9
 
 
 
5e9cc49
b877de0
 
 
 
 
 
9b2f45b
b877de0
 
9332631
b877de0
57a65f9
c9b8894
9b2f45b
b877de0
 
9b2f45b
 
 
316655e
9b2f45b
 
 
 
 
 
9dec028
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import gradio as gr
from langchain_community.llms import LlamaCpp
from langchain.prompts import ChatPromptTemplate

vector_db_path = "vectorstores/db_faiss"

llm_json = LlamaCpp(
    model_path="Llama-3.1-8B-Instruct.Q5_K_M.gguf",
    temperature=0,
    max_tokens=512,
    top_p=1,
    # callback_manager=callback_manager,
    verbose=True,
    format='json'
)
print(llm_json)

llm = LlamaCpp(
    model_path="Llama-3.1-8B-Instruct.Q5_K_M.gguf",
    temperature=0,
    max_tokens=512,
    top_p=1,
    # callback_manager=callback_manager,
    verbose=True,  # Verbose is required to pass to the callback manager
)
template = """Bạn là trợ lý ảo thông thái tên là Aleni. bạn hãy sử dụng dữ liệu dưới đây để trả lời câu hỏi, 
    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
    Question: {question}
    Chỉ đưa ra các câu trả lời hữu ích.
    Helpful answer:
    """
    # Content: {content}
def respond(message, history, system_message, path_document):
    prompt = ChatPromptTemplate.from_template(template)
    llm_chain = prompt | llm
    respon = ''
    for chunk in llm_chain.stream(message):
        respon += chunk
        # print(chunk.content, end="", flush=True)
        yield respon

        
demo = gr.ChatInterface(
    respond,
    additional_inputs=[
        # 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"),
        gr.UploadButton("Upload a file", file_count="single"),
        # gr.DownloadButton("Download the file")
    ],
)

if __name__ == "__main__":
    demo.launch()