Skip to content

Commit

Permalink
fixed method query
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Nov 6, 2024
1 parent 16e75b4 commit ddf92c6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/myrobotlab/codec/CodecUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ static public Message pathToMsg(String from, String path) {
String[] parts = path.split("/"); // <- this breaks things ! e.g.
// /runtime/connect/"http://localhost:8888"
// path parts less than 3 is a dir or ls
if (parts.length < 3) {
if (parts.length < 3 || (parts.length == 3 && path.endsWith("/"))) {
// this morphs a path which has less than 3 parts
// into a runtime "ls" method call to do reflection of services or
// service methods
Expand All @@ -1109,7 +1109,7 @@ static public Message pathToMsg(String from, String path) {
}

// ["", "runtime", "shutdown"]
if (parts.length == 3) {
if (parts.length == 3 && !path.endsWith("/")) {
msg.name = parts[1];
msg.method = parts[2];
return msg;
Expand Down
71 changes: 39 additions & 32 deletions src/main/java/org/myrobotlab/service/LLM.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public class LLM extends Service<LLMConfig> implements TextListener, TextPublish
protected String currentChannelName;

protected String currentChannelType;

transient protected OllamaAPI api = null;

protected String ollam4JUrl = "";

protected Map<String, Object> inputs = new LinkedHashMap<>();
Expand Down Expand Up @@ -140,7 +140,7 @@ public String createImagePrompt(String model, String prompt, List<String> images

}

OllamaAPI getOllamaApi() throws MalformedURLException {
OllamaAPI getOllamaApi() throws MalformedURLException {
if (api == null || ollam4JUrl == null || !ollam4JUrl.contentEquals(config.url)) {
URL url = new URL(config.url);
ollam4JUrl = config.url;
Expand Down Expand Up @@ -253,6 +253,7 @@ public static byte[] readUriContent(String uriString) throws Exception {

/***
* Converts images into a default chat completion prompt
*
* @param imageUrls
* @return
*/
Expand All @@ -262,24 +263,25 @@ public Response getResponse(List<String> imageUrls) {

/**
* convert images to array of bytes
*
* @param text
* @param imageUrls
* @return
*/
public Response getResponse(String text, List<String> imageUrls) {
// List<byte[]> bimages = null;
// if (images != null) {
// bimages = new ArrayList<>();
// for (String uri : images) {
// if (uri.startsWith("file://")) {
// try {
// bimages.add(readUriContent(uri));
// } catch (Exception e) {
// error(e);
// }
// }
// }
// }
// List<byte[]> bimages = null;
// if (images != null) {
// bimages = new ArrayList<>();
// for (String uri : images) {
// if (uri.startsWith("file://")) {
// try {
// bimages.add(readUriContent(uri));
// } catch (Exception e) {
// error(e);
// }
// }
// }
// }
return getResponseStream(text, imageUrls);
}

Expand All @@ -293,7 +295,7 @@ public Response getResponseStream(String text, List<String> imageUrls) {
if (config.sleeping) {
return null;
}

// Create and format date and time strings
LocalDateTime currentDateTime = LocalDateTime.now();
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Expand Down Expand Up @@ -341,27 +343,28 @@ public Response getResponseStream(String text, List<String> imageUrls) {
// files

// tools (lame)

OptionsBuilder optionBuilder = new OptionsBuilder();
Options options = optionBuilder.build();


OllamaChatRequestModel request = new OllamaChatRequestModel(config.model, msgList);

OllamaAPI ollamaApi = getOllamaApi();
String responseText = null;

if (imageUrls != null) {
OllamaResult result = ollamaApi.generateWithImageURLs(config.model, text, imageUrls, options, handler);
OllamaResult result = ollamaApi.generateWithImageURLs(config.model, text, imageUrls, options, handler);
responseText = result.getResponse();
} else {
OllamaChatResult result = ollamaApi.chat(request, handler);
history.add(new OllamaChatMessage(OllamaChatMessageRole.ASSISTANT, result.getResponse()));
responseText = result.getResponse();
}

// we are at the end of our response of streaming, and now the "result" will unblock signalling the end of the response
// now we have to check to see if there is any extra text on the end that did not get published

// we are at the end of our response of streaming, and now the "result"
// will unblock signalling the end of the response
// now we have to check to see if there is any extra text on the end that
// did not get published
if (handler.sentenceBuilder[0] != null && handler.sentenceBuilder[0].toString().trim().length() > 0) {
invoke("publishText", handler.sentenceBuilder[0].toString());

Expand All @@ -374,11 +377,10 @@ public Response getResponseStream(String text, List<String> imageUrls) {
utterance.channelBotName = currentBotName;
utterance.channelName = currentChannelName;
invoke("publishUtterance", utterance);



Response response = new Response("friend", getName(), handler.sentenceBuilder[0].toString(), null);
invoke("publishResponse", response);

}

Response response = new Response("friend", getName(), responseText, null);
Expand Down Expand Up @@ -433,12 +435,10 @@ public void accept(String message) {
utterance.channelBotName = currentBotName;
utterance.channelName = currentChannelName;
invoke("publishUtterance", utterance);



Response response = new Response("friend", getName(), potentialSentence, null);
invoke("publishResponse", response);


// Keep any remaining text after the last sentence-ending character
sentenceBuilder[0] = new StringBuilder(sentenceBuilder[0].substring(lastSentenceEndIndex + 1));
}
Expand Down Expand Up @@ -729,7 +729,14 @@ public void onImage(ImageData img) {
if (img.src.startsWith("/") || img.src.contains(":\\")) {
// absolute path already
fileUrl.append("file://");
fileUrl.append(img.src);
// Windows :()
if (img.src != null) {
fileUrl.append(img.src.replace("\\", "/"));
}
if (img.source != null) {
fileUrl.append(img.source.replace("\\", "/"));
}

} else {
// assume relative
File file = new File(img.src);
Expand Down Expand Up @@ -757,7 +764,7 @@ public static void main(String[] args) {
webgui.startService();

Runtime.start("cv", "OpenCV");

boolean done = true;
if (done) {
return;
Expand Down

0 comments on commit ddf92c6

Please sign in to comment.