Skip to content

Commit 0d19bc9

Browse files
committed
refactor: extract nested conditional expression into separate statements
Code quality improvement: - Extract nested ternary operator into clear if-elif-else structure - Improve readability of confidence level determination - Make order of operations explicit and easier to understand Before: nested ternary 'High' if > 0.8 else 'Medium' if > 0.6 else 'Low' After: clear if-elif-else statements with separate variable Benefits: - More readable and maintainable code - Easier to debug and modify - Clearer intent and logic flow
1 parent 2f40bb4 commit 0d19bc9

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/api/routers/reasoning.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ async def chat_with_reasoning(request: ReasoningRequest):
265265
)
266266

267267
# Generate enhanced response with reasoning
268+
# Determine confidence level (extracted from nested conditional for readability)
269+
if reasoning_chain.overall_confidence > 0.8:
270+
confidence_level = "High"
271+
elif reasoning_chain.overall_confidence > 0.6:
272+
confidence_level = "Medium"
273+
else:
274+
confidence_level = "Low"
275+
268276
enhanced_response = {
269277
"query": request.query,
270278
"reasoning_chain": {
@@ -278,11 +286,7 @@ async def chat_with_reasoning(request: ReasoningRequest):
278286
"insights": {
279287
"total_steps": len(reasoning_chain.steps),
280288
"reasoning_types_used": [rt.value for rt in reasoning_types],
281-
"confidence_level": (
282-
"High"
283-
if reasoning_chain.overall_confidence > 0.8
284-
else "Medium" if reasoning_chain.overall_confidence > 0.6 else "Low"
285-
),
289+
"confidence_level": confidence_level,
286290
},
287291
}
288292

0 commit comments

Comments
 (0)