SatyamSinghal commited on
Commit
89b637e
·
verified ·
1 Parent(s): a5ff27e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -42,8 +42,14 @@ def command_handler(user_input):
42
  return None
43
 
44
  # Function to get the response from OpenAI with professionalism and energy
45
- def get_groq_response(message, user_language):
46
  try:
 
 
 
 
 
 
47
  response = openai.ChatCompletion.create(
48
  model="llama-3.1-70b-versatile",
49
  messages=[
@@ -61,7 +67,7 @@ def get_groq_response(message, user_language):
61
  f"Your primary goal is to assist users by providing accurate, personalized, and actionable insights related to private markets. Always maintain professionalism and conciseness. Ensure that responses are easy to interpret, and avoid jargon whenever possible.\n\n"
62
  )
63
  },
64
- {"role": "user", "content": message}
65
  ]
66
  )
67
  return response.choices[0].message["content"]
@@ -73,14 +79,29 @@ def format_response(data):
73
  if not data:
74
  return "No data available for this query."
75
 
 
 
76
  if isinstance(data, dict):
77
- formatted_response = "### Insights:\n\n"
78
  for key, value in data.items():
79
- formatted_response += f"**{key.capitalize()}**: {value}\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  elif isinstance(data, list):
81
- formatted_response = "### Insights:\n\n" + "\n".join(f"{idx+1}. {item}" for idx, item in enumerate(data))
82
  else:
83
- formatted_response = f"### Key Insights:\n\n{data}"
84
 
85
  return formatted_response.strip()
86
 
@@ -116,7 +137,7 @@ def market_analysis_agent(user_input, history=[]):
116
  response = workforce
117
  else:
118
  # Get dynamic AI response if query doesn't match predefined terms
119
- response = get_groq_response(user_input, user_language)
120
 
121
  # Format the response for easy readability and highlighting
122
  formatted_response = format_response(response)
 
42
  return None
43
 
44
  # Function to get the response from OpenAI with professionalism and energy
45
+ def get_groq_response(message, user_language, custom_data=None):
46
  try:
47
+ # If custom data is available, include it in the AI prompt
48
+ if custom_data:
49
+ prompt = f"Use the following information for analysis: {custom_data}. Then answer the user's query: {message}"
50
+ else:
51
+ prompt = message
52
+
53
  response = openai.ChatCompletion.create(
54
  model="llama-3.1-70b-versatile",
55
  messages=[
 
67
  f"Your primary goal is to assist users by providing accurate, personalized, and actionable insights related to private markets. Always maintain professionalism and conciseness. Ensure that responses are easy to interpret, and avoid jargon whenever possible.\n\n"
68
  )
69
  },
70
+ {"role": "user", "content": prompt}
71
  ]
72
  )
73
  return response.choices[0].message["content"]
 
79
  if not data:
80
  return "No data available for this query."
81
 
82
+ formatted_response = ""
83
+
84
  if isinstance(data, dict):
85
+ formatted_response += "### Key Insights:\n\n"
86
  for key, value in data.items():
87
+ if isinstance(value, dict):
88
+ # For nested dictionaries, add a heading for the sub-keys
89
+ formatted_response += f"**{key.capitalize()}**:\n"
90
+ for sub_key, sub_value in value.items():
91
+ formatted_response += f" - **{sub_key.capitalize()}**: {sub_value}\n"
92
+ elif isinstance(value, list):
93
+ # If the value is a list, show it as a bullet-point list
94
+ formatted_response += f"**{key.capitalize()}**:\n"
95
+ for idx, item in enumerate(value):
96
+ formatted_response += f" - {item}\n"
97
+ else:
98
+ # For other types of data, simply display key-value pairs
99
+ formatted_response += f"**{key.capitalize()}**: {value}\n"
100
+
101
  elif isinstance(data, list):
102
+ formatted_response += "### Insights:\n\n" + "\n".join(f"{idx+1}. {item}" for idx, item in enumerate(data))
103
  else:
104
+ formatted_response = f"### Key Insight:\n\n{data}"
105
 
106
  return formatted_response.strip()
107
 
 
137
  response = workforce
138
  else:
139
  # Get dynamic AI response if query doesn't match predefined terms
140
+ response = get_groq_response(user_input, user_language, custom_data=json.dumps(company_profile))
141
 
142
  # Format the response for easy readability and highlighting
143
  formatted_response = format_response(response)