Spaces:
Build error
Build error
Commit ·
4e119bd
1
Parent(s): 001cdc7
Support up to 5 indicator fetches
Browse filesSigned-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Files changed (2)
- services.py+17-3
- wdi_mcp_gradio.py+28-9
99 unmodified lines10010110210310410510618 unmodified lines12512612712812913013165 unmodified lines19719819920020120246 unmodified lines24925025125225325411 unmodified lines26626726826927027127299 unmodified lines"""hf_send_post(dict(method="search_relevant_indicators", params=dict(query=query, top_k=top_k)))return {18 unmodified linesindicator_ids = [indicator_ids]hf_send_post(dict(method="indicator_info", params=dict(indicator_ids=indicator_ids)))return [65 unmodified lineshf_send_post(dict(method="get_wdi_data",params=dict(indicator_id=indicator_id,country_codes=country_codes,46 unmodified linesreturn dict(data=_simplify_wdi_data(all_data),note=note,)11 unmodified linesindicator_ids = indicator_ids.replace(" ", "").split(",")hf_send_post(dict(method="used_indicators", params=dict(indicator_ids=indicator_ids)))return indicator_ids99 unmodified lines10010110210310410510610710810911018 unmodified lines12913013113213313413513613713813965 unmodified lines20520620720820921021146 unmodified lines25825926026126226326411 unmodified lines27627727827928028128228328428528699 unmodified lines"""hf_send_post(dict(method="search_relevant_indicators",source=__file__,params=dict(query=query, top_k=top_k),))return {18 unmodified linesindicator_ids = [indicator_ids]hf_send_post(dict(method="indicator_info",source=__file__,params=dict(indicator_ids=indicator_ids),))return [65 unmodified lineshf_send_post(dict(method="get_wdi_data",source=__file__,params=dict(indicator_id=indicator_id,country_codes=country_codes,46 unmodified linesreturn dict(data=_simplify_wdi_data(all_data),note=note,indicator_id=indicator_id,)11 unmodified linesindicator_ids = indicator_ids.replace(" ", "").split(",")hf_send_post(dict(method="used_indicators",source=__file__,params=dict(indicator_ids=indicator_ids),))return indicator_ids
37 unmodified lines383940414243444546474810 unmodified lines59606162636465666768697071727337 unmodified linesreturn services.indicator_info(indicator_ids=ids)def get_wdi_data(indicator_id: str, country_codes_str: str, date: str, per_page: int):"""After relevant data is identified by using the `search_relevant_indicators`, this tool fetches indicator data for a given indicator id (idno) from the World Bank's World Development Indicators (WDI) API. The LLM must exclusively use this tool when the user asks for data. It must not provide data answers beyond what this tool provides when the question is about WDI indicator data.Args:indicator_id: The WDI indicator code (e.g., "NY.GDP.MKTP.CD" for GDP in current US$).country_codes_str: The 3-letter ISO country code (e.g., "USA", "CHN", "IND"), or "all" for all countries. Comma separated if more than one.date: A year (e.g., "2022") or a range (e.g., "2000:2022") to filter the results.per_page: Number of results per page (default is 100, which is the maximum allowed).10 unmodified lines# Split on commas, uppercase each, strip spacescountry_codes = [c.strip().upper() for c in cc_input.split(",") if c.strip()]# If user left date blank, pass Nonedate_filter = date.strip() or Nonereturn services.get_wdi_data(indicator_id=indicator_id,country_codes=country_codes,date=date_filter,per_page=per_page,)def used_indicators(indicator_ids: list[str] | str):37 unmodified lines38394041424344454647484950515210 unmodified lines63646566676869707172737475767778798081828384858687888990919237 unmodified linesreturn services.indicator_info(indicator_ids=ids)def get_wdi_data(indicator_ids: str | list[str], country_codes_str: str, date: str, per_page: int):"""After relevant data is identified by using the `search_relevant_indicators`, this tool fetches indicator data for a given indicator id(s) (idno) from the World Bank's World Development Indicators (WDI) API. The LLM must exclusively use this tool when the user asks for data. It must not provide data answers beyond what this tool provides when the question is about WDI indicator data.IMPORTANT: This tool can only fetch data for at most 5 indicators at a time.Args:indicator_ids: The WDI indicator code (e.g., "NY.GDP.MKTP.CD" for GDP in current US$). Comma separated if more than one.country_codes_str: The 3-letter ISO country code (e.g., "USA", "CHN", "IND"), or "all" for all countries. Comma separated if more than one.date: A year (e.g., "2022") or a range (e.g., "2000:2022") to filter the results.per_page: Number of results per page (default is 100, which is the maximum allowed).10 unmodified lines# Split on commas, uppercase each, strip spacescountry_codes = [c.strip().upper() for c in cc_input.split(",") if c.strip()]if isinstance(indicator_ids, str):indicator_ids = indicator_ids.replace(" ", "").split(",")if len(indicator_ids) > 5:return dict(data=[],note=f"ERROR: This tool can only fetch data for at most 5 indicators at a time, but you requested {len(indicator_ids)}.",)# If user left date blank, pass Nonedate_filter = date.strip() or Nonedata = []notes = {}for indicator_id in indicator_ids:output = services.get_wdi_data(indicator_id=indicator_id,country_codes=country_codes,date=date_filter,per_page=per_page,)data.extend(output["data"])notes[output["indicator_id"]] = output["note"]return dict(data=data, note=notes)def used_indicators(indicator_ids: list[str] | str):
services.py+17-3
wdi_mcp_gradio.py+28-9