PDFファイルから問題を自動生成する機能を追加し、READMEを更新#35
Merged
Merged
Conversation
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 20 medium 3 minor 1 high |
| CodeStyle | 3 minor |
| Complexity | 1 medium |
🟢 Metrics 78 complexity · 0 duplication
Metric Results Complexity 78 Duplication 0
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull request overview
PDF添付からGemini API経由で暗記問題を自動生成し、Discord Botの問題追加フローに取り込めるようにするPRです。既存の暗記メモリ機能(Excel/手動追加)に対して、PDF入力の導線と依存関係・READMEを追加しています。
Changes:
m!add_pdf <title>のプレフィックスコマンドを追加し、PDFから問題を自動生成して保存できるように変更- PDFテキスト抽出(pypdf)+ Gemini生成(google-genai)用の処理を
Addに追加 - 依存関係(pypdf / google-genai / jishaku / openpyxl)とREADME手順を更新
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| requirements.txt | PDF解析・Gemini・デバッグ等の依存を追加 |
| README.md | Gemini APIキー設定とPDF自動生成コマンドの利用手順を追記 |
| memorization_maker/README.md | PDF自動生成機能の説明を追記 |
| memorization_maker/base_question_add.py | PDF→テキスト抽出→Gemini→問題正規化→保存の処理を追加 |
| cogs/memorization_cog.py | m!add_pdf コマンド追加、OWNER_ID定数化など |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+92
to
+109
| select = question.get("select", []) | ||
| if not isinstance(select, list) or len(select) < 2: | ||
| continue | ||
| select = [str(choice).strip() for choice in select if str(choice).strip()] | ||
| if len(select) < 2: | ||
| continue | ||
|
|
||
| answer = question.get("answer") | ||
| if isinstance(answer, str) and answer.isdigit(): | ||
| answer = int(answer) | ||
| try: | ||
| answer = int(answer) | ||
| except (TypeError, ValueError): | ||
| continue | ||
| if answer < 0 or answer >= len(select): | ||
| continue | ||
|
|
||
| normalized.append({"question": question_text, "answer": answer, "mode": 1, "select": select}) |
|
|
||
| return normalized | ||
|
|
||
| async def _extract_pdf_text(self, pdf_path: str) -> str: |
Comment on lines
+181
to
+201
| try: | ||
| extracted_text = await self._extract_pdf_text(temp_path) | ||
| # max_questions の範囲を制限(MAX=100) | ||
| try: | ||
| max_q = int(max_questions) | ||
| except Exception: | ||
| max_q = 50 | ||
| if max_q > 100: | ||
| max_q = 100 | ||
| if max_q < 1: | ||
| max_q = 1 | ||
| questions = await asyncio.to_thread( | ||
| self._generate_questions_with_gemini, | ||
| temp_path, | ||
| extracted_text, | ||
| api_key, | ||
| max_q, | ||
| force_mode, | ||
| ai_instruction, | ||
| ) | ||
| return questions |
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.
No description provided.