ng0-k1 commited on
Commit
d7b3670
·
1 Parent(s): ae7a494

Update actor with yahooquery to search actions in yahoo finance

Browse files
Files changed (2) hide show
  1. app.py +25 -10
  2. requirements.txt +1 -0
app.py CHANGED
@@ -4,19 +4,33 @@ import requests
4
  import pytz
5
  import yaml
6
  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:
@@ -38,11 +52,12 @@ final_answer = FinalAnswerTool()
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
40
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
41
 
42
  model = HfApiModel(
43
  max_tokens=2096,
44
  temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
  custom_role_conversions=None,
47
  )
48
 
@@ -55,7 +70,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,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
+ from yahooquery import search, Ticker
9
 
 
10
  @tool
11
+ def busqueda_valor_accion(nombre_empresa:str)-> str:
12
+ """Una tool que busca el valor de las acciones dentro de yahoo, para esto se requiere el nombre de la empresa especifica,
13
+ Ejemplo nombre_empresa podria tomar un valor como Amazon y retornara el nombre de la empresa, el simbolo dentro de la acción, el mercado al que pertenece y el valor de la acción.
14
+
15
  Args:
16
+ nombre_empresa:str Nombre de la empresa que se quiere consultar para realizar la busqueda de las acciones
17
+
18
  """
19
+ resultado = search(nombre_empresa)
20
+ if "quotes" in resultado and resultado["quotes"]:
21
+ primer_resultado = resultado["quotes"][0]
22
+ ticker = primer_resultado["symbol"]
23
+ precio_accion = Ticker(ticker)
24
+
25
+ # Unificar prints con saltos de línea
26
+ return f"""
27
+ Nombre: {primer_resultado['longname']}
28
+ Símbolo (Ticker): {ticker}
29
+ Mercado: {primer_resultado['exchange']}
30
+ El valor de la acción es: ${precio_accion.price[ticker]['regularMarketPrice']}
31
+ """
32
+ else:
33
+ return "No se encontraron resultados, por favor verifique el nombre de la empresa que busca consultar."
34
 
35
  @tool
36
  def get_current_time_in_timezone(timezone: str) -> str:
 
52
 
53
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
54
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
55
+ model_id = 'Qwen/Qwen2.5-Coder-32B-Instruct'
56
 
57
  model = HfApiModel(
58
  max_tokens=2096,
59
  temperature=0.5,
60
+ model_id=model_id,# it is possible that this model may be overloaded
61
  custom_role_conversions=None,
62
  )
63
 
 
70
 
71
  agent = CodeAgent(
72
  model=model,
73
+ tools=[busqueda_valor_accion, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
74
  max_steps=6,
75
  verbosity_level=1,
76
  grammar=None,
requirements.txt CHANGED
@@ -3,3 +3,4 @@ smolagents
3
  requests
4
  duckduckgo_search
5
  pandas
 
 
3
  requests
4
  duckduckgo_search
5
  pandas
6
+ yahooquery