Commit 615fddf5 authored by Anh26535D's avatar Anh26535D

suacode

parent 5a242a6c
No related merge requests found
Pipeline #275 failed with stages
in 0 seconds
......@@ -33,13 +33,24 @@ context_memory = []
# yield gr.update(value=chat_history)
def generate_response_stream(chat_history, user_input):
global context_memory
try:
sql_query = generate_query_with_gemini(user_input, api_key, model, index, documents)
# Thêm câu hỏi của người dùng vào context_memory
context_memory.append({"role": "user", "content": user_input})
# Chuyển đổi định dạng tin nhắn thành dictionary với "role" và "content"
# Gộp toàn bộ context_memory thành một chuỗi văn bản để truyền vào truy vấn
combined_context = "\n".join([f"{msg['role']}: {msg['content']}" for msg in context_memory])
# Gửi truy vấn bao gồm bối cảnh đến Gemini API
sql_query = generate_query_with_gemini(combined_context, api_key, model, index, documents)
# Thêm phản hồi của chatbot vào cả chat_history và context_memory
chat_history.append({"role": "user", "content": user_input})
chat_history.append({"role": "assistant", "content": sql_query})
# Lưu phản hồi của chatbot vào context_memory để làm bối cảnh cho tương tác sau
context_memory.append({"role": "assistant", "content": sql_query})
yield gr.update(value=chat_history)
except Exception as e:
chat_history.append({"role": "assistant", "content": f"Error: {str(e)}"})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment