-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add gemini service to generate catalog names #29
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2dc3152
feat: add gemini service to generate catalog names
TimilsinaBimal 9f84f43
Update app/services/catalog_updater.py
TimilsinaBimal 182e387
fix: check for keyword length before accessing
TimilsinaBimal 3e7eed7
fix: handle gemini config
TimilsinaBimal 3e74444
redudant code
TimilsinaBimal 285fb83
gemini
TimilsinaBimal 3fcbb9e
gemini
TimilsinaBimal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from google import genai | ||
| from loguru import logger | ||
|
|
||
| from app.core.config import settings | ||
|
|
||
|
|
||
| class GeminiService: | ||
| def __init__(self, model: str = settings.DEFAULT_GEMINI_MODEL): | ||
| self.model = model | ||
| self.client = None | ||
| if api_key := settings.GEMINI_API_KEY: | ||
| try: | ||
| self.client = genai.Client(api_key=api_key) | ||
| except Exception as e: | ||
| logger.warning(f"Failed to initialize Gemini client: {e}") | ||
| else: | ||
| logger.warning("GEMINI_API_KEY not set. Gemini features will be disabled.") | ||
|
|
||
TimilsinaBimal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @staticmethod | ||
| def get_prompt(): | ||
| return """ | ||
| You are a content catalog naming expert. | ||
| Given filters like genre, keywords, countries, or years, generate natural, | ||
| engaging catalog row titles that streaming platforms would use. | ||
| Examples: | ||
| - Genre: Action, Country: South Korea → "Korean Action Thrillers" | ||
| - Keyword: "space", Genre: Sci-Fi → "Space Exploration Adventures" | ||
| - Genre: Drama, Country: France → "Acclaimed French Cinema" | ||
| - Country: "USA" + Genre: "Sci-Fi and Fantasy" → "Hollywood Sci-Fi and Fantasy" | ||
| - Keywords: "revenge" + "martial arts" → "Revenge & Martial Arts" | ||
| Keep titles: | ||
| - Short (2-5 words) | ||
| - Natural and engaging | ||
| - Focused on what makes the content appealing | ||
| - Only return a single best title and nothing else. | ||
| """ | ||
|
|
||
| def generate_content(self, prompt: str) -> str: | ||
| system_prompt = self.get_prompt() | ||
| if not self.client: | ||
| logger.warning("Gemini client not initialized. Gemini features will be disabled.") | ||
| return "" | ||
| try: | ||
| response = self.client.models.generate_content( | ||
| model=self.model, | ||
| contents=system_prompt + "\n\n" + prompt, | ||
| ) | ||
| return response.text.strip() | ||
| except Exception as e: | ||
| logger.error(f"Error generating content: {e}") | ||
| return "" | ||
TimilsinaBimal marked this conversation as resolved.
Show resolved
Hide resolved
TimilsinaBimal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| gemini_service = GeminiService() | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,14 @@ | ||
| annotated-doc==0.0.4 | ||
| annotated-types==0.7.0 | ||
| anyio==4.11.0 | ||
| apscheduler==3.11.1 | ||
| async-lru==2.0.5 | ||
| async-timeout==5.0.1 | ||
| beautifulsoup4==4.14.3 | ||
| black==25.11.0 | ||
| cachetools==6.2.2 | ||
| certifi==2025.11.12 | ||
| cffi==2.0.0 | ||
| cfgv==3.5.0 | ||
| charset-normalizer==3.4.4 | ||
| click==8.3.1 | ||
| cryptography==46.0.3 | ||
| deep-translator==1.11.4 | ||
| distlib==0.4.0 | ||
| exceptiongroup==1.3.0 | ||
| fastapi==0.121.2 | ||
| filelock==3.20.0 | ||
| flake9==3.8.3.post2 | ||
| h11==0.16.0 | ||
| httpcore==1.0.9 | ||
| httptools==0.7.1 | ||
| httpx==0.28.1 | ||
| identify==2.6.15 | ||
| idna==3.11 | ||
| loguru==0.7.3 | ||
| mccabe==0.6.1 | ||
| mypy-extensions==1.1.0 | ||
| nodeenv==1.9.1 | ||
| packaging==25.0 | ||
| pathspec==0.12.1 | ||
| platformdirs==4.5.0 | ||
| pre-commit==4.4.0 | ||
| pycodestyle==2.6.0 | ||
| pycparser==2.23 | ||
| pydantic==2.12.4 | ||
| pydantic-core==2.41.5 | ||
| pydantic-settings==2.12.0 | ||
| pyflakes==2.2.0 | ||
| python-dotenv==1.2.1 | ||
| pytokens==0.3.0 | ||
| pyyaml==6.0.3 | ||
| redis==7.1.0 | ||
| requests==2.32.5 | ||
| sniffio==1.3.1 | ||
| soupsieve==2.8 | ||
| starlette==0.49.3 | ||
| tomli==2.3.0 | ||
| typing-extensions==4.15.0 | ||
| typing-inspection==0.4.2 | ||
| tzlocal==5.3.1 | ||
| urllib3==2.6.0 | ||
| uvicorn==0.38.0 | ||
| uvloop==0.22.1 | ||
| virtualenv==20.35.4 | ||
| watchfiles==1.1.1 | ||
| websockets==15.0.1 | ||
| apscheduler>=3.11.1 | ||
| async-lru>=2.0.5 | ||
| cachetools>=6.2.2 | ||
| cryptography>=46.0.3 | ||
| deep-translator>=1.11.4 | ||
| fastapi>=0.104.1 | ||
| google-genai>=1.54.0 | ||
| httpx>=0.25.2 | ||
| loguru>=0.7.2 | ||
| pydantic>=2.5.0 | ||
| pydantic-settings>=2.1.0 | ||
| redis>=5.0.1 | ||
| tomli>=2.3.0 | ||
| uvicorn[standard]>=0.24.0 |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.