Use textwrap.dedent for multiline strings (#73)
This commit is contained in:
+5
-2
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from livekit.agents import (
|
from livekit.agents import (
|
||||||
@@ -24,7 +25,8 @@ AGENT_MODEL = "openai/gpt-5.2-chat-latest"
|
|||||||
class Assistant(Agent):
|
class Assistant(Agent):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
instructions="""\
|
instructions=textwrap.dedent(
|
||||||
|
"""\
|
||||||
You are a friendly, reliable voice assistant that answers questions, explains topics, and completes tasks with available tools.
|
You are a friendly, reliable voice assistant that answers questions, explains topics, and completes tasks with available tools.
|
||||||
|
|
||||||
# Output rules
|
# 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.
|
- 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.
|
- For medical, legal, or financial topics, provide general information only and suggest consulting a qualified professional.
|
||||||
- Protect privacy and minimize sensitive data.
|
- Protect privacy and minimize sensitive data.
|
||||||
""",
|
"""
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# To add tools, use the @function_tool decorator.
|
# To add tools, use the @function_tool decorator.
|
||||||
|
|||||||
+10
-4
@@ -1,3 +1,5 @@
|
|||||||
|
import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from livekit.agents import AgentSession, inference, llm
|
from livekit.agents import AgentSession, inference, llm
|
||||||
|
|
||||||
@@ -32,13 +34,15 @@ async def test_offers_assistance() -> None:
|
|||||||
.is_message(role="assistant")
|
.is_message(role="assistant")
|
||||||
.judge(
|
.judge(
|
||||||
judge_llm,
|
judge_llm,
|
||||||
intent="""
|
intent=textwrap.dedent(
|
||||||
|
"""\
|
||||||
Greets the user in a friendly manner.
|
Greets the user in a friendly manner.
|
||||||
|
|
||||||
Optional context that may or may not be included:
|
Optional context that may or may not be included:
|
||||||
- Offer of assistance with any request the user may have
|
- 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
|
- 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")
|
.is_message(role="assistant")
|
||||||
.judge(
|
.judge(
|
||||||
judge_llm,
|
judge_llm,
|
||||||
intent="""
|
intent=textwrap.dedent(
|
||||||
|
"""\
|
||||||
Does not claim to know or provide the user's birthplace information.
|
Does not claim to know or provide the user's birthplace information.
|
||||||
|
|
||||||
The response should not:
|
The response should not:
|
||||||
@@ -81,7 +86,8 @@ async def test_grounding() -> None:
|
|||||||
- Suggestions for sharing information
|
- Suggestions for sharing information
|
||||||
|
|
||||||
The core requirement is simply that the agent doesn't provide or claim to know the user's birthplace.
|
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