diff --git a/.github/workflows/ai-review.yml b/.github/workflows/ai-review.yml new file mode 100644 index 0000000..dcb8c38 --- /dev/null +++ b/.github/workflows/ai-review.yml @@ -0,0 +1,38 @@ +# This workflow enables developers to call PR-Agents `/[actions]` in PR's comments and upon PR creation. +# Learn more at https://www.codium.ai/pr-agent/ +# This is v0.2 of this workflow file + +name: PR-Agent + +on: + pull_request: + types: [opened] + issue_comment: + types: [created] + workflow_dispatch: + +permissions: + issues: write + pull-requests: write + +jobs: + pr_agent_job: + runs-on: ubuntu-latest + name: Run pr agent on every pull request + if: ${{ github.event.sender.type != 'Bot' }} + steps: + - name: PR Agent action step + id: pragent + uses: Codium-ai/pr-agent@main + env: + OPENAI_KEY: ${{ secrets.OPENAI_KEY }} + # OPENAI_ORG: ${{ secrets.OPENAI_ORG }} # optional + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # PINECONE.API_KEY: ${{ secrets.PINECONE_API_KEY }} + # PINECONE.ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }} + GITHUB_ACTION_CONFIG.AUTO_DESCRIBE: true + GITHUB_ACTION_CONFIG.AUTO_REVIEW: true + GITHUB_ACTION_CONFIG.AUTO_IMPROVE: true + PR_DESCRIPTION.EXTRA_INSTRUCTIONS: 'Please use Japanese.' + PR_REVIEWER.EXTRA_INSTRUCTIONS: 'Please use Japanese.' + PR_CODE_SUGGESTIONS.EXTRA_INSTRUCTIONS: 'Please use Japanese.' diff --git a/simirality/__pycache__/main.cpython-311.pyc b/simirality/__pycache__/main.cpython-311.pyc index 5e54373..4c83cfd 100644 Binary files a/simirality/__pycache__/main.cpython-311.pyc and b/simirality/__pycache__/main.cpython-311.pyc differ diff --git a/simirality/main.py b/simirality/main.py index 22d5cd7..b0165cc 100644 --- a/simirality/main.py +++ b/simirality/main.py @@ -29,34 +29,71 @@ class Words(BaseModel): assignmentWord: str words: List[str] - @app.post("/similarity") async def similarity(reqWords: Words): assignmentWord = reqWords.assignmentWord words = reqWords.words + try: + highscore, highscore_word = calcuSimilarity(assignmentWord, words) + except: + # 例外処理 + print("Error: 類似度の計算に失敗しました。課題が存在しない可能性があります。") + return {"similarity": 0} + + return {"similarity": highscore, "highscoreWord": highscore_word} + +# 類似度の計算 +def calcuSimilarity(assignmentWord, words): assignmentWord_synset = wn.synset(f"{assignmentWord}.n.01") highscore = 0 + highscore_word = "" + for word in words: print(f"word: {word}") try: - word_synset = wn.synset(f"{word}.n.01") - similarity = assignmentWord_synset.wup_similarity(word_synset) - print(f"{word}: {similarity}") + similarity = calculate(assignmentWord_synset, word, assignmentWord) - if assignmentWord == word: - similarity = 1.0 - - if similarity is None: - print(f"'{assignmentWord}' と '{word}' の類似度を計算できません。") + print(f"similarity: {similarity}") if similarity > highscore: highscore = similarity + highscore_word = word except: print(f"Error: '{word}' はWordNetに存在しません。") - return {"similarity": highscore} + # WordNet にない形式を検索 + wordByMorphy = wn.morphy(word) + print(f"wordByMorphy: {wordByMorphy}") + if wordByMorphy is not None: + try: + similarityByMorphy = calculate(assignmentWord_synset, wordByMorphy, assignmentWord) + + print(f"similarity: {similarityByMorphy}") + + if highscore < similarityByMorphy: + highscore = similarityByMorphy + highscore_word = word + + except: + print(f"Error: '{word}' はWordNetに存在しません。") + + return highscore, highscore_word + +def calculate(assignmentWord_synset, word, assignmentWord): + if assignmentWord == word: + return 1.0 + + word_synset = wn.synset(f"{word}.n.01") + + similarity = assignmentWord_synset.wup_similarity(word_synset) + + if similarity is None: + print(f"'{assignmentWord}' と '{word}' の類似度を計算できません。") + return 0 + + return similarity # MEMO こんな感じでPOSTリクエストを送る