fix(ai): 법률 RAG 답변 LLM 호출 연결 - #31
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesLive Legal LLM Integration
Sequence DiagramsequenceDiagram
participant Client
participant LLMClient
participant _generate_live
participant HTTPPost
participant LLMEndpoint as OpenAI /chat/completions
participant extract
Client->>LLMClient: generate_answer(state, Intent.LEGAL_CONSULT)
LLMClient->>_generate_live: state
alt Config present (base_url, model, api_key)
_generate_live->>HTTPPost: POST {base_url}/chat/completions<br/>Bearer auth, RAG prompt
HTTPPost->>LLMEndpoint: HTTP request with model/message
LLMEndpoint-->>HTTPPost: JSON choices[0].message
HTTPPost-->>_generate_live: Response
_generate_live->>extract: response payload
extract-->>_generate_live: text or None
_generate_live-->>LLMClient: text or None
else Missing config or HTTP error
_generate_live-->>LLMClient: None
end
alt Live result present
LLMClient-->>Client: text answer
else Fallback path
LLMClient->>LLMClient: generate_legal_answer(state)
LLMClient-->>Client: fallback answer
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
backend-ai/tests/test_legal_answer_generation.py (1)
121-138: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winAdd a malformed-payload regression test for extractor fallback
Current coverage validates text-part extraction but not malformed payload shapes. Add a non-dict payload case to lock in
Nonebehavior and prevent future fallback regressions.Suggested test addition
def test_extract_chat_completion_text_supports_text_parts() -> None: assert ( extract_chat_completion_text( { "choices": [ { "message": { "content": [ {"type": "text", "text": "첫 문장"}, {"type": "output_text", "text": "둘째 문장"}, ] } } ] } ) == "첫 문장\n둘째 문장" ) + + +def test_extract_chat_completion_text_returns_none_for_non_object_payload() -> None: + assert extract_chat_completion_text([]) is None🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend-ai/tests/test_legal_answer_generation.py` around lines 121 - 138, Add a regression test for malformed payload handling in the extract_chat_completion_text function to ensure the fallback behavior is locked in. Create a new test function (e.g., test_extract_chat_completion_text_handles_malformed_payload) that passes various malformed payload shapes to extract_chat_completion_text (such as non-dict payloads, missing required fields, or other invalid structures) and asserts that the function returns None gracefully to prevent future regressions in the extractor fallback logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend-ai/app/clients/llm_client.py`:
- Around line 92-95: The function `extract_chat_completion_text` calls `.get()`
on the `payload` parameter without first verifying it is a dictionary. Add a
guard clause at the beginning of the function to check if `payload` is an
instance of dict using `isinstance(payload, dict)`, and return None if it is
not, before attempting to call `.get("choices")` on it. This will prevent
`AttributeError` when the provider returns a non-dict JSON payload.
---
Nitpick comments:
In `@backend-ai/tests/test_legal_answer_generation.py`:
- Around line 121-138: Add a regression test for malformed payload handling in
the extract_chat_completion_text function to ensure the fallback behavior is
locked in. Create a new test function (e.g.,
test_extract_chat_completion_text_handles_malformed_payload) that passes various
malformed payload shapes to extract_chat_completion_text (such as non-dict
payloads, missing required fields, or other invalid structures) and asserts that
the function returns None gracefully to prevent future regressions in the
extractor fallback logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 65983b29-7586-4883-9735-c2e9f1c52e11
📒 Files selected for processing (4)
backend-ai/app/clients/llm_client.pybackend-ai/app/core/config.pybackend-ai/tests/conftest.pybackend-ai/tests/test_legal_answer_generation.py
변경 내용
원인
테스트
closes #30
Summary by CodeRabbit
llm_base_urlsetting (with environment override) for controlling the LLM API endpoint.