52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
from api.fetch_api_data import fetch_api_data
|
|
from api.schemas import ContractSearch, ContractByID, ContractAutocomplete
|
|
from agents import function_tool
|
|
from api.config import JUSTICE_API_BASE
|
|
|
|
class ContractsAPI:
|
|
|
|
@function_tool
|
|
async def contract(self, params: ContractSearch) -> dict:
|
|
"""
|
|
Fetch a list of contracts from the Justice API with optional filtering.
|
|
|
|
Args:
|
|
params (ContractSearch): Filtering and pagination parameters.
|
|
|
|
Returns:
|
|
dict: A dictionary containing a list of contracts and related metadata.
|
|
"""
|
|
url = f"{JUSTICE_API_BASE}/v1/zmluvy"
|
|
|
|
return await fetch_api_data(icon="📃", url=url, params=params.model_dump(exclude_none=True))
|
|
|
|
|
|
@function_tool
|
|
async def contract_id(self, params: ContractByID) -> dict:
|
|
"""
|
|
Fetch detailed information about a specific contract by its identifier.
|
|
|
|
Args:
|
|
params (ContractByID): Unique identifier of the contract.
|
|
|
|
Returns:
|
|
dict: Details of the specified contract.
|
|
"""
|
|
url = f"{JUSTICE_API_BASE}/v1/zmluvy/{params.idZmluvy}"
|
|
|
|
return await fetch_api_data(icon="📃", url=url, params={})
|
|
|
|
@function_tool
|
|
async def contract_autocomplete(self, params: ContractAutocomplete) -> dict:
|
|
"""
|
|
Fetch autocomplete suggestions for contract-related search terms.
|
|
|
|
Args:
|
|
params (ContractAutocomplete): Parameters for autocomplete query (e.g., partial text).
|
|
|
|
Returns:
|
|
dict: Suggested values matching the input query.
|
|
"""
|
|
url = f"{JUSTICE_API_BASE}/v1/zmluvy/autocomplete"
|
|
|
|
return await fetch_api_data(icon="📃", url=url, params=params.model_dump(exclude_none=True)) |