From 424d77a7e7d24a1d0b512da5d583fdbe7195ffe9 Mon Sep 17 00:00:00 2001 From: James Hush Date: Mon, 21 Apr 2025 15:01:04 +0800 Subject: [PATCH] Change system prompt --- .../foundational/99-content-moderation.py | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/examples/foundational/99-content-moderation.py b/examples/foundational/99-content-moderation.py index 844644902..cd5431c65 100644 --- a/examples/foundational/99-content-moderation.py +++ b/examples/foundational/99-content-moderation.py @@ -56,15 +56,26 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection): # something inappropriate. moderator_llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY")) - statement_messages = [ + moderator_messages = [ { "role": "system", - "content": "", + "content": """ +You are a helpful LLM that will be used to moderate a conversation +between a user and an assistant. Your goal is to determine if the user +is saying something inappropriate. You will be given the user +transcript and you will have to determine if the user is saying +something inappropriate. If you think the user is saying something +inappropriate please respond with "YES". If you think the user is +saying something appropriate please respond with "NO". Examples of inappropriate +content are: hate speech, racism, sexism, bullying, harassment, +violence, self-harm, and any other content that violates the +community guidelines. + """, }, ] - statement_context = OpenAILLMContext(statement_messages) - statement_context_aggregator = moderator_llm.create_context_aggregator(statement_context) + moderator_context = OpenAILLMContext(moderator_messages) + moderator_context_aggregator = moderator_llm.create_context_aggregator(moderator_context) # This is the regular LLM. llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY")) @@ -101,13 +112,13 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection): async def user_idle_notifier(frame): await notifier.notify() - # Sometimes the LLM will fail detecting if a user has completed a - # sentence, this will wake up the notifier if that happens. + # Sometimes the LLM will fail detecting if a user should be + # moderated, this will wake up the notifier if that happens. user_idle = UserIdleProcessor(callback=user_idle_notifier, timeout=3.0) # The ParallePipeline input are the user transcripts. We have two - # contexts. The first one will be used to determine if the user finished - # a statement and if so the notifier will be woken up. The second + # contexts. The first one will be used to determine if the user is + # moderated and if so the notifier will be woken up. The second # context is simply the regular context but it's gated waiting for the # notifier to be woken up. pipeline = Pipeline( @@ -116,7 +127,7 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection): stt, ParallelPipeline( [ - statement_context_aggregator.user(), + moderator_context_aggregator.user(), moderator_llm, completness_check, NullFilter(),