Skip to content

Add LLM memory-related interfaces #1288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
999 changes: 517 additions & 482 deletions pom.xml

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions src/main/java/org/myrobotlab/document/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class Document {

private String id;
private HashMap<String, ArrayList<Object>> data;
private final HashMap<String, ArrayList<Object>> data;
private ProcessingStatus status;

public Document(String id) {
Expand All @@ -27,11 +27,7 @@ public Document(String id) {
}

public ArrayList<Object> getField(String fieldName) {
if (data.containsKey(fieldName)) {
return data.get(fieldName);
} else {
return null;
}
return data.getOrDefault(fieldName, null);
}

public void setField(String fieldName, ArrayList<Object> value) {
Expand Down Expand Up @@ -151,9 +147,7 @@ public boolean equals(Object obj) {
return false;
} else if (!id.equals(other.id))
return false;
if (status != other.status)
return false;
return true;
return status == other.status;
}

@Override
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/myrobotlab/service/EasyBert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.myrobotlab.service;

import com.google.common.primitives.Floats;
import com.robrua.nlp.bert.Bert;
import org.myrobotlab.framework.Service;
import org.myrobotlab.service.interfaces.TextEmbeddingGenerator;

import java.io.File;
import java.util.List;

public class EasyBert extends Service implements TextEmbeddingGenerator {

private Bert bert;
public final String DEFAULT_BERT_MODEL = "com/robrua/nlp/easy-bert/bert-uncased-L-12-H-768-A-12";


/**
* Constructor of service, reservedkey typically is a services name and inId
* will be its process id
*
* @param reservedKey the service name
* @param inId process id
*/
public EasyBert(String reservedKey, String inId) {
super(reservedKey, inId);
bert = Bert.load(DEFAULT_BERT_MODEL);
}

@Override
public List<Float> generateEmbeddings(String words) {
List<Float> embeddings = Floats.asList(bert.embedSequence(words));
invoke("publishEmbeddings", embeddings);
return embeddings;
}

@Override
public List<Float> publishEmbeddings(List<Float> embeddings) {
return embeddings;
}

@Override
public void onText(String text) throws Exception {
generateEmbeddings(text);
}

public void setBertModel(String resource) {
bert = Bert.load(resource);
}

public void setBertModel(File model) {
bert = Bert.load(model);
}
}
Loading