Spaces:
Sleeping
Sleeping
| # api_callers.py (New file or integrated into your agent script) | |
| import requests | |
| import json | |
| import os | |
| # Assume your .NET API base URL is an environment variable or configured elsewhere | |
| DOTNET_API_BASE_URL = os.getenv("DOTNET_API_BASE_URL", "http://localhost:5030/api") # Example | |
| # If your API needs an API key for authentication: | |
| DOTNET_API_KEY = os.getenv("DOTNET_API_AUTH_KEY") | |
| def get_vaccination_statistics(wilaya: str) -> str: | |
| """ | |
| Fetches vaccination statistics for a specified Algerian Wilaya (province/state). | |
| For example, can provide vaccination coverage rates for different vaccines. | |
| Input must be the name of the Wilaya. | |
| """ | |
| print(f"--- API Tool: Fetching statistics for Wilaya: {wilaya} ---") | |
| try: | |
| headers = {} | |
| if DOTNET_API_KEY: | |
| headers["Authorization"] = f"Bearer {DOTNET_API_KEY}" # Or your API's auth scheme | |
| # Adjust endpoint and parameters as per your API design | |
| response = requests.get(f"{DOTNET_API_BASE_URL}/statistics/coverage", params={"wilaya": wilaya}, headers=headers) | |
| response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx) | |
| data = response.json() # Assuming your API returns JSON | |
| print(f" API Response (Statistics for {wilaya}): {data}") | |
| return json.dumps(data) # Return JSON string to the agent | |
| except requests.exceptions.RequestException as e: | |
| print(f" β Error calling statistics API for {wilaya}: {e}") | |
| return f"Error fetching statistics: {str(e)}" | |
| except json.JSONDecodeError: | |
| print(f" β Error decoding JSON response from statistics API for {wilaya}.") | |
| return "Error: Invalid JSON response from statistics API." | |
| def get_patient_vaccination_record(patient_id: str) -> str: | |
| """ | |
| Retrieves the vaccination record for a specific patient using their unique ID. | |
| Input must be the patient's unique identifier. | |
| """ | |
| print(f"--- API Tool: Fetching record for Patient ID: {patient_id} ---") | |
| try: | |
| headers = {} | |
| if DOTNET_API_KEY: | |
| headers["Authorization"] = f"Bearer {DOTNET_API_KEY}" | |
| # Adjust endpoint as per your API design | |
| response = requests.get(f"{DOTNET_API_BASE_URL}/doctors/vaccination-history/{patient_id}", headers=headers) | |
| response.raise_for_status() | |
| data = response.json() | |
| print(f" API Response (Record for patient {patient_id}): {data}") | |
| return json.dumps(data) | |
| except requests.exceptions.RequestException as e: | |
| # Handle specific errors like 404 for not found patient | |
| if e.response is not None and e.response.status_code == 404: | |
| print(f" Patient ID {patient_id} not found in API.") | |
| return f"Patient record not found for ID {patient_id}." | |
| print(f" β Error calling patient record API for {patient_id}: {e}") | |
| return f"Error fetching patient record: {str(e)}" | |
| except json.JSONDecodeError: | |
| print(f" β Error decoding JSON response from patient record API for {patient_id}.") | |
| return "Error: Invalid JSON response from patient record API." | |