Skip to content

Feat/migrate to OpenAI#21

Merged
SanghunYun95 merged 54 commits intomainfrom
feat/migrate-to-openai
Mar 6, 2026
Merged

Feat/migrate to OpenAI#21
SanghunYun95 merged 54 commits intomainfrom
feat/migrate-to-openai

Conversation

@SanghunYun95
Copy link
Copy Markdown
Owner

@SanghunYun95 SanghunYun95 commented Mar 6, 2026

Summary by CodeRabbit

릴리스 노트

  • 개선 사항

    • AI 모델 제공자를 OpenAI로 전환하였습니다.
    • 채팅 기능의 타임아웃 처리 및 에러 로깅을 개선하였습니다.
  • 기술 업데이트

    • 의존성을 최신 OpenAI 라이브러리로 업데이트하였습니다.
    • API 키 관리 설정을 변경하였습니다.

…ifespan, and move asyncio import to stdlib group
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
philo-rag Ready Ready Preview, Comment Mar 25, 2026 0:46am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e0eb802-d7c5-4e96-9271-ceb05d8781fe

📥 Commits

Reviewing files that changed from the base of the PR and between d406f0b and e60cc1a.

📒 Files selected for processing (1)
  • backend/app/api/routes/chat.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/app/api/routes/chat.py

📝 Walkthrough

Walkthrough

Google Gemini API에서 OpenAI API로의 백엔드 마이그레이션을 수행합니다. 구성 설정, 환경 변수, 서비스 로직, 의존성 및 스크립트에서 관련 참조를 업데이트하여 Gemini 클라이언트를 OpenAI 클라이언트로 교체합니다.

Changes

Cohort / File(s) Summary
API 키 관리 및 설정
backend/app/core/config.py, backend/app/core/env_utils.py
GEMINI_API_KEYOPENAI_API_KEY로 변경; Settings 모델에 extra="ignore" 추가; parse_gemini_api_keys() 함수를 parse_openai_api_keys()로 이름 변경 및 환경 변수 참조 업데이트
LLM 서비스 통합
backend/app/services/llm.py
ChatGoogleGenerativeAIChatOpenAI로 교체; gemini-2.5-flash-litegpt-4o-mini 모델로 변경; get_all_gemini_keys()get_all_openai_keys()로 함수 이름 변경; 스트리밍 에러 핸들링 강화 및 타임아웃 로깅 개선
채팅 API 및 타임아웃 처리
backend/app/api/routes/chat.py
데이터베이스 검색 흐름에서 asyncio.wait_for 타임아웃 래퍼 제거; 채팅 제목 생성의 타임아웃 로깅 재계산 (t_start 기반 경과 시간 사용)
의존성 업데이트
backend/requirements.txt
langchain-google-genai, google-generativeai 제거; langchain-openai>=0.1.0, openai>=1.0.0 추가
유틸리티 스크립트
backend/scripts/check_models.py, backend/scripts/generate_book_mapping.py
genai 클라이언트를 OpenAI 클라이언트로 교체; API 키 환경 변수 및 함수 참조 업데이트; 에러 핸들링 로직 조정 (리소스 소진 특화 처리 제거)
테스트 설정
backend/tests/unit/test_llm.py
테스트 픽스처에서 GEMINI_API_KEYOPENAI_API_KEY 참조 변경

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • philo-rag#10: LLM 키 관리 및 설정 코드 경로를 동일하게 수정 (환경 변수 파싱, get_all_*get_llm 함수 변경)
  • philo-rag#20: backend/app/api/routes/chat.py의 데이터베이스 검색 타임아웃/세마포 로직을 수정 (이전 PR에서 추가된 세마포와 호출별 타임아웃을 현재 PR에서 제거)
  • philo-rag#17: backend/app/api/routes/chat.py에서 타임아웃 처리 및 로컬 임포트 동작 수정 (채팅 제목 생성 및 호출별 타임아웃 관련)

Poem

🐰 OpenAI로 갈아탄 래빗, 반갑네요!
Gemini에서 벗어나 새로운 길을 가요,
타임아웃도 깔끔하게, 에러도 명확하게,
API 키 회전하며 안정적으로 🚀
마이그레이션 완료, 우리 함께 나아가요!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Pull request title accurately summarizes the main change: migrating the LLM backend from Gemini to OpenAI across multiple files and dependencies.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/migrate-to-openai

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/app/api/routes/chat.py`:
- Around line 87-91: The current use of
asyncio.wait_for(asyncio.to_thread(_search_documents, query_vector),
timeout=CHAT_TIMEOUT) can leave the worker thread running after a timeout;
instead, remove the wait_for wrapper and call await
asyncio.to_thread(_search_documents, query_vector) directly while keeping the
semaphore (_db_rpc_semaphore) to limit concurrency, and rely on the DB client’s
internal timeout to abort long DB ops; update error handling around the await to
handle and log DB client timeouts/errors (referencing _search_documents,
_db_rpc_semaphore and CHAT_TIMEOUT) and remove any logic that assumes wait_for
will cancel the background thread.

In `@backend/requirements.txt`:
- Line 6: The langchain-openai version constraint currently prevents installing
the latest 1.x releases; update the requirement for the package named
"langchain-openai" by removing the upper bound or changing the spec to allow 1.x
(e.g., replace "langchain-openai>=0.1.0,<1.0.0" with "langchain-openai>=0.1.0"
or a range that includes 1.x) so the latest 1.1.10 (2026-02-17) can be
installed.

In `@backend/scripts/check_models.py`:
- Line 4: The code imports OpenAI directly with "from openai import OpenAI" but
the openai package is not listed explicitly in requirements.txt; add an explicit
dependency entry for "openai" (pinned to a compatible version with your
langchain-openai dependency) to requirements.txt so direct imports are
satisfied, then run your dependency/install workflow (pip install / lockfile
update) to ensure CI and local installs include the package.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8bec5acd-744c-4c2a-a02e-5abb5dcadebc

📥 Commits

Reviewing files that changed from the base of the PR and between c220735 and ff949ea.

📒 Files selected for processing (9)
  • backend/app/api/routes/chat.py
  • backend/app/core/config.py
  • backend/app/core/env_utils.py
  • backend/app/services/database.py
  • backend/app/services/llm.py
  • backend/requirements.txt
  • backend/scripts/check_models.py
  • backend/scripts/generate_book_mapping.py
  • backend/tests/unit/test_llm.py

Comment thread backend/app/api/routes/chat.py Outdated
Comment thread backend/requirements.txt Outdated
Comment thread backend/scripts/check_models.py
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
backend/app/api/routes/chat.py (2)

92-93: logging.exception 호출에서 중복된 예외 객체를 제거하세요.

logger.exception은 자동으로 예외 정보와 트레이스백을 포함하므로 {e}를 메시지에 포함할 필요가 없습니다.

♻️ 제안된 수정
     except Exception as e:
-        logger.exception(f"Database search failed: {e}")
+        logger.exception("Database search failed")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/app/api/routes/chat.py` around lines 92 - 93, In the except block
that currently reads "except Exception as e: logger.exception(f\"Database search
failed: {e}\")" (in backend/app/api/routes/chat.py), remove the redundant "{e}"
from the log message and call logger.exception with a plain message like
"Database search failed" so the exception and traceback are captured only once
by logger.exception; do not pass exc_info or the exception object separately.

207-209: 타임아웃 로그 형식의 일관성을 고려하세요.

다른 타임아웃 로그는 실제 경과 시간(time.perf_counter() - t0)을 기록하지만, 여기서는 상수 값만 출력합니다. 일관성을 위해 동일한 패턴을 적용하는 것이 좋습니다.

♻️ 제안된 수정
+    t_start = time.perf_counter()
     try:
         title = await asyncio.wait_for(generate_chat_title_async(query), timeout=CHAT_TIMEOUT)
         # ...
     except asyncio.TimeoutError:
-        logger.warning(f"Timeout generating chat title after {CHAT_TIMEOUT}s")
+        logger.warning(f"Timeout generating chat title after {time.perf_counter() - t_start:.2f}s")
         return {"title": DEFAULT_CHAT_TITLE}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/app/api/routes/chat.py` around lines 207 - 209, The timeout handler
currently logs the constant CHAT_TIMEOUT; change the logger.warning in the
except asyncio.TimeoutError block to report the actual elapsed time (e.g., use
time.perf_counter() - t0) for consistency with other timeout logs; update the
reference in that block (where DEFAULT_CHAT_TITLE is returned) to compute
elapsed from the existing t0 variable and include that elapsed value in the
warning message instead of CHAT_TIMEOUT.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@backend/app/api/routes/chat.py`:
- Around line 92-93: In the except block that currently reads "except Exception
as e: logger.exception(f\"Database search failed: {e}\")" (in
backend/app/api/routes/chat.py), remove the redundant "{e}" from the log message
and call logger.exception with a plain message like "Database search failed" so
the exception and traceback are captured only once by logger.exception; do not
pass exc_info or the exception object separately.
- Around line 207-209: The timeout handler currently logs the constant
CHAT_TIMEOUT; change the logger.warning in the except asyncio.TimeoutError block
to report the actual elapsed time (e.g., use time.perf_counter() - t0) for
consistency with other timeout logs; update the reference in that block (where
DEFAULT_CHAT_TITLE is returned) to compute elapsed from the existing t0 variable
and include that elapsed value in the warning message instead of CHAT_TIMEOUT.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00a268b6-1540-4691-92e9-6d15e65d632d

📥 Commits

Reviewing files that changed from the base of the PR and between ff949ea and d406f0b.

📒 Files selected for processing (2)
  • backend/app/api/routes/chat.py
  • backend/requirements.txt

@SanghunYun95 SanghunYun95 merged commit 35aebf5 into main Mar 6, 2026
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant