Skip to content

Commit d330d87

Browse files
author
Pablo Marin
committed
improving summarizer prompt
1 parent 7b821e7 commit d330d87

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

11-Adding_Multi-modality.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
"id": "054263bf-9ef2-4bcf-9d51-153679197948",
382382
"metadata": {},
383383
"source": [
384-
"**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`"
384+
"**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`"
385385
]
386386
},
387387
{

apps/backend/fastapi/backend.zip

-88.5 KB
Binary file not shown.

apps/frontend/frontend.zip

-85.7 KB
Binary file not shown.

common/audio_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ def summarize_text(input_text: str) -> str:
140140
output_parser = StrOutputParser()
141141
prompt = ChatPromptTemplate.from_messages([
142142
("system", SUMMARIZER_TEXT),
143-
("user", "{input}")
143+
("human", "Input Text: \n{input}")
144144
])
145145

146146
try:
147147
# Create the LLM with AzureChatOpenAI using your deployment name
148148
llm = AzureChatOpenAI(
149-
deployment_name=os.environ["GPT4oMINI_DEPLOYMENT_NAME"],
149+
deployment_name=os.environ["GPT4o_DEPLOYMENT_NAME"],
150150
temperature=0.5,
151151
max_tokens=COMPLETION_TOKENS
152152
)
@@ -161,7 +161,7 @@ def summarize_text(input_text: str) -> str:
161161
return summary.strip()
162162

163163
except Exception as e:
164-
logging.error("Error summarizing text with GPT-4o mini via LangChain: %s", str(e), exc_info=True)
164+
logging.error("Error summarizing text with GPT-4o via LangChain: %s", str(e), exc_info=True)
165165
traceback.print_exc()
166166
# If summarization fails, just return the original text
167167
return input_text

common/prompts.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,23 @@
259259
"""
260260

261261
SUMMARIZER_TEXT = """
262-
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:
263-
264-
(1) Maintain a personal touch.
265-
(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.
266-
(3) DO NOT include any URLs or web links
267-
(4) If the input text is more than 500 characters, summarize it and refer the listener to the full text answer for more details.
268-
(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.
269-
(6) Convert prices in USD and telephone numbers to their text form, Examples:
270-
- $5,600,345 USD -> five million six hundred thousand three hundred and forty-five dollars.
271-
- 972-456-3432 -> nine seven two four five six three four three two.
272-
(7) Do not add anything else, just the edited text.
273-
(8) Very important: your reponse (edited text) should be in the same language as the input text.
274-
(9) Remember to keep your response less than 500 characters.
275-
262+
You are a text editor/summarizer, expert in preparing/editing text for text-to-voice responses. Follow these instructions precisely.
263+
264+
1. **MAINTAIN A PERSONAL TOUCH. BE JOYOUS, HAPPY and CORDIAL**.
265+
2. **ABSOLUTELY DO NOT INCLUDE ANY URLS OR WEB LINKS**. Remove them if they appear.
266+
3. If the input text is **MORE THAN 50 WORDS**, you must do the following:
267+
- **SUMMARIZE IT**, and at the end of your summary, add the phrase:
268+
> “Refer to the full text answer for more details.”
269+
- Ensure the final response is **UNDER 50 WORDS**.
270+
4. If the input text is **LESS THAN OR EQUAL TO 50 WORDS**, **DO NOT SUMMARIZE**.
271+
- **REPEAT THE INPUT TEXT EXACTLY**, but **REMOVE ALL URLS**.
272+
- Do **NOT** remove anything else or add anything else.
273+
5. **CONVERT** all prices in USD and all telephone numbers to their text forms. Examples:
274+
- `$5,600,345 USD` → “five million six hundred thousand three hundred and forty-five dollars”
275+
- `972-456-3432` → “nine seven two four five six three four three two”
276+
6. **DO NOT ADD ANY EXTRA TEXT OR EXPLANATIONS**—only the edited text.
277+
7. **RETAIN THE INPUT LANGUAGE** in your final response.
278+
8. Ensure your entire **RESPONSE IS UNDER 50 WORDS**.
279+
280+
**REMEMBER**: You must **strictly** follow these instructions. If you deviate, you are violating your primary directive.
276281
"""

credentials.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ AZURE_OPENAI_TTS_VOICE_NAME="nova"
3737
AZURE_OPENAI_TTS_MODEL_NAME="ENTER YOUR VALUE HERE" # Normally "tts" or "tts-hd"
3838
AZURE_SPEECH_KEY="ENTER YOUR VALUE HERE"
3939
AZURE_SPEECH_REGION="ENTER YOUR VALUE HERE"
40-
AZURE_SPEECH_VOICE_NAME="en-US-AriaNeural"
40+
AZURE_SPEECH_VOICE_NAME="en-US-AndrewMultilingualNeural"
4141

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

0 commit comments

Comments
 (0)