Update app.py
Browse files
app.py
CHANGED
|
@@ -29,26 +29,24 @@ def get_internet_data(query: str) -> str:
|
|
| 29 |
return result
|
| 30 |
|
| 31 |
def respond(message, history: list[tuple[str, str]]):
|
| 32 |
-
system_message = "Ikaw usa ka buotan nga Chatbot. Tubaga lang sa binisaya, ug ayaw gamita ang english nga pinulungan."
|
| 33 |
max_tokens = 4096
|
| 34 |
temperature = 0.6
|
| 35 |
top_p = 0.95
|
| 36 |
|
| 37 |
messages = [{"role": "system", "content": system_message}]
|
| 38 |
for user_text, assistant_text in history:
|
|
|
|
| 39 |
if user_text:
|
| 40 |
messages.append({"role": "user", "content": user_text})
|
| 41 |
if assistant_text:
|
| 42 |
messages.append({"role": "assistant", "content": assistant_text})
|
| 43 |
|
| 44 |
-
#
|
| 45 |
search_result = get_internet_data(message)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
})
|
| 50 |
-
# Include the original query as part of the conversation context.
|
| 51 |
-
messages.append({"role": "user", "content": message})
|
| 52 |
|
| 53 |
response = ""
|
| 54 |
previous_response = ""
|
|
@@ -63,11 +61,11 @@ def respond(message, history: list[tuple[str, str]]):
|
|
| 63 |
if not token:
|
| 64 |
break
|
| 65 |
response += token
|
| 66 |
-
# Yield only if new content was added
|
| 67 |
if response != previous_response:
|
| 68 |
yield response
|
| 69 |
previous_response = response
|
| 70 |
-
# Optional: break if the response is too long
|
| 71 |
if len(response) > 3000:
|
| 72 |
break
|
| 73 |
|
|
|
|
| 29 |
return result
|
| 30 |
|
| 31 |
def respond(message, history: list[tuple[str, str]]):
|
| 32 |
+
system_message = "Ikaw usa ka buotan nga Chatbot. Tubaga lang sa binisaya, ug ayaw gamita ang english nga pinulungan. Gamita ang pinakabag-ong impormasyon gikan sa internet kung kinahanglan."
|
| 33 |
max_tokens = 4096
|
| 34 |
temperature = 0.6
|
| 35 |
top_p = 0.95
|
| 36 |
|
| 37 |
messages = [{"role": "system", "content": system_message}]
|
| 38 |
for user_text, assistant_text in history:
|
| 39 |
+
# Ensure alternating roles: user then assistant
|
| 40 |
if user_text:
|
| 41 |
messages.append({"role": "user", "content": user_text})
|
| 42 |
if assistant_text:
|
| 43 |
messages.append({"role": "assistant", "content": assistant_text})
|
| 44 |
|
| 45 |
+
# Get search results based on the user's query.
|
| 46 |
search_result = get_internet_data(message)
|
| 47 |
+
# Enrich the user message with the search result.
|
| 48 |
+
enriched_message = f"{message}\n\nMga resulta gikan sa internet: {search_result}"
|
| 49 |
+
messages.append({"role": "user", "content": enriched_message})
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
response = ""
|
| 52 |
previous_response = ""
|
|
|
|
| 61 |
if not token:
|
| 62 |
break
|
| 63 |
response += token
|
| 64 |
+
# Yield only if new content was added.
|
| 65 |
if response != previous_response:
|
| 66 |
yield response
|
| 67 |
previous_response = response
|
| 68 |
+
# Optional: break if the response is too long.
|
| 69 |
if len(response) > 3000:
|
| 70 |
break
|
| 71 |
|