Skip to content

refactor: chatbot const values commom logic change - #98

Merged
Yu-JeSeung merged 2 commits into
mainfrom
refactor/const_values_re_handle
Apr 29, 2026
Merged

refactor: chatbot const values commom logic change#98
Yu-JeSeung merged 2 commits into
mainfrom
refactor/const_values_re_handle

Conversation

@Yu-JeSeung

@Yu-JeSeung Yu-JeSeung commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

Close #91

🎯 배경

  • 난잡한 상수값들과 정규식 정리가 필요했습니다. 이번 리팩토링으로 유지보수 쉽도록 변경하였습니다.

🔍 주요 내용

  • 연락처, URL, 게시판/학과홈/교직원 URL, 부서 suffix, formatter 라인 패턴 공통화
  • 학사일정 태크 규칙 및 쿼리 키워드 하나의 테이블로 관리
  • 정규식 패턴을 공통 패턴으로 교체
  • 중복 패턴 제거 및 검색 랭킹 숫자 라벨링화
  • 태그 판별 로직 별도의 파일로 분리

@Yu-JeSeung Yu-JeSeung self-assigned this Apr 28, 2026
@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Yu-JeSeung has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 17 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 99bf385d-c700-44d4-9795-420eb3baf4cc

📥 Commits

Reviewing files that changed from the base of the PR and between 73b8aae and b97e416.

📒 Files selected for processing (1)
  • LLM/patterns.py
📝 Walkthrough

Walkthrough

정규식 패턴 정의를 중앙 집중식 LLM.patterns 모듈로 이동하고, 스케줄 태깅 로직을 LLM.sub_model.schedule_rules 모듈로 추출했습니다. 여러 모듈에서 로컬 정의된 정규식을 공유 상수로 대체하고, 검색 가중치를 설정 기반 상수로 매개변수화했습니다.

Changes

Cohort / File(s) Summary
패턴 중앙 집중화
LLM/patterns.py
설정 기반 스태프 URL 정규식 및 전화번호(한글/국제), 이메일, URL, 스케줄 형식, 부서 연락 패턴 등 여러 컴파일된 정규식 상수를 정의하는 새 모듈 추가
포매터 리팩토링
LLM/OSS/formatter.py
로컬 정규식 정의를 제거하고 LLM.patterns에서 공유 패턴 상수를 임포트하여 다양한 토큰화 및 부서 감지 호출 사이트에서 사용
쿼리 색인 최적화
LLM/sub_model/query_index.py
로컬 정규식을 LLM.patterns 상수로 교체하고, 검색 가중치 및 풀 크기를 명명된 설정 상수(PHONE_EMAIL_BONUS_RATIO, CONTACT_SEARCH_POOL_SIZE 등)로 매개변수화하여 재랭킹 로직 개선
스케줄 규칙 추출
LLM/sub_model/schedule_rules.py
스케줄 태깅 규칙, 의도 힌트, 제목/쿼리 기반 태그 계산 함수를 정의하는 새 모듈 추가
스케줄 색인 정리
LLM/sub_model/schedule_index.py
스케줄 태깅 로직을 schedule_rules 모듈로 위임하고, tags_for_title()tags_for_query() 헬퍼 함수 사용

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive PR 제목은 주요 변경 사항인 상수값과 정규식의 공통화 및 리팩토링을 부분적으로 반영하나, '난잡한 상수값 정리 및 공통화'보다는 너무 일반적이고 오타('commom')가 있습니다. 제목을 'refactor: consolidate constants and regex patterns for maintainability'와 같이 더 구체적이고 명확하게 수정하세요.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed PR 설명이 대부분 완성되어 있으며, 배경, 주요 내용이 충실하게 기술되어 있습니다. 템플릿의 모든 필수 섹션이 포함되어 있습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/const_values_re_handle

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.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 38 minutes and 17 seconds.

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

@Yu-JeSeung

Copy link
Copy Markdown
Contributor Author

@coderabbitai 해당 pr에 대한 리뷰 부탁합니다.

@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown

@Yu-JeSeung 안녕하세요! 해당 PR에 대한 리뷰를 진행하겠습니다. 잠시만 기다려 주세요.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@LLM/patterns.py`:
- Around line 28-29: The environment-driven regex in STAFF_URL_PATTERN uses
settings.staff_url_pattern directly and can raise re.error at import time;
update initialization to validate and compile settings.staff_url_pattern inside
a try/except (or use re.compile with fallback) and fall back to
STAFF_DEFAULT_URL_PATTERN if compilation fails, logging or warning the bad
pattern; apply the same safe-compile+fallback approach to the other occurrence
referenced at line 64 so imports never raise on invalid env regexes and
STAFF_URL_PATTERN remains a safe string/compiled pattern.
- Line 45: DEPT_CONTACT_INTENT_PATTERN currently allows the single token "과",
causing false positives; update the regex to disallow a bare "과" by replacing it
with more specific tokens or require a Korean-word prefix (e.g. use a pattern
that matches '[가-힣]+과' or explicit tokens like '학과|학부|전공' instead of plain '과')
so only department-like forms trigger the intent; modify the constant
DEPT_CONTACT_INTENT_PATTERN accordingly to include these stricter alternatives
and keep the existing '담당자\s*연락처' branch.

In `@LLM/sub_model/schedule_index.py`:
- Around line 134-135: 정규화가 빠져 동일 매칭에 실패하는 문제이므로 입력 q를 한 번 정규화한 변수로 재사용하도록
변경하세요: _looks_like_schedule_query에서 q를 (q or "")로 받지 말고, q_normalized = (q or
"").strip().lower() 및 내부 연속 공백을 단일 공백으로 축약하고 불필요한 구두점/특수문자를 제거하는 등 노말라이즈를 수행한 뒤
any(k in q_normalized for k in SCHEDULE_INTENT_HINTS)을 사용해 검사하도록 수정하고, 동일한 정규화
로직을 195번의 유사 검사(해당 함수/조건 표현식)에도 적용해 중복 정규화와 None 안전성을 확보하세요.
🪄 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: CHILL

Plan: Pro

Run ID: 9b3d7fc3-f25a-4650-9dc6-f5fe4ead27b2

📥 Commits

Reviewing files that changed from the base of the PR and between 86fbe5f and 73b8aae.

📒 Files selected for processing (5)
  • LLM/OSS/formatter.py
  • LLM/patterns.py
  • LLM/sub_model/query_index.py
  • LLM/sub_model/schedule_index.py
  • LLM/sub_model/schedule_rules.py

Comment thread LLM/patterns.py Outdated
Comment thread LLM/patterns.py Outdated
Comment on lines 134 to +135
def _looks_like_schedule_query(q):
return any(k in (q or "") for k in INTENT_HINTS)
return any(k in (q or "") for k in SCHEDULE_INTENT_HINTS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

질의 공백 변형에서 의도/태그 탐지가 누락될 수 있습니다.

Line 134, Line 195은 원문 문자열 그대로 포함 매칭을 수행합니다. "이번 주", "다음 달", "수강 정정" 같은 입력에서 탐지 실패 가능성이 있습니다. 질의를 한 번 정규화해서 재사용하는 쪽이 안전합니다.

수정 예시
 def _looks_like_schedule_query(q):
-    return any(k in (q or "") for k in SCHEDULE_INTENT_HINTS)
+    source = re.sub(r"\s+", "", (q or ""))
+    return any(k in source for k in SCHEDULE_INTENT_HINTS)
@@
-    tag_need = tags_for_query(query)
+    tag_need = tags_for_query(re.sub(r"\s+", "", (query or "")))

Also applies to: 195-195

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@LLM/sub_model/schedule_index.py` around lines 134 - 135, 정규화가 빠져 동일 매칭에 실패하는
문제이므로 입력 q를 한 번 정규화한 변수로 재사용하도록 변경하세요: _looks_like_schedule_query에서 q를 (q or
"")로 받지 말고, q_normalized = (q or "").strip().lower() 및 내부 연속 공백을 단일 공백으로 축약하고
불필요한 구두점/특수문자를 제거하는 등 노말라이즈를 수행한 뒤 any(k in q_normalized for k in
SCHEDULE_INTENT_HINTS)을 사용해 검사하도록 수정하고, 동일한 정규화 로직을 195번의 유사 검사(해당 함수/조건 표현식)에도
적용해 중복 정규화와 None 안전성을 확보하세요.

@Yu-JeSeung
Yu-JeSeung merged commit af79fb6 into main Apr 29, 2026
1 check was pending
@Yu-JeSeung
Yu-JeSeung deleted the refactor/const_values_re_handle branch April 29, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REFACTOR] AI 서비스 전체 코드 리팩토링 진행

1 participant