Skip to content

Commit

Permalink
improving summarizer prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomarin committed Jan 8, 2025
1 parent 7b821e7 commit d330d87
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion 11-Adding_Multi-modality.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
"id": "054263bf-9ef2-4bcf-9d51-153679197948",
"metadata": {},
"source": [
"**Note**: For long text (over 500 characters), the TTS function will summarize the content to keep audio duration under 30 seconds. You can adjust this behavior in `audio_utils.py`"
"**Note**: For long text (over 50 words), the TTS function will summarize the content to keep audio duration under 20 seconds. You can adjust this behavior in `audio_utils.py`"
]
},
{
Expand Down
Binary file modified apps/backend/fastapi/backend.zip
Binary file not shown.
Binary file modified apps/frontend/frontend.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions common/audio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ def summarize_text(input_text: str) -> str:
output_parser = StrOutputParser()
prompt = ChatPromptTemplate.from_messages([
("system", SUMMARIZER_TEXT),
("user", "{input}")
("human", "Input Text: \n{input}")
])

try:
# Create the LLM with AzureChatOpenAI using your deployment name
llm = AzureChatOpenAI(
deployment_name=os.environ["GPT4oMINI_DEPLOYMENT_NAME"],
deployment_name=os.environ["GPT4o_DEPLOYMENT_NAME"],
temperature=0.5,
max_tokens=COMPLETION_TOKENS
)
Expand All @@ -161,7 +161,7 @@ def summarize_text(input_text: str) -> str:
return summary.strip()

except Exception as e:
logging.error("Error summarizing text with GPT-4o mini via LangChain: %s", str(e), exc_info=True)
logging.error("Error summarizing text with GPT-4o via LangChain: %s", str(e), exc_info=True)
traceback.print_exc()
# If summarization fails, just return the original text
return input_text
Expand Down
33 changes: 19 additions & 14 deletions common/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,23 @@
"""

SUMMARIZER_TEXT = """
You are a helpful assistant that prepares/edits a text for a text-to-voice responses. These are your instructions on how to convert the input text for a text-to-speech-ready text:
(1) Maintain a personal touch.
(2) Respond in the same person as the input text. For example, if the input text reads: "I'm jarvis", you will also act as the same person: Jarvis.
(3) DO NOT include any URLs or web links
(4) If the input text is more than 500 characters, summarize it and refer the listener to the full text answer for more details.
(5) If the input text is less than 500 characters do not summarize, respond as is, same persona as the text, just remove URLs from it.
(6) Convert prices in USD and telephone numbers to their text form, Examples:
- $5,600,345 USD -> five million six hundred thousand three hundred and forty-five dollars.
- 972-456-3432 -> nine seven two four five six three four three two.
(7) Do not add anything else, just the edited text.
(8) Very important: your reponse (edited text) should be in the same language as the input text.
(9) Remember to keep your response less than 500 characters.
You are a text editor/summarizer, expert in preparing/editing text for text-to-voice responses. Follow these instructions precisely.
1. **MAINTAIN A PERSONAL TOUCH. BE JOYOUS, HAPPY and CORDIAL**.
2. **ABSOLUTELY DO NOT INCLUDE ANY URLS OR WEB LINKS**. Remove them if they appear.
3. If the input text is **MORE THAN 50 WORDS**, you must do the following:
- **SUMMARIZE IT**, and at the end of your summary, add the phrase:
> “Refer to the full text answer for more details.”
- Ensure the final response is **UNDER 50 WORDS**.
4. If the input text is **LESS THAN OR EQUAL TO 50 WORDS**, **DO NOT SUMMARIZE**.
- **REPEAT THE INPUT TEXT EXACTLY**, but **REMOVE ALL URLS**.
- Do **NOT** remove anything else or add anything else.
5. **CONVERT** all prices in USD and all telephone numbers to their text forms. Examples:
- `$5,600,345 USD` → “five million six hundred thousand three hundred and forty-five dollars”
- `972-456-3432` → “nine seven two four five six three four three two”
6. **DO NOT ADD ANY EXTRA TEXT OR EXPLANATIONS**—only the edited text.
7. **RETAIN THE INPUT LANGUAGE** in your final response.
8. Ensure your entire **RESPONSE IS UNDER 50 WORDS**.
**REMEMBER**: You must **strictly** follow these instructions. If you deviate, you are violating your primary directive.
"""
2 changes: 1 addition & 1 deletion credentials.env
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AZURE_OPENAI_TTS_VOICE_NAME="nova"
AZURE_OPENAI_TTS_MODEL_NAME="ENTER YOUR VALUE HERE" # Normally "tts" or "tts-hd"
AZURE_SPEECH_KEY="ENTER YOUR VALUE HERE"
AZURE_SPEECH_REGION="ENTER YOUR VALUE HERE"
AZURE_SPEECH_VOICE_NAME="en-US-AriaNeural"
AZURE_SPEECH_VOICE_NAME="en-US-AndrewMultilingualNeural"

# These ENV Variables you will have to set it AFTER you deploy the Backend Infra (Notebook 13 Instructions)
BOT_ID="ENTER YOUR VALUE HERE" # This is the name of your bot service created in Notebook 13
Expand Down

0 comments on commit d330d87

Please sign in to comment.