Skip to content

Commit 7753f34

Browse files
run linters
1 parent 7f091ac commit 7753f34

File tree

10 files changed

+26
-72
lines changed

10 files changed

+26
-72
lines changed

python/rag/healthcare-support-portal/packages/auth/src/auth_service/routers/auth.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ async def register(
6666
detail="Only administrators can create new users. Use POST /api/v1/users/ endpoint instead.",
6767
)
6868
# Check if user already exists
69-
existing_user = (
70-
db.query(User).filter((User.username == user_data.username) | (User.email == user_data.email)).first()
71-
)
69+
existing_user = db.query(User).filter((User.username == user_data.username) | (User.email == user_data.email)).first()
7270

7371
if existing_user:
7472
raise HTTPException(

python/rag/healthcare-support-portal/packages/auth/src/auth_service/routers/users.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ async def create_user(
130130
)
131131

132132
# Check if user already exists
133-
existing_user = (
134-
db.query(User).filter((User.username == user_data.username) | (User.email == user_data.email)).first()
135-
)
133+
existing_user = db.query(User).filter((User.username == user_data.username) | (User.email == user_data.email)).first()
136134

137135
if existing_user:
138136
raise HTTPException(

python/rag/healthcare-support-portal/packages/common/src/common/migration_check.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ def get_alembic_config() -> Config:
2020
alembic_ini = common_dir / "alembic.ini"
2121

2222
if not alembic_ini.exists():
23-
raise FileNotFoundError(
24-
f"alembic.ini not found at {alembic_ini}. " "Please ensure Alembic is properly initialized."
25-
)
23+
raise FileNotFoundError(f"alembic.ini not found at {alembic_ini}. " "Please ensure Alembic is properly initialized.")
2624

2725
config = Config(str(alembic_ini))
2826

python/rag/healthcare-support-portal/packages/common/src/common/seed_data.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,9 @@ def seed_patients(db: Session, users: dict[str, User], admin_token: str) -> list
197197

198198
for patient_data in demo_patients:
199199
# Check if patient already exists
200-
existing_patient = (
201-
db.query(Patient).filter(Patient.medical_record_number == patient_data["medical_record_number"]).first()
202-
)
200+
existing_patient = db.query(Patient).filter(Patient.medical_record_number == patient_data["medical_record_number"]).first()
203201
if existing_patient:
204-
print(
205-
f"✅ Patient '{patient_data['name']}' (MRN: {patient_data['medical_record_number']}) already exists, skipping"
206-
)
202+
print(f"✅ Patient '{patient_data['name']}' (MRN: {patient_data['medical_record_number']}) already exists, skipping")
207203
created_patients.append(existing_patient)
208204

209205
# Sync OSO facts for existing patients (in case they weren't synced before)
@@ -233,9 +229,7 @@ def seed_patients(db: Session, users: dict[str, User], admin_token: str) -> list
233229
# Get patient from database
234230
new_patient = db.query(Patient).filter(Patient.id == patient_response["id"]).first()
235231
created_patients.append(new_patient)
236-
print(
237-
f"✅ Created patient via API (with OSO facts): {patient_data['name']} (MRN: {patient_data['medical_record_number']})"
238-
)
232+
print(f"✅ Created patient via API (with OSO facts): {patient_data['name']} (MRN: {patient_data['medical_record_number']})")
239233
else:
240234
print(f"⚠️ Failed to create patient {patient_data['name']}: {response.text}")
241235

python/rag/healthcare-support-portal/packages/patient/src/patient_service/routers/patients.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ async def create_patient(
8181
Create a new patient
8282
"""
8383
# Check if medical record number already exists
84-
existing_patient = (
85-
db.query(Patient).filter(Patient.medical_record_number == patient_data.medical_record_number).first()
86-
)
84+
existing_patient = db.query(Patient).filter(Patient.medical_record_number == patient_data.medical_record_number).first()
8785

8886
if existing_patient:
8987
raise HTTPException(

python/rag/healthcare-support-portal/packages/rag/src/rag_service/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ async def startup_event():
6464
# Verify database migrations are current
6565
require_migrations_current()
6666

67-
logger.info(
68-
f"🚀 {settings.app_name} started successfully", port=settings.port, galileo_enabled=settings.galileo_enabled
69-
)
67+
logger.info(f"🚀 {settings.app_name} started successfully", port=settings.port, galileo_enabled=settings.galileo_enabled)
7068

7169
except Exception as e:
7270
logger.error(f"Failed to start {settings.app_name}", error=str(e))

python/rag/healthcare-support-portal/packages/rag/src/rag_service/observability.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ async def rag_query_context(query_type: str, user_role: str, department: str = N
9090

9191
try:
9292
# Log query start
93-
logger.info(
94-
"RAG query started", query_type=query_type, user_role=user_role, department=department, query_id=query_id
95-
)
93+
logger.info("RAG query started", query_type=query_type, user_role=user_role, department=department, query_id=query_id)
9694

9795
# Start Galileo trace if enabled
9896
if galileo_enabled and galileo_logger:
@@ -193,9 +191,7 @@ async def embedding_generation_context(model: str, chunk_count: int, operation_i
193191
yield operation_id
194192

195193
except Exception as e:
196-
logger.error(
197-
"Embedding generation failed", model=model, chunk_count=chunk_count, operation_id=operation_id, error=str(e)
198-
)
194+
logger.error("Embedding generation failed", model=model, chunk_count=chunk_count, operation_id=operation_id, error=str(e))
199195

200196
# Log error to Galileo
201197
log_galileo_event(
@@ -338,9 +334,7 @@ async def ai_response_context(model: str, token_count: int, response_id: str = N
338334
yield response_id
339335

340336
except Exception as e:
341-
logger.error(
342-
"AI response generation failed", model=model, token_count=token_count, response_id=response_id, error=str(e)
343-
)
337+
logger.error("AI response generation failed", model=model, token_count=token_count, response_id=response_id, error=str(e))
344338

345339
# Log error to Galileo
346340
log_galileo_event(

python/rag/healthcare-support-portal/packages/rag/src/rag_service/routers/chat.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ async def search_documents(
6161
"""
6262
settings = request.app.state.settings
6363

64-
async with rag_query_context(
65-
query_type="search", user_role=current_user.role, department=search_request.department
66-
) as query_id:
64+
async with rag_query_context(query_type="search", user_role=current_user.role, department=search_request.department) as query_id:
6765

6866
# Get authorized documents query with OSO fallback
6967
try:
@@ -152,9 +150,7 @@ async def ask_question(
152150
"""
153151
settings = request.app.state.settings
154152

155-
async with rag_query_context(
156-
query_type="ask", user_role=current_user.role, department=chat_request.context_department
157-
) as query_id:
153+
async with rag_query_context(query_type="ask", user_role=current_user.role, department=chat_request.context_department) as query_id:
158154

159155
# Get authorized documents for context with OSO fallback
160156
try:
@@ -358,7 +354,9 @@ async def generate_ai_response(question: str, context_results: list[dict], user_
358354

359355
# Add disclaimer if no context was used
360356
if not context:
361-
ai_response += "\n\n*Note: This response was generated without specific document context. Please verify information with current medical guidelines.*"
357+
ai_response += (
358+
"\n\n*Note: This response was generated without specific document context. Please verify information with current medical guidelines.*"
359+
)
362360

363361
return ai_response
364362

python/rag/healthcare-support-portal/packages/rag/src/rag_service/routers/documents.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ async def list_documents(
5959
try:
6060
query = db.query(Document).options(authorized(current_user, "read", Document))
6161
except Exception as oso_error:
62-
logger.warning(
63-
"OSO authorization failed, falling back to basic query", error=str(oso_error), user_role=current_user.role
64-
)
62+
logger.warning("OSO authorization failed, falling back to basic query", error=str(oso_error), user_role=current_user.role)
6563
# In development, fallback to showing documents based on role/department
6664
query = db.query(Document)
6765
if current_user.role != "admin":
@@ -169,9 +167,7 @@ async def get_document(
169167
pass
170168
else:
171169
# Access denied
172-
raise HTTPException(
173-
status_code=status.HTTP_403_FORBIDDEN, detail="Access denied - document not in your department"
174-
)
170+
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Access denied - document not in your department")
175171

176172
logger.info(
177173
"Document accessed",
@@ -296,9 +292,7 @@ async def upload_document(
296292
chunk_overlap=settings.chunk_overlap,
297293
)
298294

299-
async with embedding_generation_context(
300-
model=settings.embedding_model, chunk_count=len(chunks)
301-
) as operation_id:
295+
async with embedding_generation_context(model=settings.embedding_model, chunk_count=len(chunks)) as operation_id:
302296

303297
success = await store_document_embeddings(
304298
document=document,
@@ -354,9 +348,7 @@ async def upload_document(
354348
}
355349

356350
except Exception as e:
357-
logger.error(
358-
"Error processing uploaded document", document_id=document.id, user_role=current_user.role, error=str(e)
359-
)
351+
logger.error("Error processing uploaded document", document_id=document.id, user_role=current_user.role, error=str(e))
360352

361353
# Log error to Galileo
362354
log_galileo_event(
@@ -392,9 +384,7 @@ async def regenerate_embeddings(
392384
document = db.query(Document).filter(Document.id == document_id).first()
393385

394386
if not document:
395-
logger.warning(
396-
"Document not found for embedding regeneration", document_id=document_id, user_role=current_user.role
397-
)
387+
logger.warning("Document not found for embedding regeneration", document_id=document_id, user_role=current_user.role)
398388
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Document not found")
399389

400390
# Check authorization
@@ -418,9 +408,7 @@ async def regenerate_embeddings(
418408
chunk_overlap=settings.chunk_overlap,
419409
)
420410

421-
async with embedding_generation_context(
422-
model=settings.embedding_model, chunk_count=len(chunks)
423-
) as operation_id:
411+
async with embedding_generation_context(model=settings.embedding_model, chunk_count=len(chunks)) as operation_id:
424412

425413
result = await regenerate_document_embeddings(
426414
document=document,
@@ -464,9 +452,7 @@ async def regenerate_embeddings(
464452
return result
465453

466454
except Exception as e:
467-
logger.error(
468-
"Error regenerating document embeddings", document_id=document_id, user_role=current_user.role, error=str(e)
469-
)
455+
logger.error("Error regenerating document embeddings", document_id=document_id, user_role=current_user.role, error=str(e))
470456

471457
# Log error to Galileo
472458
log_galileo_event(
@@ -503,9 +489,7 @@ async def delete_document(
503489
oso = get_oso()
504490
oso.authorize(current_user, "delete", document)
505491
except Exception as e:
506-
logger.warning(
507-
"Unauthorized document deletion attempt", document_id=document_id, user_role=current_user.role, error=str(e)
508-
)
492+
logger.warning("Unauthorized document deletion attempt", document_id=document_id, user_role=current_user.role, error=str(e))
509493
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Access denied")
510494

511495
# Remove Oso facts

python/rag/healthcare-support-portal/packages/rag/src/rag_service/utils/embeddings.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ async def similarity_search(
160160
formatted_results.append(
161161
{
162162
"document_title": result["title"],
163-
"content_chunk": (
164-
result["content_chunk"][:200] + "..."
165-
if len(result["content_chunk"]) > 200
166-
else result["content_chunk"]
167-
),
163+
"content_chunk": (result["content_chunk"][:200] + "..." if len(result["content_chunk"]) > 200 else result["content_chunk"]),
168164
"similarity_score": result["similarity_score"],
169165
"document_type": result["document_type"],
170166
"department": result["department"],
@@ -182,9 +178,7 @@ async def similarity_search(
182178
return []
183179

184180

185-
async def regenerate_document_embeddings(
186-
document: Document, db: Session, model: str = "text-embedding-3-small"
187-
) -> dict:
181+
async def regenerate_document_embeddings(document: Document, db: Session, model: str = "text-embedding-3-small") -> dict:
188182
"""
189183
Regenerate embeddings for an existing document.
190184
Returns status dict with success and message.

0 commit comments

Comments
 (0)