Skip to content

Commit d0ddeca

Browse files
committed
SSL support for websocket server, basic world editor, various prompt fixes
1 parent aa44632 commit d0ddeca

File tree

12 files changed

+489
-47
lines changed

12 files changed

+489
-47
lines changed

client/src/events.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function RenderEventItem(props: EventItemProps) {
230230
>{prompt}</Typography>
231231
}
232232
/>
233-
<ImageList cols={3} rowHeight={256}>
233+
<ImageList>
234234
{Object.entries(images).map(([name, image]) => <ImageListItem key={name}>
235235
<a href='#' onClick={() => openImage(image as string)}>
236236
<img src={`data:image/jpeg;base64,${image}`} alt="Render" style={{ maxHeight: 256, maxWidth: 256 }} />

client/src/main.tsx

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
import { doesExist } from '@apextoaster/js-utils';
1+
import { doesExist, mustDefault } from '@apextoaster/js-utils';
22
import { createRoot } from 'react-dom/client';
33
import React, { StrictMode } from 'react';
44

55
import { App } from './app.js';
66

7+
export const DEFAULT_SOCKET_PORT = 8001;
8+
9+
export function getSocketProtocol(protocol: string) {
10+
if (protocol === 'https:') {
11+
return 'wss:';
12+
}
13+
14+
return 'ws:';
15+
}
16+
17+
export function getSocketAddress(protocol: string, hostname: string, port = DEFAULT_SOCKET_PORT) {
18+
const socketProtocol = getSocketProtocol(protocol);
19+
return `${socketProtocol}://${hostname}:${port}/`;
20+
}
21+
722
window.addEventListener('DOMContentLoaded', () => {
823
const history = document.querySelector('#history');
924

@@ -12,7 +27,11 @@ window.addEventListener('DOMContentLoaded', () => {
1227
throw new Error('History element not found');
1328
}
1429

30+
const protocol = window.location.protocol;
1531
const hostname = window.location.hostname;
32+
const search = new URLSearchParams(window.location.search);
33+
const socketAddress = mustDefault(search.get('socket'), getSocketAddress(protocol, hostname));
34+
1635
const root = createRoot(history);
17-
root.render(<StrictMode><App socketUrl={`ws://${hostname}:8001/`} /></StrictMode>);
36+
root.render(<StrictMode><App socketUrl={socketAddress} /></StrictMode>);
1837
});

prompts/llama-base.yml

+15-5
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ prompts:
193193
{{name}} will happen in {{turns}} turn
194194
195195
# agent stuff
196-
world_agent_backstory: |
197-
{{ character.backstory }}
198196
world_agent_backstory_other: |
197+
{{ character.backstory }}
198+
world_agent_backstory: |
199199
You are {{character | name}}, a character in a text-based role-playing game. Your character's backstory is:
200200
{{ character.backstory }}
201201
Explore the world, interact with other characters, and complete quests to advance the story.
@@ -218,11 +218,11 @@ prompts:
218218
Generating a {{theme}} with {{room_count}} rooms
219219
220220
world_generate_room_name: |
221-
Generate one room, area, or location that would make sense in the world of {{world_theme}}.
221+
Generate one room, area, or location that would make sense in the world of {{world_theme}}. {{ additional_prompt | punctuate }}
222222
Only respond with the room name in title case, do not include the description or any other text.
223223
Do not prefix the name with "the", do not wrap it in quotes. The existing rooms are: {{existing_rooms}}
224224
world_generate_room_description: |
225-
Generate a detailed description of the {{name}} area. What does it look like?
225+
Generate a detailed description of the {{name}} area. {{ additional_prompt | punctuate }} What does it look like?
226226
What does it smell like? What can be seen or heard?
227227
world_generate_room_broadcast_room: |
228228
Generating room: {{name}}
@@ -356,6 +356,11 @@ prompts:
356356
world_simulate_character_action_error_json: |
357357
Your last reply was not a valid action or the action you tried to use does not exist. Please try again, being
358358
careful to reply with a valid function call in JSON format. The available actions are: {{actions}}.
359+
world_simulate_character_action_error_action: |
360+
You cannot use the '{{action}}' action because {{message | punctuate}}
361+
world_simulate_character_action_error_unknown_tool: |
362+
That action is not available during the action phase or it does not exist. Please try again using a different
363+
action. The available actions are: {{actions}}.
359364
360365
world_simulate_character_planning: |
361366
You are about to start your turn. Plan your next action carefully. Take notes and schedule events to help keep track of your goals.
@@ -379,6 +384,11 @@ prompts:
379384
You have no upcoming events.
380385
world_simulate_character_planning_events_item: |
381386
{{event.name}} in {{turns}} turns
387+
world_simulate_character_planning_error_action: |
388+
You cannot perform the '{{action}}' action because {{message | punctuate}}
382389
world_simulate_character_planning_error_json: |
383390
Your last reply was not a valid action or the action you tried to use does not exist. Please try again, being
384-
careful to reply with a valid function call in JSON format. The available actions are: {{actions}}.
391+
careful to reply with a valid function call in JSON format. The available actions are: {{actions}}.
392+
world_simulate_character_planning_error_unknown_tool: |
393+
That action is not available during the planning phase or it does not exist. Please try again using a different
394+
action. The available actions are: {{actions}}.

taleweave/bot/discord.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,17 @@ def bot_main():
238238
client.run(environ["DISCORD_TOKEN"])
239239

240240
def send_main():
241-
from time import sleep
241+
# from time import sleep
242242

243243
while True:
244-
sleep(0.1)
245-
if event_queue.empty():
246-
# logger.debug("no events to prompt")
247-
continue
244+
# sleep(0.05)
245+
# if event_queue.empty():
246+
# logger.debug("no events to prompt")
247+
# continue
248248

249249
# wait for pending messages to send, to keep them in order
250250
if len(active_tasks) > 0:
251-
logger.debug("waiting for active tasks to complete")
251+
# logger.debug("waiting for active tasks to complete")
252252
continue
253253

254254
event = event_queue.get()

0 commit comments

Comments
 (0)