Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #92

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

V2 #92

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a384835
created resolver function for adding Sanskrit recitation url to the A…
Srishtikumari2002 Dec 13, 2021
7633f71
Merge pull request #70 from Srishtikumari2002/main
Gupta-Anubhav12 Dec 15, 2021
da2b7f8
Revert "Feat--recitations"
Gupta-Anubhav12 Dec 15, 2021
eaec69c
Merge pull request #71 from gita/revert-70-main
Srishtikumari2002 Dec 15, 2021
2615876
feat--Sanskrit audio recitation
Srishtikumari2002 Dec 22, 2021
ff5e9a8
Merge branch 'woc_srishti' into main
Gupta-Anubhav12 Dec 22, 2021
239ae67
Merge pull request #73 from Srishtikumari2002/main
Gupta-Anubhav12 Dec 22, 2021
405eb84
Added GitaTransliteration
Srishtikumari2002 Dec 31, 2021
ce0ea59
removed english translation from Gita verse and moved to transliteration
blaze2004 Jan 14, 2022
85ae163
Merge pull request #80 from Srishtikumari2002/main
Gupta-Anubhav12 Jan 16, 2022
a366ee0
Update schemas.py
Srishtikumari2002 Jan 29, 2022
e729751
rebase with main and remove conflicts
Gupta-Anubhav12 Aug 14, 2022
4b19876
WIP API V3
Gupta-Anubhav12 Aug 14, 2022
b854d4a
fix new endpoints and maintian old version on dynamic loading
Gupta-Anubhav12 Aug 21, 2022
eb5d63e
fixed poetry package versions
samanyougarg Jan 22, 2023
ad5bf23
Update CONTRIBUTING.md
samanyougarg Jan 22, 2023
e604961
Create openai-pr-reviewer.yml
samanyougarg Jul 1, 2023
5bf40a7
Delete openai-pr-reviewer.yml
samanyougarg Jul 1, 2023
3a0b7cf
Add files via upload
samanyougarg Jul 1, 2023
3c6d920
created resolver function for adding Sanskrit recitation url to the A…
Srishtikumari2002 Dec 13, 2021
56d8314
feat--Sanskrit audio recitation
Srishtikumari2002 Dec 22, 2021
770b1cb
rebase with main
samanyougarg Jul 1, 2023
4f01dbe
Added GitaTransliteration
Srishtikumari2002 Dec 31, 2021
00d4c1f
rebase with main
samanyougarg Jul 1, 2023
cdc227a
Update .env.example
samanyougarg Jul 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# API key for testing
TESTER_API_KEY=abc123

# Remove the debug variable in production
debug=1
# URL for Sanskrit recitation audio files
SANSKRIT_RECITATION_HOST=https://gita.github.io/gita/data/verse_recitation
samanyougarg marked this conversation as resolved.
Show resolved Hide resolved

# Debug mode (1 = enabled, 0 = disabled)
# Remove this variable in production
debug=1
samanyougarg marked this conversation as resolved.
Show resolved Hide resolved
# database variables
# if the below variables are not provided
# the database will default to sqlite3
samanyougarg marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thank you for your interest and welcome here!
To work on this project you will need the following software installed in your machine.

- git (version control)
- python3.8 or above
- python3.10 or above
- poetry (package management)
- make (command line utils)
- docker (optional, if you want to build docker images)
samanyougarg marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/openai-pr-reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code Review

permissions:
contents: read
pull-requests: write

on:
pull_request:
branches:
- master
- main
pull_request_review_comment:
types: [created]

concurrency:
group:
${{ github.repository }}-${{ github.event.number || github.head_ref ||
github.sha }}-${{ github.workflow }}-${{ github.event_name ==
'pull_request_review_comment' && 'pr_comment' || 'pr' }}
cancel-in-progress: ${{ github.event_name != 'pull_request_review_comment' }}

jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: fluxninja/openai-pr-reviewer@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
with:
debug: false
review_simple_changes: false
review_comment_lgtm: false
openai_light_model: 'gpt-3.5-turbo'
openai_heavy_model: 'gpt-4'
samanyougarg marked this conversation as resolved.
Show resolved Hide resolved
40 changes: 30 additions & 10 deletions bhagavad_gita_api/api/api_v2/endpoints/gita.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,29 @@ async def get_all_verses_from_particular_chapter(
):
verses = (
db.query(models.GitaVerse)
.options(
joinedload(models.GitaVerse.commentaries),
joinedload(models.GitaVerse.translations),
)
.order_by(models.GitaVerse.id.asc())
.filter(models.GitaVerse.chapter_number == chapter_number)
.all()
)
if verses is None:
raise HTTPException(status_code=404, detail="Verse not found")
return verses
res = []
for verse in verses:
res.append(
schemas.GitaVerse(
id=verse.id,
verse_number=verse.verse_number,
chapter_number=verse.chapter_number,
slug=verse.slug,
text=verse.text,
transliteration=verse.transliteration,
word_meanings=verse.word_meanings,
sanskrit_recitation_url=verse.sanskrit_recitation_url,
translations=verse.translations.all(),
commentaries=verse.commentaries.all(),
)
)
return res

Comment on lines 101 to 127
Copy link

Choose a reason for hiding this comment

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

🤖 OpenAI

The logic for querying the verses and handling the case when no verses are found is incorrect. The SQLAlchemy all() method returns an empty list when no results are found, not None. Therefore, the condition if verses is None: will never be true even if no verses are found. You should check if the list is empty instead.

Suggested change
):
verses = (
db.query(models.GitaVerse)
.options(
joinedload(models.GitaVerse.commentaries),
joinedload(models.GitaVerse.translations),
)
.order_by(models.GitaVerse.id.asc())
.filter(models.GitaVerse.chapter_number == chapter_number)
.all()
)
if verses is None:
raise HTTPException(status_code=404, detail="Verse not found")
return verses
res = []
for verse in verses:
res.append(
schemas.GitaVerse(
id=verse.id,
verse_number=verse.verse_number,
chapter_number=verse.chapter_number,
slug=verse.slug,
text=verse.text,
transliteration=verse.transliteration,
word_meanings=verse.word_meanings,
sanskrit_recitation_url=verse.sanskrit_recitation_url,
translations=verse.translations.all(),
commentaries=verse.commentaries.all(),
)
)
return res
verses = (
db.query(models.GitaVerse)
.order_by(models.GitaVerse.id.asc())
.filter(models.GitaVerse.chapter_number == chapter_number)
.all()
)
if not verses:
raise HTTPException(status_code=404, detail="Verse not found")
res = []
for verse in verses:
res.append(
schemas.GitaVerse(
id=verse.id,
verse_number=verse.verse_number,
chapter_number=verse.chapter_number,
slug=verse.slug,
text=verse.text,
transliteration=verse.transliteration,
word_meanings=verse.word_meanings,
sanskrit_recitation_url=verse.sanskrit_recitation_url,
translations=verse.translations.all(),
commentaries=verse.commentaries.all(),
)
)
return res


@router.get(
Expand All @@ -124,19 +136,27 @@ async def get_particular_verse_from_chapter(
):
verse = (
db.query(models.GitaVerse)
.options(
joinedload(models.GitaVerse.commentaries),
joinedload(models.GitaVerse.translations),
)
.filter(
models.GitaVerse.chapter_number == chapter_number,
models.GitaVerse.verse_number == verse_number,
)
.first()
)

if verse is None:
raise HTTPException(status_code=404, detail="Verse not found")
return verse
return schemas.GitaVerse(
id=verse.id,
verse_number=verse.verse_number,
chapter_number=verse.chapter_number,
slug=verse.slug,
text=verse.text,
transliteration=verse.transliteration,
word_meanings=verse.word_meanings,
sanskrit_recitation_url=verse.sanskrit_recitation_url,
translations=verse.translations.all(),
commentaries=verse.commentaries.all(),
)
Comment on lines 136 to +159
Copy link

Choose a reason for hiding this comment

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

🤖 OpenAI

Similar to the previous issue, the SQLAlchemy first() method returns None when no results are found. So, the condition if verse is None: is correct in this case. However, you're calling .all() on verse.translations and verse.commentaries, which could potentially return None if there are no translations or commentaries. It would be better to handle these cases to avoid potential AttributeErrors.

Suggested change
):
verse = (
db.query(models.GitaVerse)
.options(
joinedload(models.GitaVerse.commentaries),
joinedload(models.GitaVerse.translations),
)
.filter(
models.GitaVerse.chapter_number == chapter_number,
models.GitaVerse.verse_number == verse_number,
)
.first()
)
if verse is None:
raise HTTPException(status_code=404, detail="Verse not found")
return verse
return schemas.GitaVerse(
id=verse.id,
verse_number=verse.verse_number,
chapter_number=verse.chapter_number,
slug=verse.slug,
text=verse.text,
transliteration=verse.transliteration,
word_meanings=verse.word_meanings,
sanskrit_recitation_url=verse.sanskrit_recitation_url,
translations=verse.translations.all(),
commentaries=verse.commentaries.all(),
)
verse = (
db.query(models.GitaVerse)
.filter(
models.GitaVerse.chapter_number == chapter_number,
models.GitaVerse.verse_number == verse_number,
)
.first()
)
if verse is None:
raise HTTPException(status_code=404, detail="Verse not found")
translations = verse.translations.all() if verse.translations else []
commentaries = verse.commentaries.all() if verse.commentaries else []
return schemas.GitaVerse(
id=verse.id,
verse_number=verse.verse_number,
chapter_number=verse.chapter_number,
slug=verse.slug,
text=verse.text,
transliteration=verse.transliteration,
word_meanings=verse.word_meanings,
sanskrit_recitation_url=verse.sanskrit_recitation_url,
translations=translations,
commentaries=commentaries,
)



@router.post("/set-daily-verse/", tags=["verses"])
Expand Down
7 changes: 7 additions & 0 deletions bhagavad_gita_api/api/api_v3/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import APIRouter

from bhagavad_gita_api.api.api_v3.endpoints import gita, social

api_router_v3 = APIRouter()
api_router_v3.include_router(gita.router)
api_router_v3.include_router(social.router, include_in_schema=True)
samanyougarg marked this conversation as resolved.
Show resolved Hide resolved
Loading