Conversation
…into feature/banking_api's
…into feature/banking_api's
…into feature/banking_api's
…into feature/banking_api's
…into feature/banking_api's
…into feature/banking_api's
…into feature/banking_api's
…into feature/banking_api's
…into feature/banking_api's
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces version 2 of the banking API with enhanced response structures and adds a new Langflow integration endpoint for processing voice inputs. The changes include improved beneficiary search with normalization, restructured API responses with status/message/data fields, and a new async HTTP client lifecycle management for external API calls.
Key changes:
- New
/voice/process-with-langflowendpoint that transcribes audio and processes it through Langflow for intent detection - V2 banking routes with improved error messages, beneficiary matching, and standardized response format
- Langflow API configuration and integration utilities
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| service/main.py | Adds Langflow integration endpoint with audio processing, async HTTP client lifecycle management, and switches to v2 banking routes |
| service/config.py | Duplicates configuration variables and adds Langflow API settings including hardcoded API keys |
| service/banking/core_banking_routes_v2.py | Implements v2 banking API with improved beneficiary search, normalized text matching, and structured JSON responses |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import os | ||
| from dotenv import load_dotenv | ||
|
|
||
| load_dotenv() | ||
|
|
||
| openai_api_key = os.getenv("OPENAI_API_KEY") | ||
| #model_id = os.getenv('MODEL_ID', 'large-v3') | ||
| model_id = os.getenv('MODEL_ID','small') | ||
| model_path = os.getenv('MODEL_PATH', './models') | ||
| ollama_host = os.getenv("OLLAMA_HOST", "http://ollama:11434") | ||
| ollama_model_name = os.getenv("OLLAMA_MODEL_NAME", "llama3.2") | ||
| open_ai_model_name = os.getenv("OPENAI_MODEL_NAME", "gpt-4") | ||
| ollama_translation_model_name = os.getenv("OLLAMA_TRANS_MODEL","gemma2:latest") | ||
| open_ai_temperature = os.getenv("OPENAI_TEMPERATURE", 0.2) | ||
| db_user = os.getenv("DB_USER") | ||
| db_password = os.getenv("DB_PASSWORD") | ||
| db_host = os.getenv("DB_HOST") | ||
| db_port = os.getenv("DB_PORT") | ||
| db_name = os.getenv("DB_NAME") | ||
|
|
||
| sarvam_api_key = os.getenv("SARVAM_API_KEY","sk_t7fvsjjb_7JsD5ZXGrEhHqjUtAQSFsCxB") | ||
| # Redis configuration | ||
| redis_host = os.getenv("REDIS_HOST", "localhost") | ||
| redis_port = int(os.getenv("REDIS_PORT", 6379)) | ||
| redis_db = int(os.getenv("REDIS_DB", 0)) | ||
| redis_password = os.getenv("REDIS_PASSWORD", None) | ||
|
|
There was a problem hiding this comment.
The configuration variables from lines 27-52 are duplicating those already defined at lines 1-26, creating code duplication. Remove this duplicate block to avoid inconsistencies and maintenance issues.
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| openai_api_key = os.getenv("OPENAI_API_KEY") | |
| #model_id = os.getenv('MODEL_ID', 'large-v3') | |
| model_id = os.getenv('MODEL_ID','small') | |
| model_path = os.getenv('MODEL_PATH', './models') | |
| ollama_host = os.getenv("OLLAMA_HOST", "http://ollama:11434") | |
| ollama_model_name = os.getenv("OLLAMA_MODEL_NAME", "llama3.2") | |
| open_ai_model_name = os.getenv("OPENAI_MODEL_NAME", "gpt-4") | |
| ollama_translation_model_name = os.getenv("OLLAMA_TRANS_MODEL","gemma2:latest") | |
| open_ai_temperature = os.getenv("OPENAI_TEMPERATURE", 0.2) | |
| db_user = os.getenv("DB_USER") | |
| db_password = os.getenv("DB_PASSWORD") | |
| db_host = os.getenv("DB_HOST") | |
| db_port = os.getenv("DB_PORT") | |
| db_name = os.getenv("DB_NAME") | |
| sarvam_api_key = os.getenv("SARVAM_API_KEY","sk_t7fvsjjb_7JsD5ZXGrEhHqjUtAQSFsCxB") | |
| # Redis configuration | |
| redis_host = os.getenv("REDIS_HOST", "localhost") | |
| redis_port = int(os.getenv("REDIS_PORT", 6379)) | |
| redis_db = int(os.getenv("REDIS_DB", 0)) | |
| redis_password = os.getenv("REDIS_PASSWORD", None) |
| db_port = os.getenv("DB_PORT") | ||
| db_name = os.getenv("DB_NAME") | ||
|
|
||
| sarvam_api_key = os.getenv("SARVAM_API_KEY","sk_t7fvsjjb_7JsD5ZXGrEhHqjUtAQSFsCxB") |
There was a problem hiding this comment.
Hardcoded API key in default value exposes sensitive credentials in source code. Remove the default value and require this key to be set via environment variables only.
| sarvam_api_key = os.getenv("SARVAM_API_KEY","sk_t7fvsjjb_7JsD5ZXGrEhHqjUtAQSFsCxB") | |
| sarvam_api_key = os.getenv("SARVAM_API_KEY") |
| # Langflow API configuration | ||
| langflow_api_url = os.getenv("LANGFLOW_API_URL", "http://localhost:7860") | ||
| langflow_flow_id = os.getenv("LANGFLOW_FLOW_ID", "df6ef421-30ef-4901-bc8b-270c2ce61d41") | ||
| langflow_api_key = os.getenv("LANGFLOW_API_KEY", "sk-SCQyDlsYB7qPzmzL3yivQs-J5JmvX82uHVbDiGWrQR8") |
There was a problem hiding this comment.
Hardcoded API key in default value exposes sensitive credentials in source code. Remove the default value and require this key to be set via environment variables only.
| langflow_api_key = os.getenv("LANGFLOW_API_KEY", "sk-SCQyDlsYB7qPzmzL3yivQs-J5JmvX82uHVbDiGWrQR8") | |
| langflow_api_key = os.getenv("LANGFLOW_API_KEY") |
| # # Verify request has required authentication | ||
| # server_api_key = langflow_api_key | ||
| # if server_api_key: | ||
| # return JSONResponse( | ||
| # status_code=401, | ||
| # content={"message": "Invalid API key. Please provide a valid API key to access this endpoint."} | ||
| # ) |
There was a problem hiding this comment.
Commented-out authentication check leaves endpoint unprotected. The logic at line 279 is also incorrect (would reject valid keys). Either implement proper authentication or remove this commented code.
| # # Verify request has required authentication | |
| # server_api_key = langflow_api_key | |
| # if server_api_key: | |
| # return JSONResponse( | |
| # status_code=401, | |
| # content={"message": "Invalid API key. Please provide a valid API key to access this endpoint."} | |
| # ) | |
| # Verify request has required authentication | |
| if langflow_api_key: | |
| if not api_key or api_key != langflow_api_key: | |
| return JSONResponse( | |
| status_code=401, | |
| content={"message": "Invalid API key. Please provide a valid API key to access this endpoint."} | |
| ) |
| if len(matches) > 1: | ||
| # Multiple partial matches - return formatted list | ||
| beneficiary_list = format_beneficiaries(matches) | ||
| return HTTPException( |
There was a problem hiding this comment.
Should raise the HTTPException instead of returning it. Change return HTTPException(...) to raise HTTPException(...).
| return HTTPException( | |
| raise HTTPException( |
| status_code=status.HTTP_400_BAD_REQUEST, | ||
| detail="To transfer money, please provide either a customer ID or a registered phone number." | ||
| ) | ||
| print(request) |
There was a problem hiding this comment.
Debug print statement should be replaced with proper logging using the logger. Change to logger.debug(f\"Payment request: {request}\").
| for b in beneficiaries | ||
| ] | ||
|
|
||
| return{"beneficiaries": beneficiaries} |
There was a problem hiding this comment.
Response format is inconsistent with other v2 endpoints which return {\"status\": \"success\", \"message\": \"...\", \"data\": {...}}. Update to match the standard v2 response structure for consistency.
| return{"beneficiaries": beneficiaries} | |
| return { | |
| "status": "success", | |
| "message": "Beneficiaries retrieved successfully.", | |
| "data": {"beneficiaries": beneficiaries} | |
| } |
|
|
||
| logger.info(f"Calling Langflow API at {url}") | ||
| # Make the API call | ||
| async with httpx.AsyncClient(timeout=langflow_timeout) as client: |
There was a problem hiding this comment.
Creating a new AsyncClient for each request is inefficient. Use the app.state.langflow_client created in the lifespan context manager instead: await app.state.langflow_client.post(...).
-added v2 api where modify response struture
Summary by Bito
This pull request introduces version 2 of the banking API, enhancing response structures and adding functionalities like improved beneficiary search, balance retrieval, and money transfer. It also includes new endpoints for detailed queries, better error handling, and updates to configuration management. Additionally, a new API endpoint for processing audio files has been added, featuring transcription and intent detection capabilities.