-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbda11d
commit eff0498
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from gigax.parse import CharacterAction, get_guided_regex | ||
from tests.utils import create_scene | ||
|
||
|
||
def test_parse(): | ||
_, locations, NPCs, protagonist, items, _ = create_scene() | ||
|
||
test_command = 'attack John the Brave "Hello, how are you"' | ||
|
||
# Test the compiled regex | ||
compiled_combined_regex = get_guided_regex( | ||
protagonist.skills, NPCs, locations, items | ||
) | ||
assert compiled_combined_regex | ||
assert compiled_combined_regex.match(test_command) | ||
|
||
# Test the from_str method | ||
character_action = CharacterAction.from_str( | ||
test_command, protagonist, NPCs, locations, items, compiled_combined_regex | ||
) | ||
assert character_action | ||
assert character_action.command == "Attack" | ||
assert character_action.protagonist == protagonist | ||
assert character_action.parameters == [NPCs[0]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from gigax.prompt import NPCPrompt | ||
from tests.utils import create_scene | ||
|
||
|
||
def test_prompt(): | ||
prompt = NPCPrompt(*create_scene()) | ||
assert prompt | ||
|
||
test_prompt = """- WORLD KNOWLEDGE: A vast open world full of mystery and adventure. | ||
- KNOWN LOCATIONS: Old Town | ||
- NPCS: John the Brave | ||
- CURRENT LOCATION: Old Town: A quiet and peaceful town. | ||
- CURRENT LOCATION ITEMS: Sword | ||
- LAST EVENTS: | ||
Aldren: Say Sword What a fine sword! | ||
- PROTAGONIST NAME: Aldren | ||
- PROTAGONIST PSYCHOLOGICAL PROFILE: Brave and curious | ||
- PROTAGONIST MEMORIES: | ||
Saved the village | ||
Lost a friend | ||
- PROTAGONIST PENDING QUESTS: | ||
Find the ancient artifact | ||
Defeat the evil warlock | ||
- PROTAGONIST ALLOWED ACTIONS: | ||
Attack <character> : Deliver a powerful blow | ||
Aldren:""" | ||
|
||
assert prompt == test_prompt, f"{prompt} != {test_prompt}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from gigax.scene import Character, Item, Location, ParameterType | ||
from gigax.parse import CharacterAction, ProtagonistCharacter, Skill | ||
|
||
|
||
def create_scene(): | ||
# Example usage of the function | ||
context = "A vast open world full of mystery and adventure." | ||
locations = [Location(name="Old Town", description="A quiet and peaceful town.")] | ||
NPCs = [ | ||
Character( | ||
name="John the Brave", | ||
description="A fearless warrior", | ||
current_location=locations[0], | ||
) | ||
] | ||
protagonist = ProtagonistCharacter( | ||
name="Aldren", | ||
description="Brave and curious", | ||
current_location=locations[0], | ||
memories=["Saved the village", "Lost a friend"], | ||
quests=["Find the ancient artifact", "Defeat the evil warlock"], | ||
skills=[ | ||
Skill( | ||
name="Attack", | ||
description="Deliver a powerful blow", | ||
parameter_types=[ParameterType.character], | ||
) | ||
], | ||
psychological_profile="Determined and compassionate", | ||
) | ||
items = [Item(name="Sword", description="A sharp blade")] | ||
events = [ | ||
CharacterAction( | ||
command="Say", | ||
protagonist=protagonist, | ||
parameters=[items[0], "What a fine sword!"], | ||
) | ||
] | ||
return context, locations, NPCs, protagonist, items, events |