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
...
@@ -14,7 +14,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
### Changed
### Changed
-
**Huge improvements**
to
**chat prompt**
for more
*balanced*
dialog and
*predictable*
behaviors
-
**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.
-
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
-
Improved
**message cleaning**
to remove any remaining
`**`
and
`<>`
after parsing behaviors
-
Privacy Policy updated
-
Privacy Policy updated
...
...
src/main/java/com/owlmaddie/message/MessageParser.java
View file @
b41a9f30
...
@@ -19,7 +19,7 @@ public class MessageParser {
...
@@ -19,7 +19,7 @@ public class MessageParser {
LOGGER
.
info
(
"Parsing message: {}"
,
input
);
LOGGER
.
info
(
"Parsing message: {}"
,
input
);
StringBuilder
cleanedMessage
=
new
StringBuilder
();
StringBuilder
cleanedMessage
=
new
StringBuilder
();
List
<
Behavior
>
behaviors
=
new
ArrayList
<>();
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
);
Matcher
matcher
=
pattern
.
matcher
(
input
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
...
...
src/test/java/com/owlmaddie/tests/BehaviorTests.java
View file @
b41a9f30
...
@@ -51,7 +51,7 @@ public class BehaviorTests {
...
@@ -51,7 +51,7 @@ public class BehaviorTests {
"DIEEE!"
);
"DIEEE!"
);
List
<
String
>
friendshipUpMessages
=
Arrays
.
asList
(
List
<
String
>
friendshipUpMessages
=
Arrays
.
asList
(
"Hi friend! I am so happy to see you again!"
,
"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>"
);
"<gives 1 golden apple>"
);
List
<
String
>
friendshipDownMessages
=
Arrays
.
asList
(
List
<
String
>
friendshipDownMessages
=
Arrays
.
asList
(
"<attacked you directly with Stone Axe>"
,
"<attacked you directly with Stone Axe>"
,
...
@@ -97,49 +97,53 @@ public class BehaviorTests {
...
@@ -97,49 +97,53 @@ public class BehaviorTests {
@Test
@Test
public
void
followBrave
()
{
public
void
followBrave
()
{
for
(
String
message
:
followMessages
)
{
for
(
String
message
:
followMessages
)
{
testPromptForBehavior
(
bravePath
,
message
,
"FOLLOW"
);
testPromptForBehavior
(
bravePath
,
List
.
of
(
message
)
,
"FOLLOW"
);
}
}
}
}
@Test
@Test
public
void
followNervous
()
{
public
void
followNervous
()
{
for
(
String
message
:
followMessages
)
{
for
(
String
message
:
followMessages
)
{
testPromptForBehavior
(
nervousPath
,
message
,
"FOLLOW"
);
testPromptForBehavior
(
nervousPath
,
List
.
of
(
message
)
,
"FOLLOW"
);
}
}
}
}
@Test
@Test
public
void
attackBrave
()
{
public
void
attackBrave
()
{
for
(
String
message
:
attackMessages
)
{
for
(
String
message
:
attackMessages
)
{
testPromptForBehavior
(
bravePath
,
message
,
"ATTACK"
);
testPromptForBehavior
(
bravePath
,
List
.
of
(
message
)
,
"ATTACK"
);
}
}
}
}
@Test
@Test
public
void
attackNervous
()
{
public
void
attackNervous
()
{
for
(
String
message
:
attackMessages
)
{
for
(
String
message
:
attackMessages
)
{
testPromptForBehavior
(
nervousPath
,
message
,
"FLEE"
);
testPromptForBehavior
(
nervousPath
,
List
.
of
(
message
)
,
"FLEE"
);
}
}
}
}
@Test
@Test
public
void
friendshipUpNervous
()
{
public
void
friendshipUpNervous
()
{
for
(
String
message
:
friendshipUpMessages
)
{
ParsedMessage
result
=
testPromptForBehavior
(
nervousPath
,
friendshipUpMessages
,
"FRIENDSHIP"
);
ParsedMessage
result
=
testPromptForBehavior
(
nervousPath
,
message
,
"FRIENDSHIP"
);
assertTrue
(
result
.
getBehaviors
().
stream
().
anyMatch
(
b
->
"FRIENDSHIP"
.
equals
(
b
.
getName
())
&&
b
.
getArgument
()
>
0
));
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
@Test
public
void
friendshipDownNervous
()
{
public
void
friendshipDownNervous
()
{
for
(
String
message
:
friendshipDownMessages
)
{
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
));
assertTrue
(
result
.
getBehaviors
().
stream
().
anyMatch
(
b
->
"FRIENDSHIP"
.
equals
(
b
.
getName
())
&&
b
.
getArgument
()
<
0
));
}
}
}
}
public
ParsedMessage
testPromptForBehavior
(
Path
chatDataPath
,
String
message
,
String
behavior
)
{
public
ParsedMessage
testPromptForBehavior
(
Path
chatDataPath
,
List
<
String
>
messages
,
String
behavior
)
{
LOGGER
.
info
(
"Testing '"
+
chatDataPath
.
getFileName
()
+
"' with '"
+
message
+
"' and expecting behavior: "
+
behavior
);
LOGGER
.
info
(
"Testing '"
+
chatDataPath
.
getFileName
()
+
"' with '"
+
message
s
.
toString
()
+
"' and expecting behavior: "
+
behavior
);
try
{
try
{
// Load entity chat data
// Load entity chat data
...
@@ -151,7 +155,9 @@ public class BehaviorTests {
...
@@ -151,7 +155,9 @@ public class BehaviorTests {
assertNotNull
(
contextData
);
assertNotNull
(
contextData
);
// Add test message
// Add test message
entityTestData
.
addMessage
(
message
,
ChatDataManager
.
ChatSender
.
USER
);
for
(
String
message
:
messages
)
{
entityTestData
.
addMessage
(
message
,
ChatDataManager
.
ChatSender
.
USER
);
}
// Get prompt
// Get prompt
Path
promptPath
=
Paths
.
get
(
PROMPT_PATH
,
"system-chat"
);
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