fix: 번역이 원활하게 작동되게 코드를 수정 - #37
Merged
Merged
Conversation
📝 Walkthrough개요번역 정제(Translation Refinement) 기능의 완전한 스택을 추가합니다. Papago의 1차 번역 결과를 OpenAI를 통해 자동으로 정제/다듬기하며, 한국어 고정 필드의 제약을 명확히 하고, 빈 필드/누락/공백 처리 및 예외 매핑을 포함합니다. 변경 사항번역 정제 기능
시퀀스 다이어그램sequenceDiagram
participant Client
participant RefineEndpoint
participant RefineService
participant OpenAIAdapter
participant OpenAI as OpenAI API
Client->>RefineEndpoint: POST /refine-translation
RefineEndpoint->>RefineService: refine_translation(request)
alt OpenAI disabled
RefineService->>RefineService: Use translated_text as-is
RefineService->>RefineEndpoint: TranslationRefineResponse
else OpenAI enabled
RefineService->>OpenAIAdapter: refine_translation(request)
OpenAIAdapter->>OpenAI: POST /responses with refine schema
OpenAI->>OpenAIAdapter: JSON response
OpenAIAdapter->>OpenAIAdapter: Extract and validate JSON
OpenAIAdapter->>RefineService: TranslationRefineResponse or error
RefineService->>RefineService: Match/validate field IDs
RefineService->>RefineEndpoint: TranslationRefineResponse
end
RefineEndpoint->>Client: 200 OK or 502/503 error
예상 코드 리뷰 노력🎯 3 (Moderate) | ⏱️ ~20 분 관련 PR
추천 라벨
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 4
🤖 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/schemas.py`:
- Around line 151-173: Add a non-empty string constraint to the translated_text
on RefineFieldInput and the text on RefineFieldOutput by specifying min_length=1
in their Field declarations (respecting the existing aliases like
koText/translatedText); update RefineFieldInput.translated_text to use
Field(..., alias="translatedText", min_length=1) and RefineFieldOutput.text to
use Field(..., min_length=1) so the Pydantic models enforce the same minLength:
1 requirement as REFINE_RESPONSE_SCHEMA.
In `@app/services/newsletter_extractor.py`:
- Around line 364-383: The variable requested_by_id is misleading and only used
to compute unknown_ids; replace it with a set of IDs (e.g., requested_ids =
{field.id for field in request.fields}) and use requested_ids when computing
unknown_ids, removing requested_by_id entirely; keep the rest of the logic that
iterates request.fields and uses refined_by_id unchanged so lookups and fallback
to field.translated_text still work.
In `@app/services/newsletter_prompt.py`:
- Around line 319-331: The function build_refine_prompt_messages currently types
fields as list[dict[str, str]] which is not type-safe; update the signature to
accept a well-defined TypedDict (e.g., RefineFieldDict with keys like "id",
"koText", "translatedText") or a pydantic/dataclass model (e.g.,
RefineFieldInput) and update any callers and _build_refine_user_prompt to use
that concrete type so key typos/missing keys are caught by the type checker;
ensure imports for TypedDict or the model are added and adjust any usages in
_build_refine_user_prompt and tests to access fields via the new typed
attributes/keys.
- Around line 358-376: The helper _build_refine_user_prompt uses defensive
field.get('koText', '') and field.get('translatedText', '') but fields are
produced from the RefineFieldInput Pydantic model so those keys always exist;
replace the .get(...) calls with direct indexing field['koText'] and
field['translatedText'] in _build_refine_user_prompt to make intent explicit and
let missing keys raise immediately (use the same concatenation/formatting logic
and keep building field_lines and sections unchanged).
🪄 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
Run ID: de5b8ccf-6921-4f78-ae2c-37d5af659136
📒 Files selected for processing (5)
app/routers/newsletters.pyapp/schemas.pyapp/services/newsletter_extractor.pyapp/services/newsletter_prompt.pyapp/services/openai_adapter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 작업 요약
🌿 브랜치 정보
fix/#36-translate-correctdevelop(기본)✅ 체크리스트
feat/refac/hotfix/chore/design/bugfix)feat/fix/refactor/docs/style/chore)Summary by CodeRabbit