Further improve exit coherence by detecting duplicate names and creating back-connects manually when necessary

This commit is contained in:
projectmoon 2024-01-11 15:59:05 +01:00
parent a83aea86e3
commit ccbaf41211
4 changed files with 35 additions and 5 deletions

View File

@ -59,10 +59,14 @@ pub(super) fn check_scene_coherence<'a>(scene: &'a Scene) -> Vec<CoherenceFailur
let mut failures: Vec<CoherenceFailure> = vec![];
for exit in scene.exits.as_slice() {
if is_direction(&exit.name) || is_weird_exit_name(&exit.name) {
// Exit names cannot be directions, "weird", or the name of
// the current scene itself.
if is_direction(&exit.name) || is_weird_exit_name(&exit.name) || exit.name == scene.name {
failures.push(CoherenceFailure::InvalidExitName(exit));
}
// Also need to detect duplicate exits by direction. Stub
// creation can have two exits that lead the same way.
let duplicate_exits: Vec<_> = scene.exits.iter().filter(|e| e.name == exit.name).collect();
if duplicate_exits.len() > 1 && !is_duplicate_recorded(&failures, exit) {
@ -137,7 +141,11 @@ pub fn make_scene_from_stub_coherent(content: &mut ContentContainer, connected_s
content.contained.swap_remove(pos);
}
} else {
println!("WARNING: could not correct stub exit");
println!("WARNING: could not correct stub exit - creating manually");
// Could not find a connected exit at all. Create one manually
let exit = Exit::from_connected_scene(connected_scene, direction_from);
new_scene.exits.push(exit);
}
}

View File

@ -166,9 +166,15 @@ impl AiLogic {
.create_scene_seed_from_stub(&stub, connected_scene)
.await?;
// There are two coherence steps: the first fixes up exit
// directions and stuff, while the second is the normal scene
// coherence (that can invoke the LLM).
let mut content = self.fill_in_scene_from_stub(seed, stub).await?;
coherence::make_scene_from_stub_coherent(&mut content, connected_scene);
let mut scene = content.owner.as_scene_mut();
coherence::make_scene_coherent(&mut self.generator, &mut scene).await?;
self.generator.reset_world_creation();
Ok(content)
@ -186,7 +192,10 @@ impl AiLogic {
.create_scene_seed(scene_type, fantasticalness)
.await?;
let content = self.fill_in_scene(scene_seed).await?;
let mut content = self.fill_in_scene(scene_seed).await?;
let mut scene = content.owner.as_scene_mut();
coherence::make_scene_coherent(&mut self.generator, &mut scene).await?;
self.generator.reset_world_creation();
Ok(content)
}
@ -257,8 +266,6 @@ impl AiLogic {
content_in_scene.append(&mut items);
content_in_scene.append(&mut stubs);
coherence::make_scene_coherent(&mut self.generator, &mut scene).await?;
Ok(ContentContainer {
owner: Content::Scene(scene),
contained: content_in_scene,

View File

@ -188,6 +188,7 @@ Extended scene description:
const FIX_EXIT_PROMPT: &'static str = r#"
This is an exit in a scene that was determined to be invalid. Fix the exit by giving it a better name, and making sure the direction makes sense. The scene's name and description is provided below for reference.
- The `name` field should be the name of the place that the player would go from this scene.
- The `name` field must not be the name of the scene below.
- The `name` field must not be a cardinal or relative direction.
- Example: `north`, `south`, `east`, `west` are NOT valid exit names.
- Example: `up`, `down`, `in`, `out` are NOT valid exit names.
@ -213,6 +214,8 @@ Do NOT use any of the directions below for the fixed exit. Prefer using the orig
**Scene Name:** `{SCENE_NAME}`
Do **NOT** use this Scene Name as a `name` for the new exit.
**Scene Description**
{SCENE_DESCRIPTION}

View File

@ -188,6 +188,18 @@ pub struct Exit {
pub scene_id: Option<String>,
}
impl Exit {
pub fn from_connected_scene(scene: &Scene, direction_from: &str) -> Exit {
Exit {
name: scene.name.clone(),
location: scene.location.clone(),
direction: direction_from.to_string(),
scene_key: scene._key.as_ref().cloned().unwrap(),
scene_id: scene._id.clone(),
}
}
}
impl From<ExitSeed> for Exit {
fn from(seed: ExitSeed) -> Self {
Self {