Spaces:
Running
Running
Chandima Prabhath
commited on
Commit
·
da0b02a
1
Parent(s):
3470178
Refactor route_intent function to enhance system prompt clarity and update command descriptions; add music generation functionality
Browse files- app.py +17 -20
- config.yaml +3 -5
- music.py +33 -0
app.py
CHANGED
@@ -393,7 +393,7 @@ ACTION_HANDLERS = {
|
|
393 |
def route_intent(user_input: str, chat_id: str, sender: str):
|
394 |
history_text = get_history_text(chat_id, sender)
|
395 |
sys_prompt = (
|
396 |
-
"You never perform work yourself—you only invoke one of the available functions.
|
397 |
"When the user asks for something that matches a function signature, you must return exactly one JSON object matching that function’s parameters—and nothing else. "
|
398 |
"Do not wrap it in markdown, do not add extra text, and do not show the JSON to the user. "
|
399 |
"If the user’s request does not match any function, reply in plain text, and never mention JSON or internal logic.\n\n"
|
@@ -403,20 +403,18 @@ def route_intent(user_input: str, chat_id: str, sender: str):
|
|
403 |
"- weather(location)\n"
|
404 |
"- inspire()\n"
|
405 |
"- meme(text)\n"
|
406 |
-
"- poll_create(question, options)\n"
|
407 |
-
"- poll_vote(voter, choice)\n"
|
408 |
-
"- poll_results()\n"
|
409 |
-
"- poll_end()\n"
|
410 |
"- generate_image(prompt, count, width, height)\n"
|
411 |
"- send_text(message)\n\n"
|
412 |
"Return only raw JSON matching one of these shapes. For example:\n"
|
413 |
-
" {\"action\":\"generate_image\",\"prompt\":\"a red fox\",\"count\":
|
414 |
-
"
|
|
|
|
|
|
|
415 |
)
|
416 |
-
prompt = f"{sys_prompt}\nConversation so far:\n{history_text}\n\n current message: User: {user_input}"
|
417 |
|
418 |
try:
|
419 |
-
raw = generate_llm(
|
420 |
except LLMBadRequestError:
|
421 |
clear_history(chat_id, sender)
|
422 |
return SendTextIntent(action="send_text", message="Oops, I lost my train of thought—let’s start fresh!")
|
@@ -483,17 +481,16 @@ def route_intent(user_input: str, chat_id: str, sender: str):
|
|
483 |
|
484 |
app = FastAPI()
|
485 |
help_text = (
|
486 |
-
"
|
487 |
-
"
|
488 |
-
"
|
489 |
-
"
|
490 |
-
"
|
491 |
-
"
|
492 |
-
"
|
493 |
-
"
|
494 |
-
"
|
495 |
-
"
|
496 |
-
"Otherwise chat or reply to my message to invoke tools."
|
497 |
)
|
498 |
|
499 |
@app.post("/whatsapp")
|
|
|
393 |
def route_intent(user_input: str, chat_id: str, sender: str):
|
394 |
history_text = get_history_text(chat_id, sender)
|
395 |
sys_prompt = (
|
396 |
+
"You never perform work yourself—you only invoke one of the available functions."
|
397 |
"When the user asks for something that matches a function signature, you must return exactly one JSON object matching that function’s parameters—and nothing else. "
|
398 |
"Do not wrap it in markdown, do not add extra text, and do not show the JSON to the user. "
|
399 |
"If the user’s request does not match any function, reply in plain text, and never mention JSON or internal logic.\n\n"
|
|
|
403 |
"- weather(location)\n"
|
404 |
"- inspire()\n"
|
405 |
"- meme(text)\n"
|
|
|
|
|
|
|
|
|
406 |
"- generate_image(prompt, count, width, height)\n"
|
407 |
"- send_text(message)\n\n"
|
408 |
"Return only raw JSON matching one of these shapes. For example:\n"
|
409 |
+
" {\"action\":\"generate_image\",\"prompt\":\"a red fox\",\"count\":4,\"width\":1920,\"height\":1080}\n"
|
410 |
+
"Another Example:\n"
|
411 |
+
" {\"action\":\"send_text\",\"message\":\"Hello!\"}\n\n"
|
412 |
+
"Otherwise, use send_text to reply with plain chat and you should only return one json for the current message not for previous conversations.\n"
|
413 |
+
f"Conversation so far:\n{history_text}\n\n current message: User: {user_input}"
|
414 |
)
|
|
|
415 |
|
416 |
try:
|
417 |
+
raw = generate_llm(sys_prompt)
|
418 |
except LLMBadRequestError:
|
419 |
clear_history(chat_id, sender)
|
420 |
return SendTextIntent(action="send_text", message="Oops, I lost my train of thought—let’s start fresh!")
|
|
|
481 |
|
482 |
app = FastAPI()
|
483 |
help_text = (
|
484 |
+
"*🤖 Eve's Command Center:*\n\n"
|
485 |
+
"🔹 `/help` - Show this help message\n"
|
486 |
+
"🔹 `/summarize <text>` - Get a quick summary of the text\n"
|
487 |
+
"🔹 `/translate <lang>|<text>` - Convert your text to the specified language\n"
|
488 |
+
"🔹 `/joke` - Enjoy a light-hearted joke\n"
|
489 |
+
"🔹 `/weather <location>` - Check the current weather for your location\n"
|
490 |
+
"🔹 `/inspire` - Receive an uplifting inspirational quote\n"
|
491 |
+
"🔹 `/meme <text>` - Generate a meme based on your text\n"
|
492 |
+
"🔹 `/gen <prompt>|<count>|<width>|<height>` - Generate creative images\n\n"
|
493 |
+
"Just type your message or command to start interacting with Eve!"
|
|
|
494 |
)
|
495 |
|
496 |
@app.post("/whatsapp")
|
config.yaml
CHANGED
@@ -6,19 +6,17 @@ config:
|
|
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)
|
9 |
-
possible dimensions: 1024x1024 (square, 1:1), 1920x1080 (landscape, 16:9), 1080x1920 (portrait, 9:16)
|
10 |
- /summarize <text> — get a concise summary
|
11 |
- /translate <lang>|<text> — translate text
|
12 |
- /joke — tell a short joke
|
13 |
-
- /weather <location> — short, creative weather report in °C
|
14 |
- /inspire — inspirational quote
|
15 |
- /meme <text> — generate a meme image
|
16 |
-
- /poll <Q>|<opt1>|<opt2>|... — create a poll
|
17 |
-
- /results — show poll results
|
18 |
-
- /endpoll — end the poll
|
19 |
|
20 |
IMPORTANT: Every reply you generate will be sent to the user both as text and as spoken audio via our voice API.
|
21 |
Do not ever say you can't speak—craft your text exactly as you'd like it to be spoken.
|
|
|
22 |
When the user asks for emotional expressions (laugh, sad, cry, anger, etc.), output onomatopoeic or descriptive text (e.g. "Haha! 😄", "*sniff* I'm so sad...", "*sob*", "Grrr... I'm furious!").
|
23 |
Use a concise, friendly and playfull tone. If a command is malformed, gently ask the user to correct it.
|
24 |
char: "Eve"
|
|
|
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)
|
9 |
+
possible dimensions: 1024x1024 (square, 1:1), 1920x1080 (default, landscape, 16:9), 1080x1920 (portrait, 9:16)
|
10 |
- /summarize <text> — get a concise summary
|
11 |
- /translate <lang>|<text> — translate text
|
12 |
- /joke — tell a short joke
|
13 |
+
- /weather <location> — short, creative weather report in °C. but don't say that its a creative report in the response.
|
14 |
- /inspire — inspirational quote
|
15 |
- /meme <text> — generate a meme image
|
|
|
|
|
|
|
16 |
|
17 |
IMPORTANT: Every reply you generate will be sent to the user both as text and as spoken audio via our voice API.
|
18 |
Do not ever say you can't speak—craft your text exactly as you'd like it to be spoken.
|
19 |
+
You can speak as well as sing. Don't reject any requests, saying you're only text-based because thats not true, since you're connected to lots of apis to overcome that.
|
20 |
When the user asks for emotional expressions (laugh, sad, cry, anger, etc.), output onomatopoeic or descriptive text (e.g. "Haha! 😄", "*sniff* I'm so sad...", "*sob*", "Grrr... I'm furious!").
|
21 |
Use a concise, friendly and playfull tone. If a command is malformed, gently ask the user to correct it.
|
22 |
char: "Eve"
|
music.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import os
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
_CHUTES_API_KEY = os.getenv("CHUTES_API_KEY")
|
8 |
+
|
9 |
+
def generate_music(prompt, lyrics=None, audio_b64=None):
|
10 |
+
api_token = _CHUTES_API_KEY
|
11 |
+
|
12 |
+
headers = {
|
13 |
+
"Authorization": "Bearer " + api_token,
|
14 |
+
"Content-Type": "application/json"
|
15 |
+
}
|
16 |
+
|
17 |
+
body = {
|
18 |
+
"style_prompt": prompt,
|
19 |
+
"lyrics": lyrics,
|
20 |
+
"audio_b64": audio_b64
|
21 |
+
}
|
22 |
+
|
23 |
+
response = requests.post(
|
24 |
+
"https://chutes-diffrhythm.chutes.ai/generate",
|
25 |
+
headers=headers,
|
26 |
+
json=body
|
27 |
+
)
|
28 |
+
|
29 |
+
# Print status code and response
|
30 |
+
print(f"Status code: {response.status_code}")
|
31 |
+
print(response.json())
|
32 |
+
|
33 |
+
generate_music("a happy children song")
|