conversation parsing from web
Some checks failed
studiorailgun/trpg/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-12-29 11:22:05 -05:00
parent cde2fb8076
commit 0eb22003d7
15 changed files with 273 additions and 22 deletions

41
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,41 @@
pipeline {
agent any
tools {
maven '3.9.6'
}
stages {
stage('Setup') {
steps {
sh "chmod +x -R ${env.WORKSPACE}"
sh "git submodule update --init --recursive" // make sure submodules are also checked out
}
}
stage ('Check Environment') {
steps {
sh 'mvn --version'
sh 'java -version'
sh 'echo $JAVA_HOME'
sh 'echo $JAVA_INCLUDE_PATH'
}
}
stage('Build (Engine)') {
steps {
sh 'mvn -B -DskipTests clean package'
}
}
stage('Test') {
steps {
script {
catchError {
sh 'mvn test'
}
}
}
post {
always {
junit testResults: 'target/surefire-reports/*.xml', keepLongStdio: true, testDataPublishers: [[$class:'AttachmentPublisher']]
}
}
}
}
}

View File

@ -1,4 +1,5 @@
{
"selfId": 2,
"nodes" : {
"0" : {
"id" : 0,
@ -18,7 +19,7 @@
},
"4" : {
"id" : 4,
"name" : "ConversationParticipant"
"name" : "Other"
}
},
"relations" : {
@ -39,6 +40,12 @@
"name" : "InstanceOf",
"parent" : 1,
"child" : 0
},
"3" : {
"id" : 3,
"name" : "InstanceOf",
"parent" : 3,
"child" : 4
}
}
}

View File

@ -2,6 +2,7 @@ package org.studiorailgun;
import java.io.File;
import org.studiorailgun.conversation.Conversation;
import org.studiorailgun.knowledge.KnowledgeWeb;
/**
@ -14,12 +15,26 @@ public class Globals {
*/
public static KnowledgeWeb web;
/**
* The current conversation
*/
public static Conversation conversation;
/**
* Initializes the knowledge web
*/
public static void init(){
web = FileUtils.loadObjectFromFile(new File("web.json"), KnowledgeWeb.class);
web.initLinks();
Globals.loadWeb("web.json");
}
/**
* Loads a web
* @param webPath The web's path
*/
public static void loadWeb(String webPath){
Globals.web = FileUtils.loadObjectFromFile(new File("web.json"), KnowledgeWeb.class);
Globals.web.initLinks();
Globals.conversation = Conversation.parse(Globals.web);
}
}

View File

@ -3,10 +3,10 @@ package org.studiorailgun.conversation;
import java.util.Scanner;
import org.studiorailgun.Globals;
import org.studiorailgun.conversation.llm.Actor;
import org.studiorailgun.conversation.llm.LLMConversation;
import org.studiorailgun.conversation.llm.Statement;
import org.studiorailgun.conversation.parser.CommandParser;
import org.studiorailgun.conversation.tracking.Actor;
import org.studiorailgun.conversation.tracking.Conversation;
import org.studiorailgun.conversation.tracking.Statement;
public class AgentLoop {
@ -30,7 +30,7 @@ public class AgentLoop {
String prompt = "";
//setup conversation tracking
Conversation convo = new Conversation();
LLMConversation convo = new LLMConversation();
Actor player = new Actor("John");
Actor ai = new Actor("Dave");
convo.addParticipant(player);

View File

@ -0,0 +1,31 @@
package org.studiorailgun.conversation;
import org.studiorailgun.knowledge.Node;
/**
* A participant in a conversation
*/
public class ConvParticipant {
/**
* The corresponding node in the knowledge web that represents this participant
*/
Node data;
/**
* Constructor
* @param data The node in the knowledge web that represents this participant
*/
public ConvParticipant(Node data){
this.data = data;
}
/**
* Gets the node in the knowledge web that represents this participant
* @return The node in the knowledge web that represents this participant
*/
public Node getData(){
return data;
}
}

View File

@ -0,0 +1,76 @@
package org.studiorailgun.conversation;
import org.studiorailgun.conversation.evaluators.GreetingData;
import org.studiorailgun.knowledge.KnowledgeWeb;
/**
* A conversation
*/
public class Conversation {
/**
* The self instance
*/
ConvParticipant self;
/**
* The other participant in the conversation
*/
ConvParticipant other;
/**
* Data on greetings
*/
GreetingData greetingData;
/**
* Parses the current conversation's data from the knowledge web
* @param web The web
* @return The conversation
*/
public static Conversation parse(KnowledgeWeb web){
//find the self
ConvParticipant self = new ConvParticipant(web.getSelf());
//find the other participant
ConvParticipant other = new ConvParticipant(web.getNode(4));
Conversation rVal = new Conversation(self, other);
return rVal;
}
/**
* Constructor
* @param self The participant representing this bot instance
* @param other The participant representing the other party in the conversation
*/
public Conversation(ConvParticipant self, ConvParticipant other){
this.self = self;
this.other = other;
}
/**
* Gets the greeting data
* @return The greeting data
*/
public GreetingData getGreetingData(){
return greetingData;
}
/**
* Gets the self
* @return The self
*/
public ConvParticipant getSelf(){
return self;
}
/**
* Gets the other
* @return The other
*/
public ConvParticipant getOther(){
return other;
}
}

View File

@ -0,0 +1,26 @@
package org.studiorailgun.conversation.evaluators;
import java.util.LinkedList;
import java.util.List;
import org.studiorailgun.conversation.ConvParticipant;
/**
* Data about greetings for a given conversation
*/
public class GreetingData {
/**
* The list of participants that have greeted themselves
*/
List<ConvParticipant> haveGreeted = new LinkedList<ConvParticipant>();
/**
* Gets the list of participants that have greeted themselves
* @return The list
*/
public List<ConvParticipant> getHaveGreeted(){
return haveGreeted;
}
}

View File

@ -5,6 +5,8 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import org.studiorailgun.conversation.Conversation;
/**
* Evaluates a greeting
*/
@ -30,7 +32,7 @@ public class GreetingEval {
* Evaluates a greeting
* @param input The sentence
*/
public static void evaluate(String input){
public static void evaluate(Conversation conversation, String input){
if(greetingStrings.contains(input)){
System.out.println("Contained!");
}

View File

@ -1,4 +1,4 @@
package org.studiorailgun.conversation.tracking;
package org.studiorailgun.conversation.llm;
/**
* A character in a conversation who can say statements

View File

@ -1,11 +1,11 @@
package org.studiorailgun.conversation.tracking;
package org.studiorailgun.conversation.llm;
import java.util.LinkedList;
import org.studiorailgun.kobold.KoboldRequest;
import org.studiorailgun.kobold.KoboldSymbols;
public class Conversation {
public class LLMConversation {
/**
* The participants in the conversation
@ -25,7 +25,7 @@ public class Conversation {
/**
* Constructor
*/
public Conversation(){
public LLMConversation(){
this.participants = new LinkedList<Actor>();
this.statements = new LinkedList<Statement>();
}

View File

@ -1,11 +1,8 @@
package org.studiorailgun.conversation;
package org.studiorailgun.conversation.llm;
import java.util.Scanner;
import org.studiorailgun.conversation.parser.CommandParser;
import org.studiorailgun.conversation.tracking.Actor;
import org.studiorailgun.conversation.tracking.Conversation;
import org.studiorailgun.conversation.tracking.Statement;
import org.studiorailgun.kobold.KoboldPrinter;
import org.studiorailgun.kobold.KoboldRequest;
@ -31,7 +28,7 @@ public class LLMLoop {
String prompt = "";
//setup conversation tracking
Conversation convo = new Conversation();
LLMConversation convo = new LLMConversation();
Actor player = new Actor("John");
Actor ai = new Actor("Dave");
convo.addParticipant(player);

View File

@ -1,4 +1,4 @@
package org.studiorailgun.conversation.tracking;
package org.studiorailgun.conversation.llm;
/**
* A statement by a character in a conversation
@ -28,7 +28,7 @@ public class Statement {
/**
* The conversation this statement was uttered in
*/
Conversation conversation;
LLMConversation conversation;
/**
* Creates a statement
@ -66,11 +66,11 @@ public class Statement {
this.actor = actor;
}
public Conversation getConversation() {
public LLMConversation getConversation() {
return conversation;
}
public void setConversation(Conversation conversation) {
public void setConversation(LLMConversation conversation) {
this.conversation = conversation;
}

View File

@ -1,7 +1,7 @@
package org.studiorailgun.conversation.parser;
import org.studiorailgun.conversation.AgentLoop;
import org.studiorailgun.conversation.LLMLoop;
import org.studiorailgun.conversation.llm.LLMLoop;
import org.studiorailgun.knowledge.CSVExport;
/**

View File

@ -28,6 +28,14 @@ public class KnowledgeWeb {
*/
transient Map<String,List<Integer>> typeRelationLookup;
/**
* The node that represents the current ai
*/
int selfId;
/**
* Constructor
*/
public KnowledgeWeb(){
this.nodes = new HashMap<Integer,Node>();
this.relations = new HashMap<Integer,Relation>();
@ -65,14 +73,27 @@ public class KnowledgeWeb {
}
}
/**
* Gets the collection of all nodes
* @return The collection
*/
public Collection<Node> getNodes() {
return nodes.values();
}
/**
* Gets the collection of all relations
* @return The collection of all relations
*/
public Collection<Relation> getRelations() {
return relations.values();
}
/**
* Gets a node by its id
* @param id The id
* @return The node
*/
public Node getNode(int id){
return nodes.get(id);
}
@ -94,6 +115,14 @@ public class KnowledgeWeb {
}
return null;
}
/**
* Gets the node that represents the ai
* @return The node
*/
public Node getSelf(){
return this.getNode(this.selfId);
}
}

View File

@ -0,0 +1,27 @@
package org.studiorailgun;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import org.junit.jupiter.api.Test;
import org.studiorailgun.conversation.Conversation;
import org.studiorailgun.knowledge.KnowledgeWeb;
/**
* Tests loading conversations
*/
public class ConvLoadingTests {
@Test
public void testLoadConversation(){
KnowledgeWeb web = FileUtils.loadObjectFromFile(new File("./data/test/webs/web.json"), KnowledgeWeb.class);
web.initLinks();
Globals.web = web;
Conversation convo = Conversation.parse(web);
assertEquals(web.getSelf(), convo.getSelf().getData());
assertNotEquals(web.getSelf(), convo.getOther().getData());
}
}