Skip to content

Commit

Permalink
SSL support for websocket server, basic world editor, various prompt …
Browse files Browse the repository at this point in the history
…fixes
  • Loading branch information
ssube committed Jun 11, 2024
1 parent aa44632 commit d0ddeca
Show file tree
Hide file tree
Showing 12 changed files with 489 additions and 47 deletions.
2 changes: 1 addition & 1 deletion client/src/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export function RenderEventItem(props: EventItemProps) {
>{prompt}</Typography>
}
/>
<ImageList cols={3} rowHeight={256}>
<ImageList>
{Object.entries(images).map(([name, image]) => <ImageListItem key={name}>
<a href='#' onClick={() => openImage(image as string)}>
<img src={`data:image/jpeg;base64,${image}`} alt="Render" style={{ maxHeight: 256, maxWidth: 256 }} />
Expand Down
23 changes: 21 additions & 2 deletions client/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { doesExist } from '@apextoaster/js-utils';
import { doesExist, mustDefault } from '@apextoaster/js-utils';
import { createRoot } from 'react-dom/client';
import React, { StrictMode } from 'react';

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

export const DEFAULT_SOCKET_PORT = 8001;

export function getSocketProtocol(protocol: string) {
if (protocol === 'https:') {
return 'wss:';
}

return 'ws:';
}

export function getSocketAddress(protocol: string, hostname: string, port = DEFAULT_SOCKET_PORT) {
const socketProtocol = getSocketProtocol(protocol);
return `${socketProtocol}://${hostname}:${port}/`;
}

window.addEventListener('DOMContentLoaded', () => {
const history = document.querySelector('#history');

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

const protocol = window.location.protocol;
const hostname = window.location.hostname;
const search = new URLSearchParams(window.location.search);
const socketAddress = mustDefault(search.get('socket'), getSocketAddress(protocol, hostname));

const root = createRoot(history);
root.render(<StrictMode><App socketUrl={`ws://${hostname}:8001/`} /></StrictMode>);
root.render(<StrictMode><App socketUrl={socketAddress} /></StrictMode>);
});
20 changes: 15 additions & 5 deletions prompts/llama-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ prompts:
{{name}} will happen in {{turns}} turn
# agent stuff
world_agent_backstory: |
{{ character.backstory }}
world_agent_backstory_other: |
{{ character.backstory }}
world_agent_backstory: |
You are {{character | name}}, a character in a text-based role-playing game. Your character's backstory is:
{{ character.backstory }}
Explore the world, interact with other characters, and complete quests to advance the story.
Expand All @@ -218,11 +218,11 @@ prompts:
Generating a {{theme}} with {{room_count}} rooms
world_generate_room_name: |
Generate one room, area, or location that would make sense in the world of {{world_theme}}.
Generate one room, area, or location that would make sense in the world of {{world_theme}}. {{ additional_prompt | punctuate }}
Only respond with the room name in title case, do not include the description or any other text.
Do not prefix the name with "the", do not wrap it in quotes. The existing rooms are: {{existing_rooms}}
world_generate_room_description: |
Generate a detailed description of the {{name}} area. What does it look like?
Generate a detailed description of the {{name}} area. {{ additional_prompt | punctuate }} What does it look like?
What does it smell like? What can be seen or heard?
world_generate_room_broadcast_room: |
Generating room: {{name}}
Expand Down Expand Up @@ -356,6 +356,11 @@ prompts:
world_simulate_character_action_error_json: |
Your last reply was not a valid action or the action you tried to use does not exist. Please try again, being
careful to reply with a valid function call in JSON format. The available actions are: {{actions}}.
world_simulate_character_action_error_action: |
You cannot use the '{{action}}' action because {{message | punctuate}}
world_simulate_character_action_error_unknown_tool: |
That action is not available during the action phase or it does not exist. Please try again using a different
action. The available actions are: {{actions}}.
world_simulate_character_planning: |
You are about to start your turn. Plan your next action carefully. Take notes and schedule events to help keep track of your goals.
Expand All @@ -379,6 +384,11 @@ prompts:
You have no upcoming events.
world_simulate_character_planning_events_item: |
{{event.name}} in {{turns}} turns
world_simulate_character_planning_error_action: |
You cannot perform the '{{action}}' action because {{message | punctuate}}
world_simulate_character_planning_error_json: |
Your last reply was not a valid action or the action you tried to use does not exist. Please try again, being
careful to reply with a valid function call in JSON format. The available actions are: {{actions}}.
careful to reply with a valid function call in JSON format. The available actions are: {{actions}}.
world_simulate_character_planning_error_unknown_tool: |
That action is not available during the planning phase or it does not exist. Please try again using a different
action. The available actions are: {{actions}}.
12 changes: 6 additions & 6 deletions taleweave/bot/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,17 @@ def bot_main():
client.run(environ["DISCORD_TOKEN"])

def send_main():
from time import sleep
# from time import sleep

while True:
sleep(0.1)
if event_queue.empty():
# logger.debug("no events to prompt")
continue
# sleep(0.05)
# if event_queue.empty():
# logger.debug("no events to prompt")
# continue

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

event = event_queue.get()
Expand Down
Loading

0 comments on commit d0ddeca

Please sign in to comment.