-
-
Notifications
You must be signed in to change notification settings - Fork 89
feat: Add Japanese language support for podcast generation #11
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
Open
MASAKASUNO1
wants to merge
1
commit into
BandarLabs:main
Choose a base branch
from
MASAKASUNO1:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,10 @@ | |||||
| from app.core.limiter import limiter | ||||||
| import os | ||||||
| from app.prompts import PODCAST_SSML_PROMPT_AFTER_BREAK, PODCAST_SSML_PROMPT, PODCAST_SSML_PROMPT_BEFORE_BREAK, SLIDE_PROMPT | ||||||
| from app.prompts_jp import PODCAST_SSML_PROMPT_AFTER_BREAK as PODCAST_SSML_PROMPT_AFTER_BREAK_JP | ||||||
| from app.prompts_jp import PODCAST_SSML_PROMPT as PODCAST_SSML_PROMPT_JP | ||||||
| from app.prompts_jp import PODCAST_SSML_PROMPT_BEFORE_BREAK as PODCAST_SSML_PROMPT_BEFORE_BREAK_JP | ||||||
| from app.prompts_jp import SLIDE_PROMPT as SLIDE_PROMPT_JP | ||||||
| from anthropic._exceptions import RateLimitError | ||||||
| from pydantic import BaseModel | ||||||
| from functools import lru_cache | ||||||
|
|
@@ -125,11 +129,12 @@ def process_github_content_for_slides(content, slide_prompt, max_length, max_tok | |||||
| return slide_markdown_response | ||||||
|
|
||||||
|
|
||||||
| def generate_ssml_concurrently(file_tree, readme, file_content, audio_length) -> str | dict: | ||||||
| def generate_ssml_concurrently(file_tree, readme, file_content, audio_length, language='en') -> str | dict: | ||||||
| # Prepare the content | ||||||
| if audio_length == 'short': | ||||||
| combined_content = f"FILE TREE: {file_tree}\nREADME: {readme} IMPORTANT FILES: {file_content}" | ||||||
| ssml_response = process_github_content(combined_content, PODCAST_SSML_PROMPT, 250000, 100000) | ||||||
| prompt = PODCAST_SSML_PROMPT_JP if language == 'ja' else PODCAST_SSML_PROMPT | ||||||
| ssml_response = process_github_content(combined_content, prompt, 250000, 100000) | ||||||
| return ssml_response | ||||||
| else: | ||||||
| combined_content_tree_readme = f"FILE TREE: {file_tree}\nREADME: {readme}" | ||||||
|
|
@@ -143,17 +148,20 @@ def check_response(response): | |||||
|
|
||||||
| # Use ThreadPoolExecutor to execute tasks concurrently | ||||||
| with concurrent.futures.ThreadPoolExecutor() as executor: | ||||||
| prompt_before = PODCAST_SSML_PROMPT_BEFORE_BREAK_JP if language == 'ja' else PODCAST_SSML_PROMPT_BEFORE_BREAK | ||||||
| prompt_after = PODCAST_SSML_PROMPT_AFTER_BREAK_JP if language == 'ja' else PODCAST_SSML_PROMPT_AFTER_BREAK | ||||||
|
|
||||||
| future_tree_readme = executor.submit( | ||||||
| process_github_content, | ||||||
| combined_content_tree_readme, | ||||||
| PODCAST_SSML_PROMPT_BEFORE_BREAK, | ||||||
| prompt_before, | ||||||
| 250000, | ||||||
| 100000 | ||||||
| ) | ||||||
| future_file_content = executor.submit( | ||||||
| process_github_content, | ||||||
| combined_content_file_content, | ||||||
| PODCAST_SSML_PROMPT_AFTER_BREAK, | ||||||
| prompt_after, | ||||||
| 250000, | ||||||
| 100000 | ||||||
| ) | ||||||
|
|
@@ -172,7 +180,8 @@ def check_response(response): | |||||
| combined_ssml_content = f"{ssml_response_tree_readme_content}\n{ssml_response_file_content_content}" | ||||||
|
|
||||||
| # Wrap the combined content in a single <speak> tag | ||||||
| full_ssml_response = f'<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">{combined_ssml_content}</speak>' | ||||||
| xml_lang = 'ja-JP' if language == 'ja' else 'en-US' | ||||||
| full_ssml_response = f'<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="{xml_lang}">{combined_ssml_content}</speak>' | ||||||
|
|
||||||
| # Proceed with ssml_response_tree_readme and ssml_response_file_content as needed | ||||||
| return full_ssml_response | ||||||
|
|
@@ -185,6 +194,7 @@ class ApiRequest(BaseModel): | |||||
| api_key: str | None = None | ||||||
| audio: bool = False # new param | ||||||
| audio_length: str = 'long' | ||||||
| language: str = 'en' # new param for language selection | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| class SlideRequest(BaseModel): | ||||||
|
|
@@ -194,6 +204,7 @@ class SlideRequest(BaseModel): | |||||
| api_key: str | None = None | ||||||
| audio: bool = False # new param | ||||||
| audio_length: str = 'long' | ||||||
| language: str = 'en' # new param for language selection | ||||||
|
|
||||||
|
|
||||||
| # @limiter.limit("1/minute;5/day") # TEMP: disable rate limit for growth?? | ||||||
|
|
@@ -216,7 +227,7 @@ async def generate(request: Request, body: ApiRequest): | |||||
| readme = github_data["readme"] | ||||||
| file_content = github_data["file_content"] | ||||||
|
|
||||||
| result = generate_ssml_concurrently(file_tree, readme, file_content, audio_length) | ||||||
| result = generate_ssml_concurrently(file_tree, readme, file_content, audio_length, body.language) | ||||||
| # Check if there was an error response | ||||||
| if isinstance(result, dict): # There was an error | ||||||
| print("Error in processing:") | ||||||
|
|
@@ -278,7 +289,8 @@ async def generate_slide(request: Request, body: SlideRequest): | |||||
| file_tree = github_data["file_tree"] | ||||||
| readme = github_data["readme"] | ||||||
| file_content = github_data["file_content"] | ||||||
| markdown = process_github_content_for_slides(f" file tree: {file_tree} \n contents: {file_content}", SLIDE_PROMPT, 250000, 100000) | ||||||
| slide_prompt = SLIDE_PROMPT_JP if body.language == 'ja' else SLIDE_PROMPT | ||||||
| markdown = process_github_content_for_slides(f" file tree: {file_tree} \n contents: {file_content}", slide_prompt, 250000, 100000) | ||||||
| return {"slide_markdown": markdown} | ||||||
| except Exception as e: | ||||||
| raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}") | ||||||
|
|
||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prompt selection logic is duplicated. Consider centralizing the prompt configuration to avoid repetition and improve maintainability. This applies to lines 151, 183, and 292 as well.