Skip to content

Conversation

@arpita-josh02
Copy link
Contributor

@arpita-josh02 arpita-josh02 commented Oct 17, 2025

-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.

@sethu sethu requested a review from Copilot October 27, 2025 08:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-langflow endpoint 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.

Comment on lines +27 to +53
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)

Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
db_port = os.getenv("DB_PORT")
db_name = os.getenv("DB_NAME")

sarvam_api_key = os.getenv("SARVAM_API_KEY","sk_t7fvsjjb_7JsD5ZXGrEhHqjUtAQSFsCxB")
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
sarvam_api_key = os.getenv("SARVAM_API_KEY","sk_t7fvsjjb_7JsD5ZXGrEhHqjUtAQSFsCxB")
sarvam_api_key = os.getenv("SARVAM_API_KEY")

Copilot uses AI. Check for mistakes.
# 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")
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
langflow_api_key = os.getenv("LANGFLOW_API_KEY", "sk-SCQyDlsYB7qPzmzL3yivQs-J5JmvX82uHVbDiGWrQR8")
langflow_api_key = os.getenv("LANGFLOW_API_KEY")

Copilot uses AI. Check for mistakes.
Comment on lines +277 to +283
# # 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."}
# )
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# # 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."}
)

Copilot uses AI. Check for mistakes.
if len(matches) > 1:
# Multiple partial matches - return formatted list
beneficiary_list = format_beneficiaries(matches)
return HTTPException(
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should raise the HTTPException instead of returning it. Change return HTTPException(...) to raise HTTPException(...).

Suggested change
return HTTPException(
raise HTTPException(

Copilot uses AI. Check for mistakes.
status_code=status.HTTP_400_BAD_REQUEST,
detail="To transfer money, please provide either a customer ID or a registered phone number."
)
print(request)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be replaced with proper logging using the logger. Change to logger.debug(f\"Payment request: {request}\").

Copilot uses AI. Check for mistakes.
for b in beneficiaries
]

return{"beneficiaries": beneficiaries}
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response format is inconsistent with other v2 endpoints which return {\"status\": \"success\", \"message\": \"...\", \"data\": {...}}. Update to match the standard v2 response structure for consistency.

Suggested change
return{"beneficiaries": beneficiaries}
return {
"status": "success",
"message": "Beneficiaries retrieved successfully.",
"data": {"beneficiaries": beneficiaries}
}

Copilot uses AI. Check for mistakes.

logger.info(f"Calling Langflow API at {url}")
# Make the API call
async with httpx.AsyncClient(timeout=langflow_timeout) as client:
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants