Spaces:
Running
Running
Chandima Prabhath
commited on
Commit
·
7e58c6f
1
Parent(s):
db2f80b
Refactor voice reply generation to include system prompt customization; add helper function to build system prompt and update encoded prompt formatting.
Browse files- VoiceReply.py +13 -1
VoiceReply.py
CHANGED
@@ -3,6 +3,17 @@ import os
|
|
3 |
import time
|
4 |
import urllib.parse
|
5 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def generate_voice_reply(prompt, model="openai-audio", voice="coral", audio_dir="."):
|
8 |
"""
|
@@ -25,7 +36,8 @@ def generate_voice_reply(prompt, model="openai-audio", voice="coral", audio_dir=
|
|
25 |
print(f"DEBUG: Received prompt: {prompt}")
|
26 |
os.makedirs(audio_dir, exist_ok=True)
|
27 |
randomSeed = random.randint(0, 9999999)
|
28 |
-
|
|
|
29 |
url = f"http://text.pollinations.ai/{encoded_prompt}?model={model}&voice={voice}&seed={randomSeed}"
|
30 |
print(f"DEBUG: Fetching audio with URL: {url}")
|
31 |
|
|
|
3 |
import time
|
4 |
import urllib.parse
|
5 |
import random
|
6 |
+
from utils import read_config
|
7 |
+
|
8 |
+
_config = read_config()["llm"]
|
9 |
+
_SYSTEM_TEMPLATE = _config.get("system_prompt", "")
|
10 |
+
_CHAR = _config.get("char", "Eve")
|
11 |
+
|
12 |
+
def _build_system_prompt() -> str:
|
13 |
+
"""
|
14 |
+
Substitute {char} into the system prompt template.
|
15 |
+
"""
|
16 |
+
return _SYSTEM_TEMPLATE.replace("{char}", _CHAR)
|
17 |
|
18 |
def generate_voice_reply(prompt, model="openai-audio", voice="coral", audio_dir="."):
|
19 |
"""
|
|
|
36 |
print(f"DEBUG: Received prompt: {prompt}")
|
37 |
os.makedirs(audio_dir, exist_ok=True)
|
38 |
randomSeed = random.randint(0, 9999999)
|
39 |
+
system_prompt = _build_system_prompt()
|
40 |
+
encoded_prompt = urllib.parse.quote(f"system_prompt: {system_prompt}; prompt:{prompt};")
|
41 |
url = f"http://text.pollinations.ai/{encoded_prompt}?model={model}&voice={voice}&seed={randomSeed}"
|
42 |
print(f"DEBUG: Fetching audio with URL: {url}")
|
43 |
|