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

wants to merge 25 commits into from

Conversation

Gupta-Anubhav12
Copy link
Member

@Gupta-Anubhav12 Gupta-Anubhav12 commented Aug 13, 2022

Summary by OpenAI

New Features:

  • Introduced SANSKRIT_RECITATION_HOST environment variable and added support for Sanskrit recitation audio files.
  • Added API_V3_STR constant to Settings class, enabling a new API version.
  • Introduced new endpoint /post_verse_of_the_day/ for posting verse of the day on Twitter.
  • Added transliterations to the database from a JSON file.
  • Added support for updating existing GitaVerse records.

Refactor:

  • Modified functions to return instances of schemas.GitaVerse instead of models.GitaVerse.
  • Changed relationships between GitaVerse, GitaTranslation, and GitaCommentary to use lazy loading.

Chore:

  • Updated required Python version from python3.8 or above to python3.10 or above.

🎉 A new dawn breaks with verses in hand, 📜

Transliterations flow like grains of sand. 🏖️

With each tweet, wisdom we expand, 🐦

In this digital Bhagavad Gita land. 🌐🕉️

Srishtikumari2002 and others added 24 commits December 13, 2021 19:21
…PI and have made necessary changes in following files

.env.example - added recitation_url host

api/api_v2/endpoints/gita.py - modified resolver function to include recitation url

* models/schemas.py - added the recitation url field
🚀   feat--Sanskrit  audio recitation
🚀 feat--Gita-Transliteration
…PI and have made necessary changes in following files

.env.example - added recitation_url host

api/api_v2/endpoints/gita.py - modified resolver function to include recitation url

* models/schemas.py - added the recitation url field
@github-actions
Copy link

github-actions bot commented Jul 1, 2023

🤖 OpenAI

High-Level Summary

The changes introduce a new version (v3) of the API, adding features like posting verses on Twitter and handling Sanskrit recitations. The codebase now supports Python 3.10 and uses GitHub Actions for PR reviews. Database operations have been optimized to handle updates and avoid duplicates. Environment variables have been updated, including the addition of a testing API key.

Files Summary
.env.example, bhagavad_gita_api/config.py Introduced SANSKRIT_RECITATION_HOST environment variable and removed debug variable in production. Added API_V3_STR constant to Settings class and updated print statement in Config class for SQLite database usage.
.github/CONTRIBUTING.md, .github/workflows/openai-pr-reviewer.yml Updated required Python version from python3.8 or above to python3.10 or above. Added GitHub Actions workflow file for code review using fluxninja/openai-pr-reviewer action.
bhagavad_gita_api/api/api_v2/endpoints/gita.py, bhagavad_gita_api/api/api_v3/api.py, bhagavad_gita_api/api/api_v3/endpoints/social.py Modified functions to return instances of schemas.GitaVerse instead of models.GitaVerse, fetching translations and commentaries for each verse. Added two routers (gita and social) to API router (api_router_v3). Introduced new endpoint /post_verse_of_the_day/ for posting verse of the day on Twitter.
bhagavad_gita_api/data/__init__.py, bhagavad_gita_api/data/helpers.py, bhagavad_gita_api/data/insert/languages.py Added transliterations module to imports. Changed default value of branch parameter in gh_file_url function to "feat--new-languages". Added check to avoid duplicate entries when loading languages from JSON file.
bhagavad_gita_api/data/insert/transliterations.py Added transliterations to the database from a JSON file, checking for existing entries before adding new ones. Displayed operation progress using rich.progress module.
bhagavad_gita_api/data/insert/verses.py Added support for updating existing GitaVerse records. Retrieved SANSKRIT_RECITATION_HOST from environment variables. Modified logic for adding verses to handle updates and new entries separately.
bhagavad_gita_api/main.py Added new router api_router_v3 to the application with prefix /api/v3/, using the same security dependency as api_router.
bhagavad_gita_api/models/gita.py Added new table GitaTransliteration and modified GitaVerse table by adding sanskrit_recitation_url column. Changed relationships between GitaVerse, GitaTranslation, and GitaCommentary to use lazy loading.
bhagavad_gita_api/models/schemas.py Introduced GitaVerseV3 class extending GitaVerse with an optional field transliterations. Added optional field author_name to GitaAuthor class.

Chat with 🤖 OpenAI Bot (@openai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @openai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Ignoring further reviews

  • Type @openai: ignore anywhere in the PR description to ignore further reviews from the bot.


In the recent run, only the files that changed from the base of the PR and between 00d4c1f9da311bec9b38692ee8f4c63b5eba6cd8 and cdc227a2d1fee87c3db0a5b27bae54bb7b020a5f commits were reviewed.

.env.example Outdated Show resolved Hide resolved
Comment on lines 101 to 127
):
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

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

Comment on lines 136 to +159
):
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(),
)
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,
)

Comment on lines +3 to +7

from fastapi import APIRouter, Depends, HTTPException, Response
from sqlalchemy.orm import Session

from bhagavad_gita_api.api import deps
Copy link

Choose a reason for hiding this comment

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

🤖 OpenAI

While these imports are fine, it's a good practice to group and order your imports according to PEP8 guidelines. This helps in maintaining the code readability.

Suggested change
from fastapi import APIRouter, Depends, HTTPException, Response
from sqlalchemy.orm import Session
from bhagavad_gita_api.api import deps
from datetime import date
import logging
from fastapi import APIRouter, Depends, HTTPException, Response
from sqlalchemy.orm import Session
from bhagavad_gita_api.api import deps
from bhagavad_gita_api.models import gita as models

Comment on lines +15 to +24

router = APIRouter()


@router.post(
"/post_verse_of_the_day/",
tags=[
"social_v3",
],
)
Copy link

Choose a reason for hiding this comment

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

🤖 OpenAI

The router object is created but not used immediately. It would be better to move this closer to where it's first used (line 19) to improve readability.

Comment on lines +25 to +32
async def post_instagram(db: Session = Depends(deps.get_db)):
verse_of_day = (
db.query(models.VerseOfDay)
.filter(
models.VerseOfDay.date == date.today(),
)
.first()
)
Copy link

Choose a reason for hiding this comment

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

🤖 OpenAI

This block of code queries for the verse of the day. However, there is no error handling if the database query fails. Consider adding a try-except block around the database operations to handle any potential exceptions.

Comment on lines +33 to +40

if verse_of_day:
verse = (
db.query(models.GitaVerse)
.join(models.GitaTranslation)
.filter(models.GitaVerse.id == verse_of_day.verse_order)
.first()
)
Copy link

Choose a reason for hiding this comment

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

🤖 OpenAI

This block of code fetches the verse corresponding to the verse of the day. Similar to the previous comment, consider adding error handling for database operations.

Comment on lines +1 to +16
import enum
import logging
import random
from datetime import date
from typing import List

from fastapi import APIRouter, Depends, HTTPException, Response
from sqlalchemy import func, or_
from sqlalchemy.orm import Session, joinedload

from bhagavad_gita_api.api import deps
from bhagavad_gita_api.models import gita as models
from bhagavad_gita_api.models import schemas

logger = logging.getLogger("api")
logger.setLevel(logging.DEBUG)
Copy link

Choose a reason for hiding this comment

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

🤖 OpenAI

The logger is set up at the module level, which is a good practice. However, it's recommended to use __name__ as the name of the logger to get the context of where the logging is happening.

Suggested change
import enum
import logging
import random
from datetime import date
from typing import List
from fastapi import APIRouter, Depends, HTTPException, Response
from sqlalchemy import func, or_
from sqlalchemy.orm import Session, joinedload
from bhagavad_gita_api.api import deps
from bhagavad_gita_api.models import gita as models
from bhagavad_gita_api.models import schemas
logger = logging.getLogger("api")
logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
.env.example Show resolved Hide resolved
.env.example Show resolved Hide resolved
.env.example Show resolved Hide resolved
@samanyougarg samanyougarg marked this pull request as draft July 2, 2023 05:56
@samanyougarg samanyougarg marked this pull request as ready for review July 8, 2023 17:36
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.

4 participants