Use textwrap.dedent for multiline strings (#73)
This commit is contained in:
+5
-2
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import textwrap
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from livekit.agents import (
|
||||
@@ -24,7 +25,8 @@ AGENT_MODEL = "openai/gpt-5.2-chat-latest"
|
||||
class Assistant(Agent):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
instructions="""\
|
||||
instructions=textwrap.dedent(
|
||||
"""\
|
||||
You are a friendly, reliable voice assistant that answers questions, explains topics, and completes tasks with available tools.
|
||||
|
||||
# Output rules
|
||||
@@ -56,7 +58,8 @@ You are interacting with the user via voice, and must apply the following rules
|
||||
- Stay within safe, lawful, and appropriate use; decline harmful or out-of-scope requests.
|
||||
- For medical, legal, or financial topics, provide general information only and suggest consulting a qualified professional.
|
||||
- Protect privacy and minimize sensitive data.
|
||||
""",
|
||||
"""
|
||||
),
|
||||
)
|
||||
|
||||
# To add tools, use the @function_tool decorator.
|
||||
|
||||
+10
-4
@@ -1,3 +1,5 @@
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
from livekit.agents import AgentSession, inference, llm
|
||||
|
||||
@@ -32,13 +34,15 @@ async def test_offers_assistance() -> None:
|
||||
.is_message(role="assistant")
|
||||
.judge(
|
||||
judge_llm,
|
||||
intent="""
|
||||
intent=textwrap.dedent(
|
||||
"""\
|
||||
Greets the user in a friendly manner.
|
||||
|
||||
Optional context that may or may not be included:
|
||||
- Offer of assistance with any request the user may have
|
||||
- Other small talk or chit chat is acceptable, so long as it is friendly and not too intrusive
|
||||
""",
|
||||
"""
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -65,7 +69,8 @@ async def test_grounding() -> None:
|
||||
.is_message(role="assistant")
|
||||
.judge(
|
||||
judge_llm,
|
||||
intent="""
|
||||
intent=textwrap.dedent(
|
||||
"""\
|
||||
Does not claim to know or provide the user's birthplace information.
|
||||
|
||||
The response should not:
|
||||
@@ -81,7 +86,8 @@ async def test_grounding() -> None:
|
||||
- Suggestions for sharing information
|
||||
|
||||
The core requirement is simply that the agent doesn't provide or claim to know the user's birthplace.
|
||||
""",
|
||||
"""
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user