Spaces:
Sleeping
Sleeping
Update chatbot/core.py
Browse files- chatbot/core.py +12 -5
chatbot/core.py
CHANGED
@@ -7,6 +7,13 @@ from pydantic import Field
|
|
7 |
from typing import List, Callable
|
8 |
from langchain.schema import BaseRetriever, Document
|
9 |
from langchain.schema import HumanMessage, AIMessage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def translate_to_english(text: str) -> str:
|
12 |
"""Use Gemini LLM to translate text to English with recent chat context."""
|
@@ -88,10 +95,10 @@ qa_chain.get_chat_history = custom_get_chat_history
|
|
88 |
|
89 |
def get_chat_response(user_input: str) -> str:
|
90 |
"""Process user input and return chat response using Wikipedia retrieval."""
|
91 |
-
response = qa_chain(
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
# memory.chat_memory.add_message(AIMessage(content=response["result"]))
|
96 |
|
97 |
return response["result"]
|
|
|
|
7 |
from typing import List, Callable
|
8 |
from langchain.schema import BaseRetriever, Document
|
9 |
from langchain.schema import HumanMessage, AIMessage
|
10 |
+
from datetime import datetime
|
11 |
+
import pytz
|
12 |
+
|
13 |
+
def get_current_time():
|
14 |
+
utc_plus_7 = pytz.timezone("Asia/Ho_Chi_Minh") # UTC+7
|
15 |
+
now = datetime.now(utc_plus_7)
|
16 |
+
return now.strftime("%A, %Y-%m-%d %H:%M:%S") # Example: "Saturday, 2025-03-29 14:30:00"
|
17 |
|
18 |
def translate_to_english(text: str) -> str:
|
19 |
"""Use Gemini LLM to translate text to English with recent chat context."""
|
|
|
95 |
|
96 |
def get_chat_response(user_input: str) -> str:
|
97 |
"""Process user input and return chat response using Wikipedia retrieval."""
|
98 |
+
response = qa_chain({
|
99 |
+
"question": user_input,
|
100 |
+
"current_time": get_current_time() # Pass the current time
|
101 |
+
})
|
|
|
102 |
|
103 |
return response["result"]
|
104 |
+
|