invincible-jha commited on
Commit
414a697
·
verified ·
1 Parent(s): d09ad37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -7,6 +7,7 @@ import re
7
  import numpy as np
8
  from sklearn.feature_extraction.text import CountVectorizer
9
  from sklearn.naive_bayes import MultinomialNB
 
10
 
11
  # Set up logging
12
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -73,9 +74,9 @@ def check_confidence(response):
73
  uncertain_phrases = ["I'm not sure", "It's possible", "I don't have enough information"]
74
  return not any(phrase.lower() in response.lower() for phrase in uncertain_phrases)
75
 
76
- def generate_response(prompt):
77
  try:
78
- return client.text_generation(prompt, max_new_tokens=500, temperature=0.7)
79
  except Exception as e:
80
  logger.error(f"Error generating response: {e}")
81
  return "I apologize, but I'm having trouble generating a response at the moment. Please try again later."
@@ -92,7 +93,7 @@ def post_process_response(response):
92
  return response
93
 
94
  # Main function
95
- def zerodha_support(message, history):
96
  try:
97
  sanitized_message = sanitize_input(message)
98
 
@@ -102,7 +103,8 @@ def zerodha_support(message, history):
102
  sanitized_message = redact_sensitive_info(sanitized_message)
103
 
104
  # Generate response
105
- response = generate_response(f"{SHARED_CONTEXT}\n\nUser: {sanitized_message}\nAssistant:")
 
106
 
107
  if not check_response_content(response):
108
  response += "\n\nPlease note that I cannot provide specific investment advice or guarantee returns. For personalized guidance, please consult with a qualified financial advisor."
 
7
  import numpy as np
8
  from sklearn.feature_extraction.text import CountVectorizer
9
  from sklearn.naive_bayes import MultinomialNB
10
+ import asyncio
11
 
12
  # Set up logging
13
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
74
  uncertain_phrases = ["I'm not sure", "It's possible", "I don't have enough information"]
75
  return not any(phrase.lower() in response.lower() for phrase in uncertain_phrases)
76
 
77
+ async def generate_response(prompt):
78
  try:
79
+ return await client.text_generation(prompt, max_new_tokens=500, temperature=0.7)
80
  except Exception as e:
81
  logger.error(f"Error generating response: {e}")
82
  return "I apologize, but I'm having trouble generating a response at the moment. Please try again later."
 
93
  return response
94
 
95
  # Main function
96
+ async def zerodha_support(message, history):
97
  try:
98
  sanitized_message = sanitize_input(message)
99
 
 
103
  sanitized_message = redact_sensitive_info(sanitized_message)
104
 
105
  # Generate response
106
+ prompt = f"{SHARED_CONTEXT}\n\nUser: {sanitized_message}\nAssistant:"
107
+ response = await generate_response(prompt)
108
 
109
  if not check_response_content(response):
110
  response += "\n\nPlease note that I cannot provide specific investment advice or guarantee returns. For personalized guidance, please consult with a qualified financial advisor."