Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
b41a9f30
Commit
b41a9f30
authored
Jun 13, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Case insensitive regex (FLEE vs flee), improved friendship unit tests.
parent
99eeea35
Pipeline
#12457
passed with stages
in 2 minutes 16 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
15 deletions
+21
-15
CHANGELOG.md
CHANGELOG.md
+1
-1
MessageParser.java
src/main/java/com/owlmaddie/message/MessageParser.java
+1
-1
BehaviorTests.java
src/test/java/com/owlmaddie/tests/BehaviorTests.java
+19
-13
No files found.
CHANGELOG.md
View file @
b41a9f30
...
...
@@ -14,7 +14,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
### Changed
-
**Huge improvements**
to
**chat prompt**
for more
*balanced*
dialog and
*predictable*
behaviors
-
Improved
**Behavior regex**
to include both
`<BEHAVIOR arg>`
and
`*BEHAVIOR arg*`
syntax, and ignore unknown behaviors.
-
Expanded regex to support args with
`+`
sign (i.e.
`<FRIENDSHIP +1>`
)
-
Expanded regex to support args with
`+`
sign (i.e.
`<FRIENDSHIP +1>`
)
and case-insensitive
-
Improved
**message cleaning**
to remove any remaining
`**`
and
`<>`
after parsing behaviors
-
Privacy Policy updated
...
...
src/main/java/com/owlmaddie/message/MessageParser.java
View file @
b41a9f30
...
...
@@ -19,7 +19,7 @@ public class MessageParser {
LOGGER
.
info
(
"Parsing message: {}"
,
input
);
StringBuilder
cleanedMessage
=
new
StringBuilder
();
List
<
Behavior
>
behaviors
=
new
ArrayList
<>();
Pattern
pattern
=
Pattern
.
compile
(
"[<*](FOLLOW|FLEE|ATTACK|FRIENDSHIP|UNFOLLOW)(?:\\s+([+-]?\\d+))?[>*]"
);
Pattern
pattern
=
Pattern
.
compile
(
"[<*](FOLLOW|FLEE|ATTACK|FRIENDSHIP|UNFOLLOW)(?:\\s+([+-]?\\d+))?[>*]"
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
matcher
=
pattern
.
matcher
(
input
);
while
(
matcher
.
find
())
{
...
...
src/test/java/com/owlmaddie/tests/BehaviorTests.java
View file @
b41a9f30
...
...
@@ -51,7 +51,7 @@ public class BehaviorTests {
"DIEEE!"
);
List
<
String
>
friendshipUpMessages
=
Arrays
.
asList
(
"Hi friend! I am so happy to see you again!"
,
"
How is my best friend doing?
"
,
"
Looking forward to hanging out with you.
"
,
"<gives 1 golden apple>"
);
List
<
String
>
friendshipDownMessages
=
Arrays
.
asList
(
"<attacked you directly with Stone Axe>"
,
...
...
@@ -97,49 +97,53 @@ public class BehaviorTests {
@Test
public
void
followBrave
()
{
for
(
String
message
:
followMessages
)
{
testPromptForBehavior
(
bravePath
,
message
,
"FOLLOW"
);
testPromptForBehavior
(
bravePath
,
List
.
of
(
message
)
,
"FOLLOW"
);
}
}
@Test
public
void
followNervous
()
{
for
(
String
message
:
followMessages
)
{
testPromptForBehavior
(
nervousPath
,
message
,
"FOLLOW"
);
testPromptForBehavior
(
nervousPath
,
List
.
of
(
message
)
,
"FOLLOW"
);
}
}
@Test
public
void
attackBrave
()
{
for
(
String
message
:
attackMessages
)
{
testPromptForBehavior
(
bravePath
,
message
,
"ATTACK"
);
testPromptForBehavior
(
bravePath
,
List
.
of
(
message
)
,
"ATTACK"
);
}
}
@Test
public
void
attackNervous
()
{
for
(
String
message
:
attackMessages
)
{
testPromptForBehavior
(
nervousPath
,
message
,
"FLEE"
);
testPromptForBehavior
(
nervousPath
,
List
.
of
(
message
)
,
"FLEE"
);
}
}
@Test
public
void
friendshipUpNervous
()
{
for
(
String
message
:
friendshipUpMessages
)
{
ParsedMessage
result
=
testPromptForBehavior
(
nervousPath
,
message
,
"FRIENDSHIP"
);
assertTrue
(
result
.
getBehaviors
().
stream
().
anyMatch
(
b
->
"FRIENDSHIP"
.
equals
(
b
.
getName
())
&&
b
.
getArgument
()
>
0
));
}
ParsedMessage
result
=
testPromptForBehavior
(
nervousPath
,
friendshipUpMessages
,
"FRIENDSHIP"
);
assertTrue
(
result
.
getBehaviors
().
stream
().
anyMatch
(
b
->
"FRIENDSHIP"
.
equals
(
b
.
getName
())
&&
b
.
getArgument
()
>
0
));
}
@Test
public
void
friendshipUpBrave
()
{
ParsedMessage
result
=
testPromptForBehavior
(
bravePath
,
friendshipUpMessages
,
"FRIENDSHIP"
);
assertTrue
(
result
.
getBehaviors
().
stream
().
anyMatch
(
b
->
"FRIENDSHIP"
.
equals
(
b
.
getName
())
&&
b
.
getArgument
()
>
0
));
}
@Test
public
void
friendshipDownNervous
()
{
for
(
String
message
:
friendshipDownMessages
)
{
ParsedMessage
result
=
testPromptForBehavior
(
nervousPath
,
message
,
"FRIENDSHIP"
);
ParsedMessage
result
=
testPromptForBehavior
(
nervousPath
,
List
.
of
(
message
)
,
"FRIENDSHIP"
);
assertTrue
(
result
.
getBehaviors
().
stream
().
anyMatch
(
b
->
"FRIENDSHIP"
.
equals
(
b
.
getName
())
&&
b
.
getArgument
()
<
0
));
}
}
public
ParsedMessage
testPromptForBehavior
(
Path
chatDataPath
,
String
message
,
String
behavior
)
{
LOGGER
.
info
(
"Testing '"
+
chatDataPath
.
getFileName
()
+
"' with '"
+
message
+
"' and expecting behavior: "
+
behavior
);
public
ParsedMessage
testPromptForBehavior
(
Path
chatDataPath
,
List
<
String
>
messages
,
String
behavior
)
{
LOGGER
.
info
(
"Testing '"
+
chatDataPath
.
getFileName
()
+
"' with '"
+
message
s
.
toString
()
+
"' and expecting behavior: "
+
behavior
);
try
{
// Load entity chat data
...
...
@@ -151,7 +155,9 @@ public class BehaviorTests {
assertNotNull
(
contextData
);
// Add test message
entityTestData
.
addMessage
(
message
,
ChatDataManager
.
ChatSender
.
USER
);
for
(
String
message
:
messages
)
{
entityTestData
.
addMessage
(
message
,
ChatDataManager
.
ChatSender
.
USER
);
}
// Get prompt
Path
promptPath
=
Paths
.
get
(
PROMPT_PATH
,
"system-chat"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment