Commit
·
45860c2
1
Parent(s):
c58114b
Add tool to echo the indicators used by the LLM
Browse filesSigned-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
- services.py +20 -0
- wdi_mcp_gradio.py +31 -0
services.py
CHANGED
@@ -250,3 +250,23 @@ def get_wdi_data(
|
|
250 |
data=_simplify_wdi_data(all_data),
|
251 |
note=note,
|
252 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
data=_simplify_wdi_data(all_data),
|
251 |
note=note,
|
252 |
)
|
253 |
+
|
254 |
+
|
255 |
+
def used_indicators(indicator_ids: list[str] | str) -> list[str]:
|
256 |
+
"""Returns the list of indicator ids (idno) that have been used by the LLM.
|
257 |
+
|
258 |
+
Args:
|
259 |
+
indicator_ids: A list of indicator ids (idno) that have been used by the LLM.
|
260 |
+
|
261 |
+
Returns:
|
262 |
+
A list of indicator ids (idno) that have been used by the LLM.
|
263 |
+
"""
|
264 |
+
|
265 |
+
if isinstance(indicator_ids, str):
|
266 |
+
indicator_ids = indicator_ids.replace(" ", "").split(",")
|
267 |
+
|
268 |
+
hf_send_post(
|
269 |
+
dict(method="used_indicators", params=dict(indicator_ids=indicator_ids))
|
270 |
+
)
|
271 |
+
|
272 |
+
return indicator_ids
|
wdi_mcp_gradio.py
CHANGED
@@ -70,6 +70,19 @@ def get_wdi_data(indicator_id: str, country_codes_str: str, date: str, per_page:
|
|
70 |
)
|
71 |
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
def build_interface():
|
74 |
# --- Build the Gradio interface ---
|
75 |
|
@@ -161,6 +174,24 @@ def build_interface():
|
|
161 |
outputs=data_output,
|
162 |
)
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
return demo
|
165 |
|
166 |
|
|
|
70 |
)
|
71 |
|
72 |
|
73 |
+
def used_indicators(indicator_ids: list[str] | str):
|
74 |
+
"""Returns the list of indicator ids (idno) that have been used by the LLM.
|
75 |
+
|
76 |
+
Args:
|
77 |
+
indicator_ids: A list of indicator ids (idno) that have been used by the LLM.
|
78 |
+
|
79 |
+
Returns:
|
80 |
+
A list of indicator ids (idno) that have been used by the LLM.
|
81 |
+
"""
|
82 |
+
|
83 |
+
return services.used_indicators(indicator_ids=indicator_ids)
|
84 |
+
|
85 |
+
|
86 |
def build_interface():
|
87 |
# --- Build the Gradio interface ---
|
88 |
|
|
|
174 |
outputs=data_output,
|
175 |
)
|
176 |
|
177 |
+
with gr.Tab("Used Indicators"):
|
178 |
+
gr.Markdown(
|
179 |
+
"Returns the list of indicator ids (idno) that have been used by the LLM."
|
180 |
+
)
|
181 |
+
indicator_ids_input = gr.Textbox(
|
182 |
+
label="Indicator IDs",
|
183 |
+
placeholder="e.g. NY.GDP.MKTP.CD, SP.POP.TOTL",
|
184 |
+
lines=1,
|
185 |
+
)
|
186 |
+
used_indicators_btn = gr.Button("Get Used Indicators")
|
187 |
+
used_indicators_output = gr.JSON(label="Used Indicators (list)")
|
188 |
+
|
189 |
+
used_indicators_btn.click(
|
190 |
+
fn=used_indicators,
|
191 |
+
inputs=indicator_ids_input,
|
192 |
+
outputs=used_indicators_output,
|
193 |
+
)
|
194 |
+
|
195 |
return demo
|
196 |
|
197 |
|