Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -94,6 +94,8 @@ def initialize_llmchain(llm_model, temperature, max_tokens, top_k, vector_db, pr
|
|
94 |
temperature=temperature,
|
95 |
max_new_tokens=max_tokens,
|
96 |
top_k=top_k,
|
|
|
|
|
97 |
)
|
98 |
|
99 |
progress(0.75, desc="Definindo memória de buffer...")
|
@@ -114,7 +116,7 @@ def initialize_llmchain(llm_model, temperature, max_tokens, top_k, vector_db, pr
|
|
114 |
)
|
115 |
progress(0.9, desc="Concluído!")
|
116 |
return qa_chain
|
117 |
-
|
118 |
# Função para gerar um nome de coleção válido
|
119 |
def create_collection_name(filepath):
|
120 |
collection_name = Path(filepath).stem
|
@@ -161,8 +163,10 @@ def format_chat_history(message, chat_history):
|
|
161 |
|
162 |
# Função para realizar a conversa com o chatbot
|
163 |
def conversation(qa_chain, message, history):
|
164 |
-
|
165 |
-
|
|
|
|
|
166 |
response_answer = response["answer"]
|
167 |
if response_answer.find("Resposta útil:") != -1:
|
168 |
response_answer = response_answer.split("Resposta útil:")[-1]
|
|
|
94 |
temperature=temperature,
|
95 |
max_new_tokens=max_tokens,
|
96 |
top_k=top_k,
|
97 |
+
# Adiciona um prompt de sistema para responder em português
|
98 |
+
system_prompt="Por favor, responda em português."
|
99 |
)
|
100 |
|
101 |
progress(0.75, desc="Definindo memória de buffer...")
|
|
|
116 |
)
|
117 |
progress(0.9, desc="Concluído!")
|
118 |
return qa_chain
|
119 |
+
|
120 |
# Função para gerar um nome de coleção válido
|
121 |
def create_collection_name(filepath):
|
122 |
collection_name = Path(filepath).stem
|
|
|
163 |
|
164 |
# Função para realizar a conversa com o chatbot
|
165 |
def conversation(qa_chain, message, history):
|
166 |
+
# Adiciona uma instrução para responder em português
|
167 |
+
message_with_language = "Por favor, responda em português: " + message
|
168 |
+
formatted_chat_history = format_chat_history(message_with_language, history)
|
169 |
+
response = qa_chain({"question": message_with_language, "chat_history": formatted_chat_history})
|
170 |
response_answer = response["answer"]
|
171 |
if response_answer.find("Resposta útil:") != -1:
|
172 |
response_answer = response_answer.split("Resposta útil:")[-1]
|