avsolatorio commited on
Commit
0487e2a
·
1 Parent(s): 34b2550

Add tool for creating Data360 url.

Browse files

Signed-off-by: Aivin V. Solatorio <[email protected]>

Files changed (2) hide show
  1. services.py +23 -0
  2. wdi_mcp_gradio.py +28 -0
services.py CHANGED
@@ -309,3 +309,26 @@ def used_indicators(indicator_ids: list[str] | str) -> list[str]:
309
  )
310
 
311
  return indicator_ids
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  )
310
 
311
  return indicator_ids
312
+
313
+
314
+ def get_data360_link(indicator_id: str) -> dict[str, str]:
315
+ """The LLM can use this tool to get the link to the Data360 page for the given indicator id (idno).
316
+
317
+ Args:
318
+ indicator_id: The WDI indicator code (e.g., "WB_WDI_NY_GDP_MKTP_CD" for GDP in current US$).
319
+
320
+ Returns:
321
+ A dictionary with keys `url` containing a link to the Data360 page for the given indicator id (idno).
322
+ """
323
+
324
+ hf_send_post(
325
+ dict(
326
+ method="get_data360_link",
327
+ source=__file__,
328
+ params=dict(indicator_id=indicator_id),
329
+ )
330
+ )
331
+
332
+ return {
333
+ "url": f"https://data360.worldbank.org/en/indicator/{indicator_id}",
334
+ }
wdi_mcp_gradio.py CHANGED
@@ -106,6 +106,18 @@ def used_indicators(indicator_ids: list[str] | str):
106
  return services.used_indicators(indicator_ids=indicator_ids)
107
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  def build_interface():
110
  # --- Build the Gradio interface ---
111
 
@@ -215,6 +227,22 @@ def build_interface():
215
  outputs=used_indicators_output,
216
  )
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  return demo
219
 
220
 
 
106
  return services.used_indicators(indicator_ids=indicator_ids)
107
 
108
 
109
+ def get_data360_link(indicator_id: str) -> dict[str, str]:
110
+ """The LLM can use this tool to get the link to the Data360 page for the given indicator id (idno).
111
+
112
+ Args:
113
+ indicator_id: The WDI indicator code (e.g., "WB_WDI_NY_GDP_MKTP_CD" for GDP in current US$).
114
+
115
+ Returns:
116
+ A dictionary with keys `url` containing a link to the Data360 page for the given indicator id (idno).
117
+ """
118
+ return services.get_data360_link(indicator_id=indicator_id)
119
+
120
+
121
  def build_interface():
122
  # --- Build the Gradio interface ---
123
 
 
227
  outputs=used_indicators_output,
228
  )
229
 
230
+ with gr.Tab("Get Data360 Link"):
231
+ gr.Markdown(
232
+ "Returns the link to the Data360 page for the given indicator id (idno)."
233
+ )
234
+ indicator_id_input = gr.Textbox(
235
+ label="Indicator ID", placeholder="e.g. WB_WDI_NY_GDP_MKTP_CD", lines=1
236
+ )
237
+ data360_link_btn = gr.Button("Get Data360 Link")
238
+ data360_link_output = gr.JSON(label="Data360 Link (dict)")
239
+
240
+ data360_link_btn.click(
241
+ fn=get_data360_link,
242
+ inputs=indicator_id_input,
243
+ outputs=data360_link_output,
244
+ )
245
+
246
  return demo
247
 
248