Ilke Ileri commited on
Commit
7242003
·
1 Parent(s): a1e3c35

Add keyword-based sales filter to redirect off-topic questions

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -82,6 +82,39 @@ def chat_completions():
82
  if not prompt:
83
  return jsonify({"error": "No prompt provided"}), 400
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  # Gemma formatında prompt
86
  formatted_prompt = f"<start_of_turn>user\n{prompt}<end_of_turn>\n<start_of_turn>model\n"
87
 
 
82
  if not prompt:
83
  return jsonify({"error": "No prompt provided"}), 400
84
 
85
+ # Sales-only keyword filter
86
+ sales_keywords = ['sale', 'price', 'objection', 'close', 'deal', 'customer', 'prospect',
87
+ 'lead', 'pitch', 'negotiate', 'client', 'business', 'product', 'service',
88
+ 'wisemate', 'revenue', 'quota', 'conversion', 'crm', 'follow up']
89
+
90
+ # Check if question is sales-related
91
+ prompt_lower = prompt.lower()
92
+ is_sales_related = any(keyword in prompt_lower for keyword in sales_keywords)
93
+
94
+ # If not sales-related, return redirect message
95
+ if not is_sales_related and len(prompt.split()) > 3: # Only filter if it's a real question
96
+ redirect_message = "I'm Daniel from Wisemate, and I specialize in sales and business topics. I can help you with sales techniques, handling objections, closing deals, and Wisemate's services. How can I assist you with your sales needs?"
97
+
98
+ return jsonify({
99
+ "id": "chatcmpl-redirect",
100
+ "object": "chat.completion",
101
+ "created": int(__import__('time').time()),
102
+ "model": MODEL_NAME,
103
+ "choices": [{
104
+ "index": 0,
105
+ "message": {
106
+ "role": "assistant",
107
+ "content": redirect_message
108
+ },
109
+ "finish_reason": "stop"
110
+ }],
111
+ "usage": {
112
+ "prompt_tokens": 0,
113
+ "completion_tokens": 0,
114
+ "total_tokens": 0
115
+ }
116
+ }), 200
117
+
118
  # Gemma formatında prompt
119
  formatted_prompt = f"<start_of_turn>user\n{prompt}<end_of_turn>\n<start_of_turn>model\n"
120