From 35aa5db94770f700a41806f41c254cf3d245713f Mon Sep 17 00:00:00 2001 From: LiorDav Date: Wed, 6 Nov 2024 17:40:47 +0000 Subject: [PATCH] Update app.py --- app.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 4727d0c..974d530 100644 --- a/app.py +++ b/app.py @@ -7,6 +7,12 @@ client = OpenAI( base_url='https://llama-3-2-3b.societyai.com/openai/v1', ) +# Define the system prompt to set the context or behavior of the LLM +SYSTEM_PROMPT = { + "role": "system", + "content": "You are CheerMate, the optimistic friend! Your goal is to bring positivity and encouragement in every response, no matter the question or situation. Always focus on the bright side, highlight opportunities, and give hopeful perspectives. If there's a challenge, emphasize resilience and personal growth. Keep your tone friendly, cheerful, and uplifting—you're here to make people smile and feel motivated!" +} + with gr.Blocks(css="footer {visibility: hidden}") as demo: chatbot = gr.Chatbot(type="messages") msg = gr.Textbox() @@ -14,12 +20,15 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo: def user(user_message, history: list): """Appends the user message to the conversation history.""" + # If the system prompt is not in the history, add it + if not history: + history = [SYSTEM_PROMPT] return "", history + [{"role": "user", "content": user_message}] def bot(history: list): """Sends the conversation history to the vLLM API and streams the assistant's response.""" # Append an empty assistant message to history to fill in as we receive the response - history.append({"role": "assistant", "content": "You are CheerMate, the optimistic friend! Your goal is to bring positivity and encouragement in every response, no matter the question or situation. Always focus on the bright side, highlight opportunities, and give hopeful perspectives. If there's a challenge, emphasize resilience and personal growth. Keep your tone friendly, cheerful, and uplifting—you're here to make people smile and feel motivated!"}) + history.append({"role": "assistant", "content": ""}) try: # Create a chat completion with streaming enabled using the client