{"id":28250744,"url":"https://github.com/largonarco/medint_b","last_synced_at":"2025-10-24T14:40:10.566Z","repository":{"id":285013296,"uuid":"955759804","full_name":"Largonarco/MedInt_B","owner":"Largonarco","description":"Backend for a Realtime Medical Interpreter","archived":false,"fork":false,"pushed_at":"2025-04-02T06:40:28.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-14T03:37:58.136Z","etag":null,"topics":["fastapi","openai-realtime-api","websockets"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Largonarco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-27T06:39:32.000Z","updated_at":"2025-04-12T23:55:14.000Z","dependencies_parsed_at":"2025-06-14T03:31:40.948Z","dependency_job_id":"deb9dd81-3304-45d3-9cad-28ea6e06f57a","html_url":"https://github.com/Largonarco/MedInt_B","commit_stats":null,"previous_names":["largonarco/sully_b","largonarco/medint_b"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Largonarco/MedInt_B","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Largonarco%2FMedInt_B","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Largonarco%2FMedInt_B/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Largonarco%2FMedInt_B/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Largonarco%2FMedInt_B/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Largonarco","download_url":"https://codeload.github.com/Largonarco/MedInt_B/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Largonarco%2FMedInt_B/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279096952,"owners_count":26102697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-15T02:00:07.814Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","openai-realtime-api","websockets"],"created_at":"2025-05-19T14:18:57.949Z","updated_at":"2025-10-15T17:43:44.663Z","avatar_url":"https://github.com/Largonarco.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MedInt API\n\nA FastAPI-based backend service designed to facilitate real-time communication between Spanish-speaking patients and English-speaking doctors. This API leverages OpenAI's Realtime API for speech-to-text translation and integrates tools for scheduling follow-up appointments and sending lab orders.\n\n## Features\n\n- **Real-Time Translation**: Translates audio input from Spanish (patient) to English (doctor) and vice versa using OpenAI's Realtime API.\n- **WebSocket Support**: Handles real-time bidirectional communication for audio and text streaming.\n- **Conversation History**: Maintains session-based conversation logs for doctors and patients.\n- **Action Tools**: Supports scheduling follow-up appointments and sending lab orders via configurable webhooks.\n- **Summary Generation**: Generates concise summaries of medical conversations on demand.\n- **CORS Enabled**: Allows cross-origin requests for flexible frontend integration.\n\n## Prerequisites\n\n- Python 3.9+\n- An OpenAI API key with access to the Realtime API (model: gpt-4o-realtime-preview-2024-10-01)\n- Optional: A webhook URL for testing tool actions (e.g., webhook.site)\n\n## Installation\n\n1. **Clone the Repository**\n\n```bash\ngit clone https://github.com/yourusername/medical-interpreter-api.git\ncd medical-interpreter-api\n```\n\n2. **Set Up a Virtual Environment**\n\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n```\n\n3. **Install Dependencies**\n\n```bash\npip install -r requirements.txt\n```\n\nNote: Create a requirements.txt file with the following dependencies:\n\n```\nfastapi==0.115.0\nuvicorn==0.31.0\nwebsocket-client==1.8.0\npython-dotenv==1.0.1\naiohttp==3.10.5\npydantic==2.9.2\n```\n\n4. **Configure Environment Variables**\n\nCreate a `.env` file in the root directory and add your OpenAI API key:\n\n```\nOPENAI_API_KEY=your-openai-api-key\nWEBHOOK_URL=https://webhook.site/your-webhook-id  # Optional, defaults to webhook.site\n```\n\n## Running the Application\n\n1. **Start the FastAPI Server**\n\n```bash\nuvicorn server:app --reload --host 0.0.0.0 --port 8000\n```\n\n- `--reload`: Enables auto-reloading during development.\n- The server will be accessible at http://localhost:8000.\n\n2. **Verify the Health Check**\n\nOpen a browser or use curl to check the root endpoint:\n\n```bash\ncurl http://localhost:8000/\n```\n\nExpected response:\n\n```json\n{ \"status\": \"online\", \"service\": \"Medical Interpreter API\" }\n```\n\n## Usage\n\n### WebSocket Endpoint\n\nConnect to the WebSocket endpoint at `ws://localhost:8000/ws` for real-time communication.\n\n### Message Types\n\n- **connect**: Establishes a connection to OpenAI's Realtime API.\n\n```json\n{ \"type\": \"connect\" }\n```\n\n- **begin_conversation**: Sends audio for translation.\n\n```json\n{ \"type\": \"begin_conversation\", \"audio\": \"\u003cbase64-encoded-audio\u003e\" }\n```\n\n- **get_summary**: Requests a summary of the conversation.\n\n```json\n{ \"type\": \"get_summary\" }\n```\n\n### Responses\n\n- **session**: Returns a unique session ID.\n\n```json\n{ \"type\": \"session\", \"session_id\": \"\u003cuuid\u003e\" }\n```\n\n- **openai_connected**: Confirms OpenAI connection.\n\n```json\n{ \"type\": \"openai_connected\" }\n```\n\n- **text_done**: Translated text response.\n\n```json\n{ \"type\": \"text_done\", \"text\": \"\u003ctranslated-text\u003e\" }\n```\n\n- **audio_response_delta**: Streaming audio chunk.\n\n```json\n{ \"type\": \"audio_response_delta\", \"delta\": \"\u003cbase64-audio-chunk\u003e\" }\n```\n\n- **response_done**: Final translated response with role.\n\n```json\n{ \"type\": \"response_done\", \"text\": \"\u003ctranslated-text\u003e\", \"role\": \"doctor|patient\" }\n```\n\n- **action_executed**: Tool action result.\n\n```json\n{\"type\": \"action_executed\", \"action\": \"schedule_follow_up\", \"details\": {...}}\n```\n\n- **error**: Error message.\n\n```json\n{ \"type\": \"error\", \"message\": \"\u003cerror-message\u003e\" }\n```\n\n### Example Workflow\n\n1. Connect to the WebSocket and receive a session_id.\n2. Send a connect message to initialize OpenAI.\n3. Send audio via begin_conversation for translation.\n4. Receive translated text and audio responses in real-time.\n5. Request a summary with get_summary when needed.\n\n### Tools\n\n- **schedule_follow_up**: Schedules a follow-up appointment.\n\n  - Parameters: patientName (str), date (YYYY-MM-DD), reason (str, optional).\n  - Trigger: Doctor says \"schedule followup appointment\".\n\n- **send_lab_order**: Sends a lab order.\n  - Parameters: patientName (str), testType (str), urgency (str: routine, urgent, stat, optional).\n  - Trigger: Doctor says \"send lab order\".\n\nResults are sent to the configured WEBHOOK_URL.\n\n## Project Structure\n\n```\nmedical-interpreter-api/\n├── server.py              # Main FastAPI application\n├── openai_realtime.py     # OpenAI Realtime API integration\n├── tools.py               # Tool execution logic\n├── models.py              # Pydantic models for requests/responses\n├── .env                   # Environment variables\n└── README.md              # This file\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flargonarco%2Fmedint_b","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flargonarco%2Fmedint_b","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flargonarco%2Fmedint_b/lists"}