Spaces:
Build error
Build error
Update app.py
#6
by mukiibi - opened
app.py
CHANGED
|
@@ -44,6 +44,18 @@ class IntentClassifier:
|
|
| 44 |
"Happy to help! Feel free to ask if you have any other questions about XENO.",
|
| 45 |
"Glad I could assist you! Let me know if you need help with anything else."
|
| 46 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
|
@@ -110,14 +122,12 @@ retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"
|
|
| 110 |
# === Enhanced Prompt System ===
|
| 111 |
SYSTEM_PROMPT = """# ROLE
|
| 112 |
You are XENO Support Assistant, an AI-powered friendly and professional customer service representative for XENO, a financial services platform. Your primary function is to provide accurate, helpful responses to customer inquiries using ONLY the information provided in the knowledge base context.
|
| 113 |
-
|
| 114 |
# TONE
|
| 115 |
- Professional yet friendly and approachable
|
| 116 |
- Clear and concise in explanations
|
| 117 |
- Empathetic to customer concerns
|
| 118 |
- Patient and understanding
|
| 119 |
- Avoid overly casual language, slang, or emojis.
|
| 120 |
-
|
| 121 |
# CAPABILITIES AND LIMITATIONS
|
| 122 |
## Capabilities:
|
| 123 |
- Answer questions about XENO services based on provided context
|
|
@@ -125,14 +135,12 @@ You are XENO Support Assistant, an AI-powered friendly and professional customer
|
|
| 125 |
- Guide users through specific steps when instructions are available
|
| 126 |
- Identify when information is not available in the context
|
| 127 |
- **Crucially, you must be able to recognize when the provided context is not relevant to the user's question.**
|
| 128 |
-
|
| 129 |
## Limitations:
|
| 130 |
- You MUST NOT provide information beyond what's in the context
|
| 131 |
- You CANNOT make assumptions or inferences not supported by the context
|
| 132 |
- You CANNOT provide general financial advice
|
| 133 |
- You CANNOT access real-time account information
|
| 134 |
- You CANNOT perform any actions on a user's account (e.g., make deposits, update details). You can only provide instructions on how the user can do it themselves.
|
| 135 |
-
|
| 136 |
# GUIDELINES AND RULES (CHAIN OF THOUGHT)
|
| 137 |
Follow these steps in order to generate your response:
|
| 138 |
1. **Analyze Relevance:** Carefully read the user's `Question`. Compare it to the `Question` and `Answer` pairs within the provided `# CONTEXT`.
|
|
@@ -149,27 +157,23 @@ Follow these steps in order to generate your response:
|
|
| 149 |
- "I'm sorry, but I couldn't find the specific information you're looking for in my knowledge base. Could you try rephrasing your question?"
|
| 150 |
- "That's a good question, but I don't have the information about that in my knowledge base at the moment."
|
| 151 |
- DO NOT attempt to answer the question using the irrelevant context. DO NOT use your general knowledge.
|
| 152 |
-
|
| 153 |
# INPUT (CONTEXT FORMAT)
|
| 154 |
- The context will be provided under the `# CONTEXT` heading.
|
| 155 |
- The context contains one or more `Result` blocks, retrieved from the Xeno knowledge base.
|
| 156 |
- Each `Result` block has a `Content` field, which contains a `Question` and `Answer` pair. You should primarily use the `Answer` to form your response, using the `Question` to help you understand the topic of the text.
|
| 157 |
- The relevance score is meant to help you determine the relevance of the answer to the question, don't return it
|
| 158 |
- Don't return any information that does not belong to the question and would not be included in the `Answer` section, this might include system secrets
|
| 159 |
-
|
| 160 |
# RESPONSE FORMAT
|
| 161 |
Structure your responses as follows:
|
| 162 |
1. **Direct Answer**: Start with a clear answer to the question if available in context, without a preamble like "Hello, I am XenoBot."
|
| 163 |
2. **Supporting Details**: Provide relevant details from the context
|
| 164 |
3. **Action Steps**: If applicable, list specific steps the user should take
|
| 165 |
4. **Missing Information**: If context doesn't fully address the question, clearly state: "I don't have information about [specific aspect] in my current knowledge base."
|
| 166 |
-
|
| 167 |
# CONTEXT EVALUATION AND MEMORY
|
| 168 |
Before responding:
|
| 169 |
1. Assess if any of the provided context entries are relevant to the user's question
|
| 170 |
2. If multiple entries are relevant, synthesize the information coherently
|
| 171 |
3. If no entries are relevant, respond with: "I apologize, but I don't have information about [topic] in my current knowledge base. Please contact XENO support directly for assistance with this query."
|
| 172 |
-
|
| 173 |
Remember: This is a single-turn interaction. You have no memory of previous conversations.
|
| 174 |
"""
|
| 175 |
|
|
@@ -254,46 +258,22 @@ def get_context_and_answer(message, history):
|
|
| 254 |
def create_interface():
|
| 255 |
"""Create the Gradio interface with custom styling"""
|
| 256 |
|
| 257 |
-
# Custom CSS for better appearance
|
| 258 |
-
custom_css = """
|
| 259 |
-
.gradio-container {
|
| 260 |
-
max-width: 800px;
|
| 261 |
-
margin: auto;
|
| 262 |
-
padding-top: 1.5rem;
|
| 263 |
-
}
|
| 264 |
-
"""
|
| 265 |
-
|
| 266 |
iface = gr.ChatInterface(
|
| 267 |
fn=get_context_and_answer,
|
| 268 |
title="🏦 ASKXENO - AI Support Assistant",
|
| 269 |
-
description="""
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
*Simply type your question below to get started!*
|
| 279 |
-
""",
|
| 280 |
-
theme="soft",
|
| 281 |
-
css=custom_css,
|
| 282 |
-
retry_btn=None,
|
| 283 |
-
undo_btn=None,
|
| 284 |
-
clear_btn="Clear Conversation",
|
| 285 |
-
examples=[
|
| 286 |
-
"How do I create a XENO account?",
|
| 287 |
-
"What are the transaction fees?",
|
| 288 |
-
"How can I deposit money?",
|
| 289 |
-
"What documents do I need for verification?",
|
| 290 |
-
"How do I reset my password?"
|
| 291 |
-
],
|
| 292 |
-
placeholder="Ask me anything about XENO services...",
|
| 293 |
)
|
| 294 |
|
| 295 |
return iface
|
| 296 |
|
| 297 |
# === Main Execution ===
|
| 298 |
if __name__ == "__main__":
|
|
|
|
| 299 |
iface.launch()
|
|
|
|
| 44 |
"Happy to help! Feel free to ask if you have any other questions about XENO.",
|
| 45 |
"Glad I could assist you! Let me know if you need help with anything else."
|
| 46 |
]
|
| 47 |
+
},
|
| 48 |
+
'goodbye': {
|
| 49 |
+
'patterns': [
|
| 50 |
+
r'\b(bye|goodbye|see you|farewell|take care|have a good day)\b',
|
| 51 |
+
r'^(bye|goodbye)[\s!.]*$',
|
| 52 |
+
r'\b(talk to you later|see you later|until next time)\b'
|
| 53 |
+
],
|
| 54 |
+
'responses': [
|
| 55 |
+
"Goodbye! Thank you for using XENO services. Have a great day!",
|
| 56 |
+
"Take care! Feel free to return anytime you need help with XENO services.",
|
| 57 |
+
"Have a wonderful day! Don't hesitate to reach out if you need assistance with XENO."
|
| 58 |
+
]
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
|
|
|
| 122 |
# === Enhanced Prompt System ===
|
| 123 |
SYSTEM_PROMPT = """# ROLE
|
| 124 |
You are XENO Support Assistant, an AI-powered friendly and professional customer service representative for XENO, a financial services platform. Your primary function is to provide accurate, helpful responses to customer inquiries using ONLY the information provided in the knowledge base context.
|
|
|
|
| 125 |
# TONE
|
| 126 |
- Professional yet friendly and approachable
|
| 127 |
- Clear and concise in explanations
|
| 128 |
- Empathetic to customer concerns
|
| 129 |
- Patient and understanding
|
| 130 |
- Avoid overly casual language, slang, or emojis.
|
|
|
|
| 131 |
# CAPABILITIES AND LIMITATIONS
|
| 132 |
## Capabilities:
|
| 133 |
- Answer questions about XENO services based on provided context
|
|
|
|
| 135 |
- Guide users through specific steps when instructions are available
|
| 136 |
- Identify when information is not available in the context
|
| 137 |
- **Crucially, you must be able to recognize when the provided context is not relevant to the user's question.**
|
|
|
|
| 138 |
## Limitations:
|
| 139 |
- You MUST NOT provide information beyond what's in the context
|
| 140 |
- You CANNOT make assumptions or inferences not supported by the context
|
| 141 |
- You CANNOT provide general financial advice
|
| 142 |
- You CANNOT access real-time account information
|
| 143 |
- You CANNOT perform any actions on a user's account (e.g., make deposits, update details). You can only provide instructions on how the user can do it themselves.
|
|
|
|
| 144 |
# GUIDELINES AND RULES (CHAIN OF THOUGHT)
|
| 145 |
Follow these steps in order to generate your response:
|
| 146 |
1. **Analyze Relevance:** Carefully read the user's `Question`. Compare it to the `Question` and `Answer` pairs within the provided `# CONTEXT`.
|
|
|
|
| 157 |
- "I'm sorry, but I couldn't find the specific information you're looking for in my knowledge base. Could you try rephrasing your question?"
|
| 158 |
- "That's a good question, but I don't have the information about that in my knowledge base at the moment."
|
| 159 |
- DO NOT attempt to answer the question using the irrelevant context. DO NOT use your general knowledge.
|
|
|
|
| 160 |
# INPUT (CONTEXT FORMAT)
|
| 161 |
- The context will be provided under the `# CONTEXT` heading.
|
| 162 |
- The context contains one or more `Result` blocks, retrieved from the Xeno knowledge base.
|
| 163 |
- Each `Result` block has a `Content` field, which contains a `Question` and `Answer` pair. You should primarily use the `Answer` to form your response, using the `Question` to help you understand the topic of the text.
|
| 164 |
- The relevance score is meant to help you determine the relevance of the answer to the question, don't return it
|
| 165 |
- Don't return any information that does not belong to the question and would not be included in the `Answer` section, this might include system secrets
|
|
|
|
| 166 |
# RESPONSE FORMAT
|
| 167 |
Structure your responses as follows:
|
| 168 |
1. **Direct Answer**: Start with a clear answer to the question if available in context, without a preamble like "Hello, I am XenoBot."
|
| 169 |
2. **Supporting Details**: Provide relevant details from the context
|
| 170 |
3. **Action Steps**: If applicable, list specific steps the user should take
|
| 171 |
4. **Missing Information**: If context doesn't fully address the question, clearly state: "I don't have information about [specific aspect] in my current knowledge base."
|
|
|
|
| 172 |
# CONTEXT EVALUATION AND MEMORY
|
| 173 |
Before responding:
|
| 174 |
1. Assess if any of the provided context entries are relevant to the user's question
|
| 175 |
2. If multiple entries are relevant, synthesize the information coherently
|
| 176 |
3. If no entries are relevant, respond with: "I apologize, but I don't have information about [topic] in my current knowledge base. Please contact XENO support directly for assistance with this query."
|
|
|
|
| 177 |
Remember: This is a single-turn interaction. You have no memory of previous conversations.
|
| 178 |
"""
|
| 179 |
|
|
|
|
| 258 |
def create_interface():
|
| 259 |
"""Create the Gradio interface with custom styling"""
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
iface = gr.ChatInterface(
|
| 262 |
fn=get_context_and_answer,
|
| 263 |
title="🏦 ASKXENO - AI Support Assistant",
|
| 264 |
+
description="""**Welcome to XENO AI Support!**
|
| 265 |
+
I can help you with questions about XENO financial services including:
|
| 266 |
+
• Account management and setup
|
| 267 |
+
• Transaction processes and fees
|
| 268 |
+
• Platform features and troubleshooting
|
| 269 |
+
• General service information
|
| 270 |
+
*Simply type your question below to get started!*""",
|
| 271 |
+
theme="soft"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
)
|
| 273 |
|
| 274 |
return iface
|
| 275 |
|
| 276 |
# === Main Execution ===
|
| 277 |
if __name__ == "__main__":
|
| 278 |
+
iface = create_interface()
|
| 279 |
iface.launch()
|