CoolFace
Apppublic

preview/medical-summarizer

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
apiService.js103 linesDownload Raw Back to services
1/**2 * API Service for Medical Multi-Agent System3 * Handles communication with backend Web API4 */5 6const API_BASE_URL = process.env.REACT_APP_API_URL || "https://0a986f11bced.ngrok-free.app";7 8class ApiService {9  constructor() {10    this.baseUrl = API_BASE_URL;11  }12 13  /**14   * Generic API call wrapper15   */16  async apiCall(endpoint, options = {}) {17    const url = `${this.baseUrl}${endpoint}`;18    const config = {19      headers: {20        "Content-Type": "application/json",21        "ngrok-skip-browser-warning": "true",22        ...options.headers,23      },24      ...options,25    };26 27    try {28      const response = await fetch(url, config);29 30      if (!response.ok) {31        const errorData = await response32          .json()33          .catch(() => ({ detail: "Unknown error" }));34        throw new Error(35          `API Error: ${response.status} - ${36            errorData.detail || response.statusText37          }`38        );39      }40 41      return await response.json();42    } catch (error) {43      console.error("API call failed:", error);44      throw error;45    }46  }47 48  /**49   * Health check50   */51  async healthCheck() {52    return this.apiCall("/api/health");53  }54 55  /**56   * Start new chat session57   */58  async startChat() {59    return this.apiCall("/api/chat/start", {60      method: "POST",61    });62  }63 64  /**65   * Send message to AI66   */67  async sendMessage(message) {68    return this.apiCall("/api/chat/send", {69      method: "POST",70      body: JSON.stringify({ message }),71    });72  }73 74  /**75   * Get current session status and patient record76   */77  async getSessionStatus() {78    return this.apiCall("/api/chat/status");79  }80 81  /**82   * Generate doctor summary83   */84  async generateSummary() {85    return this.apiCall("/api/chat/summary", {86      method: "POST",87    });88  }89 90  /**91   * Reset current session92   */93  async resetSession() {94    return this.apiCall("/api/chat/reset", {95      method: "DELETE",96    });97  }98}99 100// Export singleton instance101export const apiService = new ApiService();102export default apiService;103