Spaces:
Sleeping
Sleeping
remove redundant API files
Browse files- apis/__init__.py +0 -24
- apis/econdb.py +0 -67
- apis/passport_index.py +0 -104
- apis/statistics_of_the_world.py +0 -55
- apis/visadb.py +0 -55
- ui/chat.py +3 -4
- ui/inference/config.py +0 -150
- ui/inference/tools.py +0 -42
apis/__init__.py
CHANGED
|
@@ -1,33 +1,9 @@
|
|
| 1 |
# apis/__init__.py
|
| 2 |
-
from apis.econdb import list_datasets, list_series, list_sources
|
| 3 |
-
from apis.passport_index import (
|
| 4 |
-
get_visa_requirement as get_passport_index_requirement,
|
| 5 |
-
get_visa_requirement_matrix,
|
| 6 |
-
load_matrix_dataset,
|
| 7 |
-
load_tidy_dataset,
|
| 8 |
-
)
|
| 9 |
from apis.passport_visa import passport_stats, visa_requirement
|
| 10 |
-
from apis.statistics_of_the_world import (
|
| 11 |
-
get_history,
|
| 12 |
-
list_countries,
|
| 13 |
-
list_indicators,
|
| 14 |
-
)
|
| 15 |
-
from apis.visadb import get_questions
|
| 16 |
from apis.world_bank import get_indicator_series
|
| 17 |
|
| 18 |
__all__ = [
|
| 19 |
"get_indicator_series",
|
| 20 |
-
"get_history",
|
| 21 |
-
"list_countries",
|
| 22 |
-
"list_indicators",
|
| 23 |
-
"list_sources",
|
| 24 |
-
"list_datasets",
|
| 25 |
-
"list_series",
|
| 26 |
"visa_requirement",
|
| 27 |
"passport_stats",
|
| 28 |
-
"load_tidy_dataset",
|
| 29 |
-
"load_matrix_dataset",
|
| 30 |
-
"get_passport_index_requirement",
|
| 31 |
-
"get_visa_requirement_matrix",
|
| 32 |
-
"get_questions",
|
| 33 |
]
|
|
|
|
| 1 |
# apis/__init__.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from apis.passport_visa import passport_stats, visa_requirement
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from apis.world_bank import get_indicator_series
|
| 4 |
|
| 5 |
__all__ = [
|
| 6 |
"get_indicator_series",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"visa_requirement",
|
| 8 |
"passport_stats",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
]
|
apis/econdb.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
"""Econdb API client for macroeconomic time series discovery."""
|
| 2 |
-
|
| 3 |
-
from __future__ import annotations
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
from typing import Any
|
| 7 |
-
|
| 8 |
-
import requests
|
| 9 |
-
|
| 10 |
-
BASE_URL = "https://www.econdb.com/api"
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def _headers() -> dict[str, str]:
|
| 14 |
-
headers = {"Accept": "application/json"}
|
| 15 |
-
token = os.getenv("ECONDB_API_TOKEN")
|
| 16 |
-
if token:
|
| 17 |
-
headers["Authorization"] = f"Token {token}"
|
| 18 |
-
return headers
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
def _get_page(
|
| 22 |
-
path: str,
|
| 23 |
-
*,
|
| 24 |
-
page: int | None = None,
|
| 25 |
-
timeout: float = 30,
|
| 26 |
-
) -> dict[str, Any]:
|
| 27 |
-
url = f"{BASE_URL}/{path.strip('/')}/"
|
| 28 |
-
params = {"page": page} if page is not None else None
|
| 29 |
-
resp = requests.get(url, params=params, headers=_headers(), timeout=timeout)
|
| 30 |
-
resp.raise_for_status()
|
| 31 |
-
return resp.json()
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def list_sources(
|
| 35 |
-
*,
|
| 36 |
-
page: int | None = None,
|
| 37 |
-
timeout: float = 30,
|
| 38 |
-
) -> list[dict[str, Any]]:
|
| 39 |
-
"""List data sources (first page by default)."""
|
| 40 |
-
return _get_page("sources", page=page, timeout=timeout).get("results", [])
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
def list_datasets(
|
| 44 |
-
*,
|
| 45 |
-
page: int | None = None,
|
| 46 |
-
timeout: float = 30,
|
| 47 |
-
) -> list[dict[str, Any]]:
|
| 48 |
-
"""List datasets (first page by default)."""
|
| 49 |
-
return _get_page("datasets", page=page, timeout=timeout).get("results", [])
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def list_series(
|
| 53 |
-
*,
|
| 54 |
-
page: int | None = None,
|
| 55 |
-
timeout: float = 30,
|
| 56 |
-
) -> list[dict[str, Any]]:
|
| 57 |
-
"""
|
| 58 |
-
List series (first page by default).
|
| 59 |
-
|
| 60 |
-
Requires ``ECONDB_API_TOKEN``; the series endpoint is authenticated.
|
| 61 |
-
"""
|
| 62 |
-
token = os.getenv("ECONDB_API_TOKEN")
|
| 63 |
-
if not token:
|
| 64 |
-
raise ValueError(
|
| 65 |
-
"ECONDB_API_TOKEN environment variable is required for list_series()"
|
| 66 |
-
)
|
| 67 |
-
return _get_page("series", page=page, timeout=timeout).get("results", [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apis/passport_index.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
# apis/passport_index.py
|
| 2 |
-
"""Passport Index CSV dataset loader (ilyankou/passport-index-dataset)."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import pandas as pd
|
| 7 |
-
|
| 8 |
-
TIDY_URL = (
|
| 9 |
-
"https://raw.githubusercontent.com/ilyankou/passport-index-dataset/"
|
| 10 |
-
"master/passport-index-tidy-iso2.csv"
|
| 11 |
-
)
|
| 12 |
-
MATRIX_URL = (
|
| 13 |
-
"https://raw.githubusercontent.com/ilyankou/passport-index-dataset/"
|
| 14 |
-
"master/passport-index-matrix-iso2.csv"
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
_tidy_cache: pd.DataFrame | None = None
|
| 18 |
-
_matrix_cache: pd.DataFrame | None = None
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
def load_tidy_dataset(*, use_cache: bool = True) -> pd.DataFrame:
|
| 22 |
-
"""
|
| 23 |
-
Load the tidy ISO-2 dataset (columns: passport, destination, requirement).
|
| 24 |
-
|
| 25 |
-
Args:
|
| 26 |
-
use_cache: Reuse the in-memory copy on subsequent calls.
|
| 27 |
-
"""
|
| 28 |
-
global _tidy_cache
|
| 29 |
-
if use_cache and _tidy_cache is not None:
|
| 30 |
-
return _tidy_cache
|
| 31 |
-
df = pd.read_csv(TIDY_URL)
|
| 32 |
-
df = df.rename(
|
| 33 |
-
columns={
|
| 34 |
-
"Passport": "passport",
|
| 35 |
-
"Destination": "destination",
|
| 36 |
-
"Requirement": "requirement",
|
| 37 |
-
}
|
| 38 |
-
)
|
| 39 |
-
if use_cache:
|
| 40 |
-
_tidy_cache = df
|
| 41 |
-
return df
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def load_matrix_dataset(*, use_cache: bool = True) -> pd.DataFrame:
|
| 45 |
-
"""
|
| 46 |
-
Load the matrix ISO-2 dataset (passport rows, destination columns).
|
| 47 |
-
|
| 48 |
-
Args:
|
| 49 |
-
use_cache: Reuse the in-memory copy on subsequent calls.
|
| 50 |
-
"""
|
| 51 |
-
global _matrix_cache
|
| 52 |
-
if use_cache and _matrix_cache is not None:
|
| 53 |
-
return _matrix_cache
|
| 54 |
-
df = pd.read_csv(MATRIX_URL)
|
| 55 |
-
if "Passport" in df.columns:
|
| 56 |
-
df = df.rename(columns={"Passport": "passport"})
|
| 57 |
-
if "passport" not in df.columns and len(df.columns):
|
| 58 |
-
df = df.rename(columns={df.columns[0]: "passport"})
|
| 59 |
-
if use_cache:
|
| 60 |
-
_matrix_cache = df
|
| 61 |
-
return df
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
def get_visa_requirement(
|
| 65 |
-
passport_iso2: str,
|
| 66 |
-
destination_iso2: str,
|
| 67 |
-
*,
|
| 68 |
-
use_cache: bool = True,
|
| 69 |
-
) -> str | None:
|
| 70 |
-
"""
|
| 71 |
-
Look up visa requirement from the tidy dataset.
|
| 72 |
-
|
| 73 |
-
Returns:
|
| 74 |
-
Requirement code (e.g. ``visa free``, ``e-visa``) or ``None`` if not found.
|
| 75 |
-
"""
|
| 76 |
-
df = load_tidy_dataset(use_cache=use_cache)
|
| 77 |
-
match = df[
|
| 78 |
-
(df["passport"] == passport_iso2) & (df["destination"] == destination_iso2)
|
| 79 |
-
]
|
| 80 |
-
if match.empty:
|
| 81 |
-
return None
|
| 82 |
-
return str(match.iloc[0]["requirement"])
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
def get_visa_requirement_matrix(
|
| 86 |
-
passport_iso2: str,
|
| 87 |
-
destination_iso2: str,
|
| 88 |
-
*,
|
| 89 |
-
use_cache: bool = True,
|
| 90 |
-
) -> str | None:
|
| 91 |
-
"""
|
| 92 |
-
Look up visa requirement from the matrix dataset.
|
| 93 |
-
|
| 94 |
-
Returns:
|
| 95 |
-
Requirement code or ``None`` if the passport row is missing.
|
| 96 |
-
"""
|
| 97 |
-
mat = load_matrix_dataset(use_cache=use_cache)
|
| 98 |
-
rows = mat.loc[mat["passport"] == passport_iso2]
|
| 99 |
-
if rows.empty or destination_iso2 not in mat.columns:
|
| 100 |
-
return None
|
| 101 |
-
value = rows.iloc[0][destination_iso2]
|
| 102 |
-
if pd.isna(value):
|
| 103 |
-
return None
|
| 104 |
-
return str(value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apis/statistics_of_the_world.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
# apis/statistics_of_the_world.py
|
| 2 |
-
"""Statistics of the World API client."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import os
|
| 7 |
-
from typing import Any
|
| 8 |
-
|
| 9 |
-
import requests
|
| 10 |
-
|
| 11 |
-
BASE_URL = "https://statisticsoftheworld.com/api"
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def _headers() -> dict[str, str]:
|
| 15 |
-
api_key = os.getenv("SOTW_API_KEY")
|
| 16 |
-
if api_key:
|
| 17 |
-
return {"X-API-Key": api_key}
|
| 18 |
-
return {}
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
def get_history(
|
| 22 |
-
indicator: str,
|
| 23 |
-
country: str,
|
| 24 |
-
*,
|
| 25 |
-
timeout: float = 30,
|
| 26 |
-
) -> list[dict[str, Any]]:
|
| 27 |
-
"""
|
| 28 |
-
Fetch historical data for an indicator/country pair.
|
| 29 |
-
|
| 30 |
-
Args:
|
| 31 |
-
indicator: Indicator code (e.g. ``IMF.NGDPD``).
|
| 32 |
-
country: ISO-3 country code (e.g. ``USA``).
|
| 33 |
-
|
| 34 |
-
Returns:
|
| 35 |
-
List of yearly observations from ``payload["data"]``.
|
| 36 |
-
"""
|
| 37 |
-
url = f"{BASE_URL}/v2/history"
|
| 38 |
-
params = {"indicator": indicator, "country": country}
|
| 39 |
-
resp = requests.get(url, params=params, headers=_headers(), timeout=timeout)
|
| 40 |
-
resp.raise_for_status()
|
| 41 |
-
return resp.json().get("data", [])
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def list_countries(*, timeout: float = 30) -> list[dict[str, Any]]:
|
| 45 |
-
"""List all countries available in the API."""
|
| 46 |
-
resp = requests.get(f"{BASE_URL}/v1/countries", headers=_headers(), timeout=timeout)
|
| 47 |
-
resp.raise_for_status()
|
| 48 |
-
return resp.json().get("data", [])
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
def list_indicators(*, timeout: float = 30) -> list[dict[str, Any]]:
|
| 52 |
-
"""List all indicators available in the API."""
|
| 53 |
-
resp = requests.get(f"{BASE_URL}/v1/indicators", headers=_headers(), timeout=timeout)
|
| 54 |
-
resp.raise_for_status()
|
| 55 |
-
return resp.json().get("data", [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apis/visadb.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
# apis/visadb.py
|
| 2 |
-
"""VisaDB API client (paid visa & travel data)."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import os
|
| 7 |
-
from typing import Any
|
| 8 |
-
|
| 9 |
-
import requests
|
| 10 |
-
|
| 11 |
-
QUESTION_BANK_URL = "https://question-bank-api.vercel.app"
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def _auth_headers() -> dict[str, str]:
|
| 15 |
-
api_key = os.getenv("VISADB_API_KEY")
|
| 16 |
-
if not api_key:
|
| 17 |
-
raise ValueError(
|
| 18 |
-
"VISADB_API_KEY environment variable is required for VisaDB requests"
|
| 19 |
-
)
|
| 20 |
-
return {"Authorization": api_key}
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def get_questions(*, timeout: float = 10) -> list[dict[str, Any]]:
|
| 24 |
-
"""Fetch questions from the VisaDB question bank."""
|
| 25 |
-
resp = requests.get(
|
| 26 |
-
f"{QUESTION_BANK_URL}/get/questions",
|
| 27 |
-
headers=_auth_headers(),
|
| 28 |
-
timeout=timeout,
|
| 29 |
-
)
|
| 30 |
-
resp.raise_for_status()
|
| 31 |
-
return resp.json()
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def request(
|
| 35 |
-
base_url: str,
|
| 36 |
-
path: str,
|
| 37 |
-
*,
|
| 38 |
-
params: dict[str, str] | None = None,
|
| 39 |
-
timeout: float = 10,
|
| 40 |
-
) -> Any:
|
| 41 |
-
"""
|
| 42 |
-
Generic authenticated VisaDB request.
|
| 43 |
-
|
| 44 |
-
Use this for visa/entry/safety endpoints documented at visadb.io/api;
|
| 45 |
-
pass the appropriate ``base_url`` and ``path``.
|
| 46 |
-
"""
|
| 47 |
-
url = f"{base_url.rstrip('/')}/{path.lstrip('/')}"
|
| 48 |
-
resp = requests.get(
|
| 49 |
-
url,
|
| 50 |
-
params=params,
|
| 51 |
-
headers=_auth_headers(),
|
| 52 |
-
timeout=timeout,
|
| 53 |
-
)
|
| 54 |
-
resp.raise_for_status()
|
| 55 |
-
return resp.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui/chat.py
CHANGED
|
@@ -7,10 +7,9 @@ from ui.inference import respond
|
|
| 7 |
ADDITIONAL_INPUTS = [
|
| 8 |
gr.Textbox(
|
| 9 |
value=(
|
| 10 |
-
"You are a friendly chatbot with access to
|
| 11 |
-
"
|
| 12 |
-
"
|
| 13 |
-
"passport strength, or other country-level statistics."
|
| 14 |
),
|
| 15 |
label="System message",
|
| 16 |
),
|
|
|
|
| 7 |
ADDITIONAL_INPUTS = [
|
| 8 |
gr.Textbox(
|
| 9 |
value=(
|
| 10 |
+
"You are a friendly chatbot with access to World Bank economic data "
|
| 11 |
+
"and passport/visa information. Use tools when users ask about GDP, "
|
| 12 |
+
"inflation, trade, visa requirements, or passport strength."
|
|
|
|
| 13 |
),
|
| 14 |
label="System message",
|
| 15 |
),
|
ui/inference/config.py
CHANGED
|
@@ -33,97 +33,6 @@ TOOLS: list[dict[str, Any]] = [
|
|
| 33 |
},
|
| 34 |
},
|
| 35 |
},
|
| 36 |
-
{
|
| 37 |
-
"type": "function",
|
| 38 |
-
"function": {
|
| 39 |
-
"name": "get_statistics_history",
|
| 40 |
-
"description": (
|
| 41 |
-
"Fetch Statistics of the World historical yearly observations for "
|
| 42 |
-
"an indicator/country pair. Use ISO-3 country codes."
|
| 43 |
-
),
|
| 44 |
-
"parameters": {
|
| 45 |
-
"type": "object",
|
| 46 |
-
"properties": {
|
| 47 |
-
"indicator": {
|
| 48 |
-
"type": "string",
|
| 49 |
-
"description": "Statistics of the World indicator code, e.g. IMF.NGDPD",
|
| 50 |
-
},
|
| 51 |
-
"country": {
|
| 52 |
-
"type": "string",
|
| 53 |
-
"description": "ISO-3 country code, e.g. USA, IND, HKG",
|
| 54 |
-
},
|
| 55 |
-
},
|
| 56 |
-
"required": ["indicator", "country"],
|
| 57 |
-
},
|
| 58 |
-
},
|
| 59 |
-
},
|
| 60 |
-
{
|
| 61 |
-
"type": "function",
|
| 62 |
-
"function": {
|
| 63 |
-
"name": "list_statistics_countries",
|
| 64 |
-
"description": "List countries available in Statistics of the World.",
|
| 65 |
-
"parameters": {"type": "object", "properties": {}},
|
| 66 |
-
},
|
| 67 |
-
},
|
| 68 |
-
{
|
| 69 |
-
"type": "function",
|
| 70 |
-
"function": {
|
| 71 |
-
"name": "list_statistics_indicators",
|
| 72 |
-
"description": "List indicators available in Statistics of the World.",
|
| 73 |
-
"parameters": {"type": "object", "properties": {}},
|
| 74 |
-
},
|
| 75 |
-
},
|
| 76 |
-
{
|
| 77 |
-
"type": "function",
|
| 78 |
-
"function": {
|
| 79 |
-
"name": "list_econdb_sources",
|
| 80 |
-
"description": "List Econdb data sources, optionally by page.",
|
| 81 |
-
"parameters": {
|
| 82 |
-
"type": "object",
|
| 83 |
-
"properties": {
|
| 84 |
-
"page": {
|
| 85 |
-
"type": "integer",
|
| 86 |
-
"description": "Optional result page number.",
|
| 87 |
-
},
|
| 88 |
-
},
|
| 89 |
-
},
|
| 90 |
-
},
|
| 91 |
-
},
|
| 92 |
-
{
|
| 93 |
-
"type": "function",
|
| 94 |
-
"function": {
|
| 95 |
-
"name": "list_econdb_datasets",
|
| 96 |
-
"description": "List Econdb datasets, optionally by page.",
|
| 97 |
-
"parameters": {
|
| 98 |
-
"type": "object",
|
| 99 |
-
"properties": {
|
| 100 |
-
"page": {
|
| 101 |
-
"type": "integer",
|
| 102 |
-
"description": "Optional result page number.",
|
| 103 |
-
},
|
| 104 |
-
},
|
| 105 |
-
},
|
| 106 |
-
},
|
| 107 |
-
},
|
| 108 |
-
{
|
| 109 |
-
"type": "function",
|
| 110 |
-
"function": {
|
| 111 |
-
"name": "list_econdb_series",
|
| 112 |
-
"description": (
|
| 113 |
-
"List Econdb series, optionally by page. Requires ECONDB_API_TOKEN "
|
| 114 |
-
"to be configured."
|
| 115 |
-
),
|
| 116 |
-
"parameters": {
|
| 117 |
-
"type": "object",
|
| 118 |
-
"properties": {
|
| 119 |
-
"page": {
|
| 120 |
-
"type": "integer",
|
| 121 |
-
"description": "Optional result page number.",
|
| 122 |
-
},
|
| 123 |
-
},
|
| 124 |
-
},
|
| 125 |
-
},
|
| 126 |
-
},
|
| 127 |
{
|
| 128 |
"type": "function",
|
| 129 |
"function": {
|
|
@@ -168,63 +77,4 @@ TOOLS: list[dict[str, Any]] = [
|
|
| 168 |
},
|
| 169 |
},
|
| 170 |
},
|
| 171 |
-
{
|
| 172 |
-
"type": "function",
|
| 173 |
-
"function": {
|
| 174 |
-
"name": "get_passport_index_requirement",
|
| 175 |
-
"description": (
|
| 176 |
-
"Look up a visa requirement from the Passport Index CSV dataset. "
|
| 177 |
-
"Use ISO-2 country codes."
|
| 178 |
-
),
|
| 179 |
-
"parameters": {
|
| 180 |
-
"type": "object",
|
| 181 |
-
"properties": {
|
| 182 |
-
"passport_iso2": {
|
| 183 |
-
"type": "string",
|
| 184 |
-
"description": "Passport issuing country ISO-2 code.",
|
| 185 |
-
},
|
| 186 |
-
"destination_iso2": {
|
| 187 |
-
"type": "string",
|
| 188 |
-
"description": "Destination country ISO-2 code.",
|
| 189 |
-
},
|
| 190 |
-
},
|
| 191 |
-
"required": ["passport_iso2", "destination_iso2"],
|
| 192 |
-
},
|
| 193 |
-
},
|
| 194 |
-
},
|
| 195 |
-
{
|
| 196 |
-
"type": "function",
|
| 197 |
-
"function": {
|
| 198 |
-
"name": "get_passport_index_matrix_requirement",
|
| 199 |
-
"description": (
|
| 200 |
-
"Look up a visa requirement from the Passport Index matrix dataset. "
|
| 201 |
-
"Use ISO-2 country codes."
|
| 202 |
-
),
|
| 203 |
-
"parameters": {
|
| 204 |
-
"type": "object",
|
| 205 |
-
"properties": {
|
| 206 |
-
"passport_iso2": {
|
| 207 |
-
"type": "string",
|
| 208 |
-
"description": "Passport issuing country ISO-2 code.",
|
| 209 |
-
},
|
| 210 |
-
"destination_iso2": {
|
| 211 |
-
"type": "string",
|
| 212 |
-
"description": "Destination country ISO-2 code.",
|
| 213 |
-
},
|
| 214 |
-
},
|
| 215 |
-
"required": ["passport_iso2", "destination_iso2"],
|
| 216 |
-
},
|
| 217 |
-
},
|
| 218 |
-
},
|
| 219 |
-
{
|
| 220 |
-
"type": "function",
|
| 221 |
-
"function": {
|
| 222 |
-
"name": "get_visadb_questions",
|
| 223 |
-
"description": (
|
| 224 |
-
"Fetch VisaDB question bank questions. Requires VISADB_API_KEY to "
|
| 225 |
-
"be configured."
|
| 226 |
-
),
|
| 227 |
-
"parameters": {"type": "object", "properties": {}},
|
| 228 |
-
},
|
| 229 |
-
},
|
| 230 |
]
|
|
|
|
| 33 |
},
|
| 34 |
},
|
| 35 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
{
|
| 37 |
"type": "function",
|
| 38 |
"function": {
|
|
|
|
| 77 |
},
|
| 78 |
},
|
| 79 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
]
|
ui/inference/tools.py
CHANGED
|
@@ -7,18 +7,7 @@ from typing import Any
|
|
| 7 |
|
| 8 |
from gradio import ChatMessage
|
| 9 |
|
| 10 |
-
from apis.econdb import list_datasets, list_series, list_sources
|
| 11 |
-
from apis.passport_index import (
|
| 12 |
-
get_visa_requirement as get_passport_index_requirement,
|
| 13 |
-
get_visa_requirement_matrix,
|
| 14 |
-
)
|
| 15 |
from apis.passport_visa import passport_stats, visa_requirement
|
| 16 |
-
from apis.statistics_of_the_world import (
|
| 17 |
-
get_history,
|
| 18 |
-
list_countries,
|
| 19 |
-
list_indicators,
|
| 20 |
-
)
|
| 21 |
-
from apis.visadb import get_questions
|
| 22 |
from apis.world_bank import get_indicator_series
|
| 23 |
|
| 24 |
from .messages import assistant_message_dict
|
|
@@ -45,21 +34,6 @@ def _run_tool(name: str, args: dict[str, Any]) -> Any:
|
|
| 45 |
indicator=args["indicator"],
|
| 46 |
country=args["country"],
|
| 47 |
)
|
| 48 |
-
if name == "get_statistics_history":
|
| 49 |
-
return get_history(
|
| 50 |
-
indicator=args["indicator"],
|
| 51 |
-
country=args["country"],
|
| 52 |
-
)
|
| 53 |
-
if name == "list_statistics_countries":
|
| 54 |
-
return list_countries()
|
| 55 |
-
if name == "list_statistics_indicators":
|
| 56 |
-
return list_indicators()
|
| 57 |
-
if name == "list_econdb_sources":
|
| 58 |
-
return list_sources(page=args.get("page"))
|
| 59 |
-
if name == "list_econdb_datasets":
|
| 60 |
-
return list_datasets(page=args.get("page"))
|
| 61 |
-
if name == "list_econdb_series":
|
| 62 |
-
return list_series(page=args.get("page"))
|
| 63 |
if name == "get_visa_requirement":
|
| 64 |
return visa_requirement(
|
| 65 |
passport_iso2=args["passport_iso2"],
|
|
@@ -67,22 +41,6 @@ def _run_tool(name: str, args: dict[str, Any]) -> Any:
|
|
| 67 |
)
|
| 68 |
if name == "get_passport_stats":
|
| 69 |
return passport_stats(passport_iso2=args["passport_iso2"])
|
| 70 |
-
if name == "get_passport_index_requirement":
|
| 71 |
-
return {
|
| 72 |
-
"requirement": get_passport_index_requirement(
|
| 73 |
-
passport_iso2=args["passport_iso2"],
|
| 74 |
-
destination_iso2=args["destination_iso2"],
|
| 75 |
-
)
|
| 76 |
-
}
|
| 77 |
-
if name == "get_passport_index_matrix_requirement":
|
| 78 |
-
return {
|
| 79 |
-
"requirement": get_visa_requirement_matrix(
|
| 80 |
-
passport_iso2=args["passport_iso2"],
|
| 81 |
-
destination_iso2=args["destination_iso2"],
|
| 82 |
-
)
|
| 83 |
-
}
|
| 84 |
-
if name == "get_visadb_questions":
|
| 85 |
-
return get_questions()
|
| 86 |
|
| 87 |
return {"error": f"Unknown tool: {name}"}
|
| 88 |
|
|
|
|
| 7 |
|
| 8 |
from gradio import ChatMessage
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
from apis.passport_visa import passport_stats, visa_requirement
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
from apis.world_bank import get_indicator_series
|
| 12 |
|
| 13 |
from .messages import assistant_message_dict
|
|
|
|
| 34 |
indicator=args["indicator"],
|
| 35 |
country=args["country"],
|
| 36 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if name == "get_visa_requirement":
|
| 38 |
return visa_requirement(
|
| 39 |
passport_iso2=args["passport_iso2"],
|
|
|
|
| 41 |
)
|
| 42 |
if name == "get_passport_stats":
|
| 43 |
return passport_stats(passport_iso2=args["passport_iso2"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
return {"error": f"Unknown tool: {name}"}
|
| 46 |
|