feat: OpenAI 호출 어댑터 추가#6
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough이 PR은 AI 서버에 선택적 OpenAI API 호출 기능을 추가합니다. 환경변수로 활성화 여부를 제어하며, 활성화 시 OpenAI Responses API를 호출하고, 비활성화 시 기존 규칙 기반 분석을 수행합니다. 예외 처리 및 설정 검증도 함께 구현됩니다. ChangesOpenAI 통합 및 조건부 실행
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 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/config.py`:
- Around line 12-19: The _read_float function allows non-positive values (<= 0)
to pass through which can cause runtime errors for settings like
OPENAI_TIMEOUT_SECONDS; update _read_float (and any callers that read
OPENAI_TIMEOUT_SECONDS) to validate the parsed float and if it is <= 0 return
the provided default (or clamp to a sensible minimum) instead of returning the
invalid value—specifically, after converting value = float(value) in _read_float
check if value <= 0 and if so return default; apply the same non-positive check
where OPENAI_TIMEOUT_SECONDS is consumed so bad config falls back to the
default.
- Around line 34-36: 환경 변수가 공백 문자열로 들어오는 경우를 막기 위해 os.getenv("OPENAI_API_KEY")
등에서 반환된 값을 strip()으로 정규화하고, strip 결과가 빈 문자열이면 None(또는 기본값)으로 대체하도록 변경하세요; 구체적으로
app/config.py의 api_key, model, base_url 할당부에서 OPENAI_API_KEY, OPENAI_MODEL,
OPENAI_BASE_URL 값을 각각 가져온 뒤 .strip()으로 공백을 제거하고 빈 문자열이면 None 또는 기존
기본("gpt-4o-mini" / "https://api.openai.com/v1")을 사용하도록 처리하면 됩니다.
In `@app/services/openai_adapter.py`:
- Around line 70-75: The current log call in openai_adapter.py exposes response
bodies/model outputs by logging error_body (from exc.read().decode) and
exc.code; change it to avoid printing raw body/model text: log only the status
code and a sanitized error type/message (e.g., exc.code and
exc.__class__.__name__), replace or redact the body content (e.g., mention
"response body redacted" or include a fixed-length hash/placeholder), and ensure
the same change is applied to the other occurrence around the block referenced
at line ~107; update the logger.warning call(s) to remove or mask error_body
while preserving useful diagnostic info.
- Around line 95-99: The loop over response_body needs defensive type checks to
avoid AttributeError when output/content are not the expected list/dict types;
before iterating, ensure response_body.get("output") is a list, each output is a
dict, output.get("content") is a list, and each content is a dict whose "text"
is a non-empty str, then pass that text into self._loads_model_json; skip
non-conforming entries and if no valid text is found raise/return a proper
adapter-level error (convert the potential AttributeError into the adapter's
exception type) so callers get a clear, handled error instead of a 500.
🪄 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: 58863025-d8a2-4b34-b1de-5dae16e16508
📒 Files selected for processing (8)
.env.exampleREADME.mdapp/config.pyapp/routers/newsletters.pyapp/services/newsletter_extractor.pyapp/services/openai_adapter.pydocs/env.mddocs/newsletter-extraction.md
📌 작업 요약
OPENAI_ENABLED환경변수로 OpenAI 실제 호출 활성화 여부 제어OPENAI_ENABLED=false로 두어 기존 rule-based baseline 응답 유지OPENAI_API_KEY,OPENAI_MODEL,OPENAI_BASE_URL,OPENAI_TIMEOUT_SECONDS환경변수 로딩 추가503, OpenAI 호출/응답 파싱/스키마 검증 실패 시502반환🌿 브랜치 정보
feat/#4-openai-adapterdevelop(기본)✅ 체크리스트
feat/refac/hotfix/chore/design/bugfix)feat/fix/refactor/docs/style/chore)🧪 테스트 결과
Summary by CodeRabbit
릴리스 노트
새로운 기능
문서
OPENAI_ENABLED,OPENAI_API_KEY,OPENAI_MODEL등)