Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1783,7 +1783,7 @@ def chatbot_response(message, history):
|
|
| 1783 |
"Relationship": [
|
| 1784 |
"We put a lot of emphasis on the interior experience and two of our cars have been ranked in the top 10. (24%)",
|
| 1785 |
"We are at the forefront of technology to deliver better cars and driving experiences. (17%)",
|
| 1786 |
-
"Our beginnings are a unique combination of investors and unions and today 9 of our 20 board members are staff representatives.(17%)",
|
| 1787 |
],
|
| 1788 |
"Competence": [
|
| 1789 |
"At the heart of our decision-making is the long-term quality of life for all of us. (20%)",
|
|
@@ -1809,13 +1809,11 @@ def chatbot_response(message, history):
|
|
| 1809 |
last_top_scoring_statements = top_scoring_statements
|
| 1810 |
|
| 1811 |
# Combine predefined prompt, top-scoring statements, and user input
|
| 1812 |
-
combined_prompt =
|
| 1813 |
-
combined_prompt += "\n\n### Top-Scoring Statements for Integration ###\n" + top_scoring_statements
|
| 1814 |
combined_prompt += "\n\nUser Input:\n" + message
|
| 1815 |
trust_tip, suggestion = get_trust_tip_and_suggestion()
|
| 1816 |
trust_tip_and_suggestion = f"\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
|
| 1817 |
|
| 1818 |
-
|
| 1819 |
# Validate chat history
|
| 1820 |
validated_chat_history = []
|
| 1821 |
for entry in history:
|
|
@@ -1824,20 +1822,24 @@ def chatbot_response(message, history):
|
|
| 1824 |
else:
|
| 1825 |
logger.warning(f"Invalid chat history entry skipped: {entry}")
|
| 1826 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1827 |
structured_input = {
|
| 1828 |
"input": combined_prompt,
|
| 1829 |
"chat_history": validated_chat_history,
|
| 1830 |
}
|
| 1831 |
|
| 1832 |
-
# Generate AI output using the agent pipeline
|
| 1833 |
agent_output = agent_executor.invoke(structured_input)
|
| 1834 |
|
| 1835 |
# Prepare the final response
|
| 1836 |
response = f"**Selected Dataset: {selected_dataset_ai}**\n\n"
|
| 1837 |
response += f"{top_scoring_statements}\n"
|
| 1838 |
response += f"\n{agent_output['output']}"
|
| 1839 |
-
|
| 1840 |
-
response+=trust_tip_and_suggestion
|
| 1841 |
|
| 1842 |
# Append interaction to history
|
| 1843 |
validated_chat_history.append({"role": "user", "content": message})
|
|
@@ -1855,7 +1857,6 @@ def chatbot_response(message, history):
|
|
| 1855 |
logger.error(f"Unexpected error: {e}")
|
| 1856 |
return "Error occurred during response generation."
|
| 1857 |
|
| 1858 |
-
|
| 1859 |
def read_ai_dataset_selection():
|
| 1860 |
global selected_dataset_ai
|
| 1861 |
return selected_dataset_ai
|
|
|
|
| 1783 |
"Relationship": [
|
| 1784 |
"We put a lot of emphasis on the interior experience and two of our cars have been ranked in the top 10. (24%)",
|
| 1785 |
"We are at the forefront of technology to deliver better cars and driving experiences. (17%)",
|
| 1786 |
+
"Our beginnings are a unique combination of investors and unions and today 9 of our 20 board members are staff representatives. (17%)",
|
| 1787 |
],
|
| 1788 |
"Competence": [
|
| 1789 |
"At the heart of our decision-making is the long-term quality of life for all of us. (20%)",
|
|
|
|
| 1809 |
last_top_scoring_statements = top_scoring_statements
|
| 1810 |
|
| 1811 |
# Combine predefined prompt, top-scoring statements, and user input
|
| 1812 |
+
combined_prompt = "\n\n### Top-Scoring Statements for Integration ###\n" + top_scoring_statements
|
|
|
|
| 1813 |
combined_prompt += "\n\nUser Input:\n" + message
|
| 1814 |
trust_tip, suggestion = get_trust_tip_and_suggestion()
|
| 1815 |
trust_tip_and_suggestion = f"\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
|
| 1816 |
|
|
|
|
| 1817 |
# Validate chat history
|
| 1818 |
validated_chat_history = []
|
| 1819 |
for entry in history:
|
|
|
|
| 1822 |
else:
|
| 1823 |
logger.warning(f"Invalid chat history entry skipped: {entry}")
|
| 1824 |
|
| 1825 |
+
# Include validated history in the prompt
|
| 1826 |
+
for entry in validated_chat_history:
|
| 1827 |
+
combined_prompt += f"\n{entry['role']}: {entry['content']}"
|
| 1828 |
+
|
| 1829 |
+
# Structured input for agent execution
|
| 1830 |
structured_input = {
|
| 1831 |
"input": combined_prompt,
|
| 1832 |
"chat_history": validated_chat_history,
|
| 1833 |
}
|
| 1834 |
|
| 1835 |
+
# Generate AI output using the agent pipeline (replace with actual logic)
|
| 1836 |
agent_output = agent_executor.invoke(structured_input)
|
| 1837 |
|
| 1838 |
# Prepare the final response
|
| 1839 |
response = f"**Selected Dataset: {selected_dataset_ai}**\n\n"
|
| 1840 |
response += f"{top_scoring_statements}\n"
|
| 1841 |
response += f"\n{agent_output['output']}"
|
| 1842 |
+
response += trust_tip_and_suggestion
|
|
|
|
| 1843 |
|
| 1844 |
# Append interaction to history
|
| 1845 |
validated_chat_history.append({"role": "user", "content": message})
|
|
|
|
| 1857 |
logger.error(f"Unexpected error: {e}")
|
| 1858 |
return "Error occurred during response generation."
|
| 1859 |
|
|
|
|
| 1860 |
def read_ai_dataset_selection():
|
| 1861 |
global selected_dataset_ai
|
| 1862 |
return selected_dataset_ai
|