-
Notifications
You must be signed in to change notification settings - Fork 286
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
[Proof-of-concept] Added configurable reduction step after longform chunk transcript generation #205
Closed
Closed
[Proof-of-concept] Added configurable reduction step after longform chunk transcript generation #205
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
from langchain_community.chat_models import ChatLiteLLM | ||
from langchain_google_genai import ChatGoogleGenerativeAI | ||
from langchain_community.llms.llamafile import Llamafile | ||
from langchain_core.prompts import ChatPromptTemplate | ||
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate | ||
from langchain_core.output_parsers import StrOutputParser | ||
from langchain import hub | ||
from podcastfy.utils.config_conversation import load_conversation_config | ||
|
@@ -503,6 +503,7 @@ def clean(self, | |
# Then apply additional long-form specific cleaning | ||
return self._clean_transcript_response(standard_clean, config) | ||
|
||
|
||
def _clean_transcript_response(self, transcript: str, config: Dict[str, Any]) -> str: | ||
""" | ||
Clean transcript using a two-step process with LLM-based cleaning. | ||
|
@@ -522,7 +523,40 @@ def _clean_transcript_response(self, transcript: str, config: Dict[str, Any]) -> | |
""" | ||
logger.debug("Starting transcript cleaning process") | ||
|
||
final_transcript = self._fix_alternating_tags(transcript) | ||
# Run rewriting chain | ||
llm = self.llm | ||
|
||
analysis_prompt = PromptTemplate( | ||
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. Should probably be off by default. |
||
input_variables=["transcript"], | ||
template=config.get("analysis_prompt_template", "You are a podcast editor. Analyze this podcast transcript and identify duplicated/repeated lines and recommendations to improve flow. Do not remove too many facts or add any new facts: \n\n{transcript} \n\nAnalysis (bullet-points, with line numbers referring to problematic lines.):") | ||
) | ||
analysis_chain = analysis_prompt | llm | StrOutputParser() | ||
|
||
rewrite_prompt = PromptTemplate( | ||
input_variables=["transcript", "analysis"], | ||
template=config.get("rewrite_prompt_template", "Rewrite the podcast transcript by applying only the following recommendations. Refrain from shortening the transcript too much.\n\nRecommendations: \n\n{analysis}\n\nOriginal Transcript: \n\n{transcript}\n\nRewritten Transcript:") | ||
) | ||
rewrite_chain = rewrite_prompt | llm | StrOutputParser() | ||
|
||
try: | ||
logger.debug("Executing analysis chain") | ||
analysis = analysis_chain.invoke({"transcript": transcript}) | ||
logger.debug(f"Successfully analyzed transcript: \n\n{analysis}") | ||
|
||
logger.debug("Executing rewriting chain") | ||
rewritten_response = rewrite_chain.invoke({"analysis": analysis, "transcript": transcript}) | ||
if not rewritten_response: | ||
logger.warning("Rewriting chain returned empty response") | ||
# Fall back to original | ||
rewritten_response = transcript | ||
logger.debug("Successfully rewrote transcript") | ||
logger.debug(f"Successfully rewrote transcript, BEFORE = \n\n{transcript}") | ||
logger.debug(f"Successfully rewrote transcript, AFTER = \n\n{rewritten_response}") | ||
except Exception as e: | ||
logger.error(f"Error in rewriting chain: {str(e)}") | ||
rewritten_response = transcript # Fall back to original | ||
|
||
final_transcript = self._fix_alternating_tags(rewritten_response) | ||
|
||
logger.debug("Completed transcript cleaning process") | ||
|
||
|
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.
Perhaps this code should not be in the
_clean_transcript_response
function