Skip to content

Commit 90d8192

Browse files
committed
start moving prompts into data files
1 parent d37de8a commit 90d8192

20 files changed

+983
-328
lines changed

client/src/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<title>Text World</title>
4+
<title>TaleWeave AI</title>
55
<link href="./bundle/main.css" rel="stylesheet">
66
</head>
77
<body>

prompts/discord-en-us.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
prompts:
2+
discord_help: |
3+
**Commands:**
4+
- `!help` - Show this help message
5+
- `!{{ bot_name }}` - Show the active world
6+
- `!join <character>` - Join the game as the specified character
7+
- `!leave` - Leave the game
8+
discord_join_error_none: You must specify a character!
9+
discord_join_error_not_found: Character {{ character }} was not found!
10+
discord_join_error_taken: Someone is already playing as {{ character }}!
11+
discord_join_result: |
12+
{{ event.client }} is now playing as {{ event.character }}!
13+
discord_join_title: |
14+
Player Joined
15+
discord_leave_error_none: You are not playing the game yet!
16+
discord_leave_result: |
17+
{{ event.client }} has left the game! {{ event.character }} is now being played by an LLM.
18+
discord_leave_title: |
19+
Player Left
20+
discord_user_new: |
21+
You are not playing the game yet! Use `!join <character>` to start playing.
22+
discord_world_active: |
23+
Hello! Welcome to {{ bot_name }}. The active world is `{{ world.name }}` (theme: {{ world.theme }})
24+
discord_world_none: Hello! Welcome to {{ bot_name }}. There is no active world yet.

prompts/llama-base.yml

+378
Large diffs are not rendered by default.

prompts/llama-quest.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
prompts:
2+
action_accept_quest_error_none: No quests are available at the moment.
3+
action_accept_quest_error_name: |
4+
{{character}} does not have a quest named "{{quest_name}}".
5+
action_accept_quest_error_room: |
6+
{{character}} is not in the room.
7+
action_accept_quest_result: |
8+
You have started the quest "{{quest_name}}".
9+
10+
action_submit_quest_error_active: |
11+
You do not have any active quests.
12+
action_submit_quest_error_none: No quests are available at the moment.
13+
action_submit_quest_error_name: |
14+
{{character}} does not have a quest named "{{quest_name}}".
15+
action_submit_quest_error_room: |
16+
{{character}} is not in the room.
17+
action_submit_quest_result: |
18+
You have completed the quest "{{quest_name}}".

taleweave/actions/base.py

+132-66
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
broadcast,
66
get_agent_for_character,
77
get_character_agent_for_name,
8+
get_prompt,
89
world_context,
910
)
1011
from taleweave.errors import ActionError
1112
from taleweave.utils.conversation import loop_conversation
13+
from taleweave.utils.prompt import format_prompt
1214
from taleweave.utils.search import (
1315
find_character_in_room,
1416
find_item_in_character,
@@ -17,7 +19,6 @@
1719
find_room,
1820
)
1921
from taleweave.utils.string import normalize_name
20-
from taleweave.utils.world import describe_entity
2122

2223
logger = getLogger(__name__)
2324

@@ -33,34 +34,65 @@ def action_examine(target: str) -> str:
3334
"""
3435

3536
with action_context() as (action_room, action_character):
36-
broadcast(f"{action_character.name} looks at {target}")
37+
broadcast(
38+
format_prompt(
39+
"action_examine_broadcast_action",
40+
action_character=action_character,
41+
target=target,
42+
)
43+
)
3744

3845
if normalize_name(target) == normalize_name(action_room.name):
39-
broadcast(f"{action_character.name} saw the {action_room.name} room")
40-
return describe_entity(action_room)
46+
broadcast(
47+
format_prompt(
48+
"action_examine_broadcast_room",
49+
action_character=action_character,
50+
action_room=action_room,
51+
)
52+
)
53+
return format_prompt("action_examine_result_room", action_room=action_room)
4154

4255
target_character = find_character_in_room(action_room, target)
4356
if target_character:
4457
broadcast(
45-
f"{action_character.name} saw the {target_character.name} character in the {action_room.name} room"
58+
format_prompt(
59+
"action_examine_broadcast_character",
60+
action_character=action_character,
61+
action_room=action_room,
62+
target_character=target_character,
63+
)
64+
)
65+
return format_prompt(
66+
"action_examine_result_character", target_character=target_character
4667
)
47-
return describe_entity(target_character)
4868

4969
target_item = find_item_in_room(action_room, target)
5070
if target_item:
5171
broadcast(
52-
f"{action_character.name} saw the {target_item.name} item in the {action_room.name} room"
72+
format_prompt(
73+
"action_examine_broadcast_item",
74+
action_character=action_character,
75+
action_room=action_room,
76+
target_item=target_item,
77+
)
5378
)
54-
return describe_entity(target_item)
79+
return format_prompt("action_examine_result_item", target_item=target_item)
5580

5681
target_item = find_item_in_character(action_character, target)
5782
if target_item:
5883
broadcast(
59-
f"{action_character.name} saw the {target_item.name} item in their inventory"
84+
format_prompt(
85+
"action_examine_broadcast_inventory",
86+
action_character=action_character,
87+
action_room=action_room,
88+
target_item=target_item,
89+
)
90+
)
91+
return format_prompt(
92+
"action_examine_result_inventory", target_item=target_item
6093
)
61-
return describe_entity(target_item)
6294

63-
return "You do not see that item or character in the room."
95+
return format_prompt("action_examine_error_target", target=target)
6496

6597

6698
def action_move(direction: str) -> str:
@@ -74,20 +106,36 @@ def action_move(direction: str) -> str:
74106
with world_context() as (action_world, action_room, action_character):
75107
portal = find_portal_in_room(action_room, direction)
76108
if not portal:
77-
raise ActionError(f"You cannot move {direction} from here.")
109+
portals = [p.name for p in action_room.portals]
110+
raise ActionError(
111+
format_prompt(
112+
"action_move_error_direction", direction=direction, portals=portals
113+
)
114+
)
78115

79-
destination_room = find_room(action_world, portal.destination)
80-
if not destination_room:
81-
raise ActionError(f"The {portal.destination} room does not exist.")
116+
dest_room = find_room(action_world, portal.destination)
117+
if not dest_room:
118+
raise ActionError(
119+
format_prompt(
120+
"action_move_error_room",
121+
direction=direction,
122+
destination=portal.destination,
123+
)
124+
)
82125

83126
broadcast(
84-
f"{action_character.name} moves through {direction} to {destination_room.name}"
127+
format_prompt(
128+
"action_move_broadcast",
129+
action_character=action_character,
130+
dest_room=dest_room,
131+
direction=direction,
132+
)
85133
)
86134
action_room.characters.remove(action_character)
87-
destination_room.characters.append(action_character)
135+
dest_room.characters.append(action_character)
88136

89-
return (
90-
f"You move through the {direction} and arrive at {destination_room.name}."
137+
return format_prompt(
138+
"action_move_result", direction=direction, dest_room=dest_room
91139
)
92140

93141

@@ -101,12 +149,20 @@ def action_take(item: str) -> str:
101149
with action_context() as (action_room, action_character):
102150
action_item = find_item_in_room(action_room, item)
103151
if not action_item:
104-
raise ActionError(f"The {item} item is not in the room.")
152+
raise ActionError(format_prompt("action_take_error_item", item=item))
105153

106-
broadcast(f"{action_character.name} takes the {item} item")
154+
broadcast(
155+
format_prompt(
156+
"action_take_broadcast",
157+
action_character=action_character,
158+
action_room=action_room,
159+
item=item,
160+
)
161+
)
107162
action_room.items.remove(action_item)
108163
action_character.items.append(action_item)
109-
return f"You take the {item} item and put it in your inventory."
164+
165+
return format_prompt("action_take_result", item=item)
110166

111167

112168
def action_ask(character: str, question: str) -> str:
@@ -122,27 +178,31 @@ def action_ask(character: str, question: str) -> str:
122178
# sanity checks
123179
question_character, question_agent = get_character_agent_for_name(character)
124180
if question_character == action_character:
125-
raise ActionError(
126-
"You cannot ask yourself a question. Stop talking to yourself. Try another action."
127-
)
181+
raise ActionError(format_prompt("action_ask_error_self"))
128182

129183
if not question_character:
130-
raise ActionError(f"The {character} character is not in the room.")
184+
raise ActionError(
185+
format_prompt("action_ask_error_target", character=character)
186+
)
131187

132188
if not question_agent:
133-
raise ActionError(f"The {character} character does not exist.")
189+
raise ActionError(
190+
format_prompt("action_ask_error_agent", character=character)
191+
)
134192

135-
broadcast(f"{action_character.name} asks {character}: {question}")
136-
first_prompt = (
137-
"{last_character.name} asks you: {response}\n"
138-
"Reply with your response to them. Reply with 'END' to end the conversation. "
139-
"Do not include the question or any JSON. Only include your answer for {last_character.name}."
140-
)
141-
reply_prompt = (
142-
"{last_character.name} continues the conversation with you. They reply: {response}\n"
143-
"Reply with your response to them. Reply with 'END' to end the conversation. "
144-
"Do not include the question or any JSON. Only include your answer for {last_character.name}."
193+
# TODO: make sure they are in the same room
194+
195+
broadcast(
196+
format_prompt(
197+
"action_ask_broadcast",
198+
action_character=action_character,
199+
character=character,
200+
question=question,
201+
)
145202
)
203+
first_prompt = get_prompt("action_ask_conversation_first")
204+
reply_prompt = get_prompt("action_ask_conversation_reply")
205+
end_prompt = get_prompt("action_ask_conversation_end")
146206

147207
action_agent = get_agent_for_character(action_character)
148208
result = loop_conversation(
@@ -153,7 +213,7 @@ def action_ask(character: str, question: str) -> str:
153213
first_prompt,
154214
reply_prompt,
155215
question,
156-
"Goodbye",
216+
end_prompt,
157217
echo_function=action_tell.__name__,
158218
echo_parameter="message",
159219
max_length=MAX_CONVERSATION_STEPS,
@@ -162,7 +222,7 @@ def action_ask(character: str, question: str) -> str:
162222
if result:
163223
return result
164224

165-
return f"{character} does not respond."
225+
return format_prompt("action_ask_ignore", character=character)
166226

167227

168228
def action_tell(character: str, message: str) -> str:
@@ -179,27 +239,22 @@ def action_tell(character: str, message: str) -> str:
179239
# sanity checks
180240
question_character, question_agent = get_character_agent_for_name(character)
181241
if question_character == action_character:
182-
raise ActionError(
183-
"You cannot tell yourself a message. Stop talking to yourself. Try another action."
184-
)
242+
raise ActionError(format_prompt("action_tell_error_self"))
185243

186244
if not question_character:
187-
raise ActionError(f"The {character} character is not in the room.")
245+
raise ActionError(
246+
format_prompt("action_tell_error_target", character=character)
247+
)
188248

189249
if not question_agent:
190-
raise ActionError(f"The {character} character does not exist.")
250+
raise ActionError(
251+
format_prompt("action_tell_error_agent", character=character)
252+
)
191253

192254
broadcast(f"{action_character.name} tells {character}: {message}")
193-
first_prompt = (
194-
"{last_character.name} starts a conversation with you. They say: {response}\n"
195-
"Reply with your response to them. "
196-
"Do not include the message or any JSON. Only include your reply to {last_character.name}."
197-
)
198-
reply_prompt = (
199-
"{last_character.name} continues the conversation with you. They reply: {response}\n"
200-
"Reply with your response to them. "
201-
"Do not include the message or any JSON. Only include your reply to {last_character.name}."
202-
)
255+
first_prompt = get_prompt("action_tell_conversation_first")
256+
reply_prompt = get_prompt("action_tell_conversation_reply")
257+
end_prompt = get_prompt("action_tell_conversation_end")
203258

204259
action_agent = get_agent_for_character(action_character)
205260
result = loop_conversation(
@@ -210,7 +265,7 @@ def action_tell(character: str, message: str) -> str:
210265
first_prompt,
211266
reply_prompt,
212267
message,
213-
"Goodbye",
268+
end_prompt,
214269
echo_function=action_tell.__name__,
215270
echo_parameter="message",
216271
max_length=MAX_CONVERSATION_STEPS,
@@ -219,7 +274,7 @@ def action_tell(character: str, message: str) -> str:
219274
if result:
220275
return result
221276

222-
return f"{character} does not respond."
277+
return format_prompt("action_tell_ignore", character=character)
223278

224279

225280
def action_give(character: str, item: str) -> str:
@@ -233,22 +288,29 @@ def action_give(character: str, item: str) -> str:
233288
with action_context() as (action_room, action_character):
234289
destination_character = find_character_in_room(action_room, character)
235290
if not destination_character:
236-
raise ActionError(f"The {character} character is not in the room.")
237-
238-
if destination_character == action_character:
239291
raise ActionError(
240-
"You cannot give an item to yourself. Try another action."
292+
format_prompt("action_give_error_target", character=character)
241293
)
242294

295+
if destination_character == action_character:
296+
raise ActionError(format_prompt("action_give_error_self"))
297+
243298
action_item = find_item_in_character(action_character, item)
244299
if not action_item:
245-
raise ActionError(f"You do not have the {item} item in your inventory.")
300+
raise ActionError(format_prompt("action_give_error_item", item=item))
246301

247-
broadcast(f"{action_character.name} gives {character} the {item} item.")
302+
broadcast(
303+
format_prompt(
304+
"action_give_broadcast",
305+
action_character=action_character,
306+
character=character,
307+
item=item,
308+
)
309+
)
248310
action_character.items.remove(action_item)
249311
destination_character.items.append(action_item)
250312

251-
return f"You give the {item} item to {character}."
313+
return format_prompt("action_give_result", character=character, item=item)
252314

253315

254316
def action_drop(item: str) -> str:
@@ -262,10 +324,14 @@ def action_drop(item: str) -> str:
262324
with action_context() as (action_room, action_character):
263325
action_item = find_item_in_character(action_character, item)
264326
if not action_item:
265-
raise ActionError(f"You do not have the {item} item in your inventory.")
327+
raise ActionError(format_prompt("action_drop_error_item", item=item))
266328

267-
broadcast(f"{action_character.name} drops the {item} item")
329+
broadcast(
330+
format_prompt(
331+
"action_drop_broadcast", action_character=action_character, item=item
332+
)
333+
)
268334
action_character.items.remove(action_item)
269335
action_room.items.append(action_item)
270336

271-
return f"You drop the {item} item."
337+
return format_prompt("action_drop_result", item=item)

0 commit comments

Comments
 (0)