Kyleshechtman commited on
Commit
d9fff49
·
verified ·
1 Parent(s): f1c8621

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -7,16 +7,41 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +80,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ #S&P500 Sentiment StoryTeller
11
  @tool
12
+ def market_sentiment_story(index:str)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
+ """A tool that fetches the current price of the a stock exchanges and based on whether the price is up or down generate a short story or explanation for why that might be — even if speculative.
15
  Args:
16
+ index: A string representing one of the 3 major exchanges (e.g,'sp500','dowjones', or 'nasdaq')
 
17
  """
18
+ try:
19
+ # Map user input to Yahoo Finance symbols (I probably can make another function down the line)
20
+ ticker = {
21
+ "sp500": "^GSPC",
22
+ "dowjones": "^DJI",
23
+ "nasdaq": "^IXIC"
24
+ }
25
+ #Get the correct symbol for the requested index
26
+ ticker = symbols.get(index.lower())
27
+
28
+ # 3. Fetch data from Yahoo Finance
29
+ url = f"https://query1.finance.yahoo.com/v8/finance/chart/{symbol}"
30
+ data = requests.get(url).json()
31
+
32
+ # 4. Extract current and previous prices
33
+ result = data["chart"]["result"][0]["meta"]
34
+ current = result["regularMarketPrice"]
35
+ previous = result["chartPreviousClose"]
36
+ change = current - previous
37
+ percent = (change / previous) * 100
38
+
39
+ # 5. Return a prompt for the LLM to generate a story
40
+ return (
41
+ f"The {index.upper()} is currently at {current:.2f}, "
42
+ f"which is a change of {percent:.2f}% from the previous close. "
43
+ f"Write a short, realistic story that explains why it moved in this direction."
44
+ )
45
 
46
  @tool
47
  def get_current_time_in_timezone(timezone: str) -> str:
 
80
 
81
  agent = CodeAgent(
82
  model=model,
83
+ tools=[final_answer, market_sentiment_story], ## add your tools here (don't remove final answer)
84
  max_steps=6,
85
  verbosity_level=1,
86
  grammar=None,