feat: 문서 챗봇 기능와 맥락설명을 위한 프롬프팅 - #49
Conversation
|
Warning Review limit reached
Next review available in: 26 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthrough문서 챗봇용 요청 스키마, 문서 기반 프롬프트, 누락 문서 오류 처리를 추가했습니다. 문화 가이드 FAQ 선택을 위한 스키마·프롬프트·서비스·OpenAI 어댑터·POST 엔드포인트도 추가했습니다. Changes문서 챗봇
문화 가이드 FAQ 선택
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)문서 채팅 오류 처리sequenceDiagram
participant Client
participant send_message
participant chat
Client->>send_message: 문서 채팅 요청
send_message->>chat: chat(request)
chat-->>send_message: 문서 본문 누락 오류
send_message-->>Client: 400 Bad Request
문화 가이드 FAQ 선택sequenceDiagram
participant Client
participant cultural_guides
participant select_cultural_guides
participant OpenAINewsletterAdapter
Client->>cultural_guides: POST /ai/newsletters/cultural-guides
cultural_guides->>select_cultural_guides: CulturalGuideRequest
select_cultural_guides->>OpenAINewsletterAdapter: FAQ 선택 요청
OpenAINewsletterAdapter-->>select_cultural_guides: CulturalGuideResponse
select_cultural_guides-->>Client: 정제된 selectedFaqs
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/services/chat_service.py (1)
17-29: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win문서 입력을 OpenAI 설정보다 먼저 검증하세요.
현재 OpenAI가 비활성화됐거나 키가 없으면 공백
document.originalText요청도 400이 아닌 503으로 끝납니다.DOCUMENT요청의 본문 검증을 함수 첫 부분으로 옮겨 잘못된 클라이언트 입력이 항상 400으로 매핑되게 하세요.🤖 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 `@app/services/chat_service.py` around lines 17 - 29, In the chat service validation flow, move the ChatType.DOCUMENT check for missing or blank request.document.original_text before retrieving or validating OpenAI settings. Preserve the existing ChatDocumentMissingError so invalid document requests map to 400 regardless of OpenAI availability, while leaving settings validation unchanged for valid requests.
🤖 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 `@app/routers/newsletters.py`:
- Around line 68-81: Update the /cultural-guides endpoint and
CulturalGuideResponse so the public DTO exposes only the selected FAQ IDs and
never serializes SelectedCulturalGuide.relevanceReason. Keep relevanceReason
available only in the internal selection result for logging or quality checks,
and map the result to the new FAQ-ID-only response schema before returning it
from cultural_guides.
In `@app/schemas.py`:
- Line 147: Update the schema field original_text in the relevant document model
to allow a missing or null originalText value, so DOCUMENT requests reach the
service-level ChatDocumentMissingError and retain the existing 400 response
mapping; keep non-document validation behavior unchanged.
In `@app/services/chat_prompt.py`:
- Around line 80-90: Update _build_document_system_prompt so it contains only
trusted static instructions and explicitly treats document content as untrusted
data, not executable instructions. Move document_block out of the system prompt
and pass it through a separate user/reference message while preserving the
required language and document-chat behavior.
- Around line 135-141: Update the prompt construction around the document block
to enforce length limits on document.title and document.summary, not just
original_text. Apply the schema-input limits for each metadata field and cap the
complete assembled document block at 6,000 characters before adding it to the
system prompt, preserving the existing formatting and trimming behavior for
valid content.
- Around line 87-90: Update the prompt templates in the document-description
sections near the Korean and alternate-language blocks to state that the content
may be a truncated excerpt, not the entire original document. Explicitly
instruct the model to distinguish information absent from the provided excerpt
from information absent in the original document, and include whether truncation
occurred using the existing document-length/truncation context.
In `@app/services/cultural_guide_prompt.py`:
- Around line 82-109: Update the request schema for CulturalGuideRequest to
enforce maximum limits on original_text length and FAQ candidate count, and
limit each candidate’s category and question length. Reject inputs exceeding
these contract limits with validation errors mapped to HTTP 422, while
preserving the existing _build_user_prompt and _format_faq_candidates behavior
for valid requests.
In `@app/services/openai_adapter.py`:
- Around line 164-175: Update the payload constructed in
select_cultural_guides() to explicitly set the Responses API store option to
False, preserving the existing model, input, and response-format fields.
---
Outside diff comments:
In `@app/services/chat_service.py`:
- Around line 17-29: In the chat service validation flow, move the
ChatType.DOCUMENT check for missing or blank request.document.original_text
before retrieving or validating OpenAI settings. Preserve the existing
ChatDocumentMissingError so invalid document requests map to 400 regardless of
OpenAI availability, while leaving settings validation unchanged for valid
requests.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b578f2d6-3da6-44ff-818f-43a38581fd2f
📒 Files selected for processing (8)
app/routers/chat.pyapp/routers/newsletters.pyapp/schemas.pyapp/services/chat_prompt.pyapp/services/chat_service.pyapp/services/cultural_guide_prompt.pyapp/services/cultural_guide_service.pyapp/services/openai_adapter.py
📌 작업 요약
🌿 브랜치 정보
feat/#48-document-chatdevelop(기본) /main(릴리즈, 핫픽스)✅ 체크리스트
feat/refac/hotfix/chore/design/bugfix)feat/fix/refactor/docs/style/chore)🧪 테스트 결과
Summary by CodeRabbit
새로운 기능
버그 수정