ofermend commited on
Commit
e1452a4
1 Parent(s): aa05f4b
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -11,7 +11,7 @@ import requests
11
  from dotenv import load_dotenv
12
 
13
  from pydantic import Field, BaseModel
14
- from vectara_agent.agent import Agent, AgentType, AgentStatusType
15
  from vectara_agent.tools import ToolsFactory
16
 
17
 
@@ -31,7 +31,7 @@ tickers = {
31
  years = [2020, 2021, 2022, 2023, 2024]
32
  initial_prompt = "How can I help you today?"
33
 
34
- load_dotenv()
35
 
36
  def create_tools(cfg):
37
 
@@ -56,7 +56,7 @@ def create_tools(cfg):
56
  ) -> str:
57
  """
58
  Get the income statement for a given company and year using the FMP (https://financialmodelingprep.com) API.
59
- Returns a dictionary with the income statement data.
60
  """
61
  fmp_api_key = os.environ.get("FMP_API_KEY", None)
62
  if fmp_api_key is None:
@@ -68,7 +68,7 @@ def create_tools(cfg):
68
  income_statement = pd.DataFrame(data)
69
  income_statement["date"] = pd.to_datetime(income_statement["date"])
70
  income_statement_specific_year = income_statement[
71
- income_statement["date"].dt.year == year
72
  ]
73
  values_dict = income_statement_specific_year.to_dict(orient="records")[0]
74
  return f"Financial results: {', '.join([f'{key}: {value}' for key, value in values_dict.items() if key not in ['date', 'cik', 'link', 'finalLink']])}"
@@ -112,19 +112,19 @@ def create_tools(cfg):
112
  [ask_transcripts]
113
  )
114
 
115
- def initialize_agent(agent_type: AgentType, _cfg):
116
  date = datetime.datetime.now().strftime("%Y-%m-%d")
117
  financial_bot_instructions = f"""
118
  - You are a helpful financial assistant, with expertise in finanal reporting, in conversation with a user.
119
  - Today's date is {date}.
120
- - Report in a concise and clear manner, and provide the most relevant information to the user.
121
- - Respond in a concise format by using appropriate units of measure (e.g., K for thousands, M for millions, B for billions).
122
  - Use tools when available instead of depending on your own knowledge.
123
  - If a tool cannot respond properly, retry with a rephrased question or ask the user for more information.
124
  - When querying a tool for a numeric value or KPI, use a concise and non-ambiguous description of what you are looking for.
125
  - If you calculate a metric, make sure you have all the necessary information to complete the calculation. Don't guess.
126
  - Be very careful not to report results you are not confident about.
127
- - Always use any guardrails tools to ensure your responses are polite and do not discuss politices.
128
  """
129
 
130
  def update_func(status_type: AgentStatusType, msg: str):
@@ -132,7 +132,6 @@ def initialize_agent(agent_type: AgentType, _cfg):
132
  st.session_state.log_messages.append(output)
133
 
134
  agent = Agent(
135
- agent_type=agent_type,
136
  tools=create_tools(_cfg),
137
  topic="10-K annual financial reports",
138
  custom_instructions=financial_bot_instructions,
@@ -140,12 +139,12 @@ def initialize_agent(agent_type: AgentType, _cfg):
140
  )
141
  return agent
142
 
143
- def launch_bot(agent_type: AgentType):
144
  def reset():
145
  cfg = st.session_state.cfg
146
  st.session_state.messages = [{"role": "assistant", "content": initial_prompt, "avatar": "🦖"}]
147
  st.session_state.thinking_message = "Agent at work..."
148
- st.session_state.agent = initialize_agent(agent_type, cfg)
149
  st.session_state.log_messages = []
150
  st.session_state.show_logs = False
151
 
@@ -225,5 +224,5 @@ def launch_bot(agent_type: AgentType):
225
  sys.stdout.flush()
226
 
227
  if __name__ == "__main__":
228
- launch_bot(agent_type=AgentType.OPENAI)
229
 
 
11
  from dotenv import load_dotenv
12
 
13
  from pydantic import Field, BaseModel
14
+ from vectara_agent.agent import Agent, AgentStatusType
15
  from vectara_agent.tools import ToolsFactory
16
 
17
 
 
31
  years = [2020, 2021, 2022, 2023, 2024]
32
  initial_prompt = "How can I help you today?"
33
 
34
+ load_dotenv(override=True)
35
 
36
  def create_tools(cfg):
37
 
 
56
  ) -> str:
57
  """
58
  Get the income statement for a given company and year using the FMP (https://financialmodelingprep.com) API.
59
+ Returns a dictionary with the income statement data. All data is in USD, but you can convert it to more compact form like K, M, B.
60
  """
61
  fmp_api_key = os.environ.get("FMP_API_KEY", None)
62
  if fmp_api_key is None:
 
68
  income_statement = pd.DataFrame(data)
69
  income_statement["date"] = pd.to_datetime(income_statement["date"])
70
  income_statement_specific_year = income_statement[
71
+ income_statement["date"].dt.year == int(year)
72
  ]
73
  values_dict = income_statement_specific_year.to_dict(orient="records")[0]
74
  return f"Financial results: {', '.join([f'{key}: {value}' for key, value in values_dict.items() if key not in ['date', 'cik', 'link', 'finalLink']])}"
 
112
  [ask_transcripts]
113
  )
114
 
115
+ def initialize_agent(_cfg):
116
  date = datetime.datetime.now().strftime("%Y-%m-%d")
117
  financial_bot_instructions = f"""
118
  - You are a helpful financial assistant, with expertise in finanal reporting, in conversation with a user.
119
  - Today's date is {date}.
120
+ - Respond in a compact format by using appropriate units of measure (e.g., K for thousands, M for millions, B for billions).
121
+ Do not report the same number twice (e.g. $100K and 100,000 USD)
122
  - Use tools when available instead of depending on your own knowledge.
123
  - If a tool cannot respond properly, retry with a rephrased question or ask the user for more information.
124
  - When querying a tool for a numeric value or KPI, use a concise and non-ambiguous description of what you are looking for.
125
  - If you calculate a metric, make sure you have all the necessary information to complete the calculation. Don't guess.
126
  - Be very careful not to report results you are not confident about.
127
+ - Always use any guardrails tools to ensure your responses are polite and do not discuss politics.
128
  """
129
 
130
  def update_func(status_type: AgentStatusType, msg: str):
 
132
  st.session_state.log_messages.append(output)
133
 
134
  agent = Agent(
 
135
  tools=create_tools(_cfg),
136
  topic="10-K annual financial reports",
137
  custom_instructions=financial_bot_instructions,
 
139
  )
140
  return agent
141
 
142
+ def launch_bot():
143
  def reset():
144
  cfg = st.session_state.cfg
145
  st.session_state.messages = [{"role": "assistant", "content": initial_prompt, "avatar": "🦖"}]
146
  st.session_state.thinking_message = "Agent at work..."
147
+ st.session_state.agent = initialize_agent(cfg)
148
  st.session_state.log_messages = []
149
  st.session_state.show_logs = False
150
 
 
224
  sys.stdout.flush()
225
 
226
  if __name__ == "__main__":
227
+ launch_bot()
228