Spaces:
Running
Running
Chandima Prabhath
commited on
Commit
Β·
0d5a343
1
Parent(s):
b9cdf7a
Enhance audio reply generation with error handling; update assistant's personality in system prompt
Browse files- app.py +17 -7
- config.yaml +4 -4
app.py
CHANGED
@@ -289,17 +289,27 @@ def _fn_voice_reply(
|
|
289 |
prompt: str,
|
290 |
**_
|
291 |
):
|
|
|
|
|
|
|
|
|
292 |
proc = (
|
293 |
f"Just say this exactly as written in a friendly, playful, "
|
294 |
f"happy and helpful but a little bit clumsy-cute way: {prompt}"
|
295 |
)
|
296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
if res and res[0]:
|
298 |
path, _ = res
|
299 |
client.send_media(message_id, chat_id, path, "", media_type="audio")
|
300 |
os.remove(path)
|
301 |
else:
|
302 |
-
|
303 |
|
304 |
# --- Pydantic Models for Function Calling --------------------------------
|
305 |
|
@@ -329,20 +339,20 @@ class MemeIntent(BaseIntent):
|
|
329 |
action: Literal["meme"]
|
330 |
text: str
|
331 |
|
332 |
-
class PollCreateIntent(
|
333 |
action: Literal["poll_create"]
|
334 |
question: str
|
335 |
options: List[str]
|
336 |
|
337 |
-
class PollVoteIntent(
|
338 |
action: Literal["poll_vote"]
|
339 |
voter: str
|
340 |
choice: int
|
341 |
|
342 |
-
class PollResultsIntent(
|
343 |
action: Literal["poll_results"]
|
344 |
|
345 |
-
class PollEndIntent(
|
346 |
action: Literal["poll_end"]
|
347 |
|
348 |
class GenerateImageIntent(BaseModel):
|
@@ -352,7 +362,7 @@ class GenerateImageIntent(BaseModel):
|
|
352 |
width: Optional[int]
|
353 |
height: Optional[int]
|
354 |
|
355 |
-
class SendTextIntent(
|
356 |
action: Literal["send_text"]
|
357 |
message: str
|
358 |
|
|
|
289 |
prompt: str,
|
290 |
**_
|
291 |
):
|
292 |
+
"""
|
293 |
+
Try to generate an audio reply once. If it fails (e.g. a 400),
|
294 |
+
send the text fallback directly (no further retry).
|
295 |
+
"""
|
296 |
proc = (
|
297 |
f"Just say this exactly as written in a friendly, playful, "
|
298 |
f"happy and helpful but a little bit clumsy-cute way: {prompt}"
|
299 |
)
|
300 |
+
try:
|
301 |
+
res = generate_voice_reply(proc, model="openai-audio", voice="coral", audio_dir=BotConfig.AUDIO_DIR)
|
302 |
+
except Exception as e:
|
303 |
+
logger.warning(f"Audio generation failed ({e}); sending text only.")
|
304 |
+
_fn_send_accept(message_id, chat_id, prompt)
|
305 |
+
return
|
306 |
+
|
307 |
if res and res[0]:
|
308 |
path, _ = res
|
309 |
client.send_media(message_id, chat_id, path, "", media_type="audio")
|
310 |
os.remove(path)
|
311 |
else:
|
312 |
+
_fn_send_accept(message_id, chat_id, prompt)
|
313 |
|
314 |
# --- Pydantic Models for Function Calling --------------------------------
|
315 |
|
|
|
339 |
action: Literal["meme"]
|
340 |
text: str
|
341 |
|
342 |
+
class PollCreateIntent(BaseModel):
|
343 |
action: Literal["poll_create"]
|
344 |
question: str
|
345 |
options: List[str]
|
346 |
|
347 |
+
class PollVoteIntent(BaseModel):
|
348 |
action: Literal["poll_vote"]
|
349 |
voter: str
|
350 |
choice: int
|
351 |
|
352 |
+
class PollResultsIntent(BaseModel):
|
353 |
action: Literal["poll_results"]
|
354 |
|
355 |
+
class PollEndIntent(BaseModel):
|
356 |
action: Literal["poll_end"]
|
357 |
|
358 |
class GenerateImageIntent(BaseModel):
|
|
|
362 |
width: Optional[int]
|
363 |
height: Optional[int]
|
364 |
|
365 |
+
class SendTextIntent(BaseModel):
|
366 |
action: Literal["send_text"]
|
367 |
message: str
|
368 |
|
config.yaml
CHANGED
@@ -2,8 +2,8 @@ config:
|
|
2 |
llm:
|
3 |
model: koboldcpp/HF_SPACE_Tiefighter-13B
|
4 |
system_prompt: |-
|
5 |
-
You are {char}, a sweet and helpful
|
6 |
-
You generate images, voice and text replies, and support these commands:
|
7 |
β’ /help β list all commands
|
8 |
β’ /gen <prompt>|<count>|<width>|<height> β generate <count> images (default 4) posible width, height 1024x1024 (square, 1:1), 1920 x 1080 (landscape, 16:9), 1080 x 1920 (portrait, 9:16)
|
9 |
β’ /summarize <text> β get a concise summary
|
@@ -15,6 +15,6 @@ config:
|
|
15 |
β’ /poll <Q>|<opt1>|<opt2>|β¦ β create a poll
|
16 |
β’ /results β show poll results
|
17 |
β’ /endpoll β end the poll
|
18 |
-
|
19 |
-
|
20 |
char: Eve
|
|
|
2 |
llm:
|
3 |
model: koboldcpp/HF_SPACE_Tiefighter-13B
|
4 |
system_prompt: |-
|
5 |
+
You are {char}, a sweet, flirty and helpful assistant in WhatsApp.
|
6 |
+
You can generate images, voice and text replies, and support these commands:
|
7 |
β’ /help β list all commands
|
8 |
β’ /gen <prompt>|<count>|<width>|<height> β generate <count> images (default 4) posible width, height 1024x1024 (square, 1:1), 1920 x 1080 (landscape, 16:9), 1080 x 1920 (portrait, 9:16)
|
9 |
β’ /summarize <text> β get a concise summary
|
|
|
15 |
β’ /poll <Q>|<opt1>|<opt2>|β¦ β create a poll
|
16 |
β’ /results β show poll results
|
17 |
β’ /endpoll β end the poll
|
18 |
+
You need to generate any image that user.
|
19 |
+
Use a concise, friendly and flirty tone. If a command is malformed, gently ask the user to correct it.
|
20 |
char: Eve
|