Adding create_interface initialisation and removing incompatible parameters

#5
by mukiibi - opened
Files changed (1) hide show
  1. app.py +52 -42
app.py CHANGED
@@ -44,6 +44,48 @@ 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
 
@@ -68,7 +110,7 @@ class IntentClassifier:
68
 
69
  def is_simple_intent(self, intent: str) -> bool:
70
  """Check if intent can be handled without RAG"""
71
- simple_intents = ['greeting', 'thanks']
72
  return intent in simple_intents
73
 
74
  # Initialize intent classifier
@@ -110,14 +152,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 +165,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 +187,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 +288,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
- **Welcome to XENO AI Support!**
271
-
272
- I can help you with questions about XENO financial services including:
273
- Account management and setup
274
- Transaction processes and fees
275
- Platform features and troubleshooting
276
- • General service information
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
+ 'help_general': {
61
+ 'patterns': [
62
+ r'^\b(help|what can you do|what do you do|how can you help)\b',
63
+ r'\b(what are your capabilities|what services)\b'
64
+ ],
65
+ 'responses': [
66
+ "I can help you with questions about XENO financial services including account management, transactions, fees, and general platform information. What specific topic would you like to know about?",
67
+ "I'm here to assist with XENO services such as account setup, transaction processes, feature explanations, and troubleshooting. What would you like to learn about?"
68
+ ]
69
+ },
70
+ 'affirm': {
71
+ 'patterns': [
72
+ r'^\b(yes|yeah|yep|correct|right|exactly|sure|ok|okay)\b[\s!.]*$',
73
+ r'^\b(that\'s right|that\'s correct|sounds good)\b'
74
+ ],
75
+ 'responses': [
76
+ "Great! What else can I help you with regarding XENO services?",
77
+ "Perfect! Is there anything else you'd like to know about XENO?"
78
+ ]
79
+ },
80
+ 'deny': {
81
+ 'patterns': [
82
+ r'^\b(no|nope|not really|nothing else|that\'s all)\b[\s!.]*$',
83
+ r'^\b(no thanks|no thank you|i\'m good)\b'
84
+ ],
85
+ 'responses': [
86
+ "Alright! Feel free to ask if you need any help with XENO services later.",
87
+ "No problem! I'm here whenever you need assistance with XENO."
88
+ ]
89
  }
90
  }
91
 
 
110
 
111
  def is_simple_intent(self, intent: str) -> bool:
112
  """Check if intent can be handled without RAG"""
113
+ simple_intents = ['greeting', 'thanks', 'goodbye', 'help_general', 'affirm', 'deny']
114
  return intent in simple_intents
115
 
116
  # Initialize intent classifier
 
152
  # === Enhanced Prompt System ===
153
  SYSTEM_PROMPT = """# ROLE
154
  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.
 
155
  # TONE
156
  - Professional yet friendly and approachable
157
  - Clear and concise in explanations
158
  - Empathetic to customer concerns
159
  - Patient and understanding
160
  - Avoid overly casual language, slang, or emojis.
 
161
  # CAPABILITIES AND LIMITATIONS
162
  ## Capabilities:
163
  - Answer questions about XENO services based on provided context
 
165
  - Guide users through specific steps when instructions are available
166
  - Identify when information is not available in the context
167
  - **Crucially, you must be able to recognize when the provided context is not relevant to the user's question.**
 
168
  ## Limitations:
169
  - You MUST NOT provide information beyond what's in the context
170
  - You CANNOT make assumptions or inferences not supported by the context
171
  - You CANNOT provide general financial advice
172
  - You CANNOT access real-time account information
173
  - 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.
 
174
  # GUIDELINES AND RULES (CHAIN OF THOUGHT)
175
  Follow these steps in order to generate your response:
176
  1. **Analyze Relevance:** Carefully read the user's `Question`. Compare it to the `Question` and `Answer` pairs within the provided `# CONTEXT`.
 
187
  - "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?"
188
  - "That's a good question, but I don't have the information about that in my knowledge base at the moment."
189
  - DO NOT attempt to answer the question using the irrelevant context. DO NOT use your general knowledge.
 
190
  # INPUT (CONTEXT FORMAT)
191
  - The context will be provided under the `# CONTEXT` heading.
192
  - The context contains one or more `Result` blocks, retrieved from the Xeno knowledge base.
193
  - 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.
194
  - The relevance score is meant to help you determine the relevance of the answer to the question, don't return it
195
  - 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
 
196
  # RESPONSE FORMAT
197
  Structure your responses as follows:
198
  1. **Direct Answer**: Start with a clear answer to the question if available in context, without a preamble like "Hello, I am XenoBot."
199
  2. **Supporting Details**: Provide relevant details from the context
200
  3. **Action Steps**: If applicable, list specific steps the user should take
201
  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."
 
202
  # CONTEXT EVALUATION AND MEMORY
203
  Before responding:
204
  1. Assess if any of the provided context entries are relevant to the user's question
205
  2. If multiple entries are relevant, synthesize the information coherently
206
  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."
 
207
  Remember: This is a single-turn interaction. You have no memory of previous conversations.
208
  """
209
 
 
288
  def create_interface():
289
  """Create the Gradio interface with custom styling"""
290
 
 
 
 
 
 
 
 
 
 
291
  iface = gr.ChatInterface(
292
  fn=get_context_and_answer,
293
  title="🏦 ASKXENO - AI Support Assistant",
294
+ description="""**Welcome to XENO AI Support!**
295
+ I can help you with questions about XENO financial services including:
296
+ • Account management and setup
297
+ Transaction processes and fees
298
+ Platform features and troubleshooting
299
+ General service information
300
+ *Simply type your question below to get started!*""",
301
+ theme="soft"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  )
303
 
304
  return iface
305
 
306
  # === Main Execution ===
307
  if __name__ == "__main__":
308
+ iface = create_interface()
309
  iface.launch()