Skip to content

Commit ddf92c6

Browse files
committed
fixed method query
1 parent 16e75b4 commit ddf92c6

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

src/main/java/org/myrobotlab/codec/CodecUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ static public Message pathToMsg(String from, String path) {
10961096
String[] parts = path.split("/"); // <- this breaks things ! e.g.
10971097
// /runtime/connect/"http://localhost:8888"
10981098
// path parts less than 3 is a dir or ls
1099-
if (parts.length < 3) {
1099+
if (parts.length < 3 || (parts.length == 3 && path.endsWith("/"))) {
11001100
// this morphs a path which has less than 3 parts
11011101
// into a runtime "ls" method call to do reflection of services or
11021102
// service methods
@@ -1109,7 +1109,7 @@ static public Message pathToMsg(String from, String path) {
11091109
}
11101110

11111111
// ["", "runtime", "shutdown"]
1112-
if (parts.length == 3) {
1112+
if (parts.length == 3 && !path.endsWith("/")) {
11131113
msg.name = parts[1];
11141114
msg.method = parts[2];
11151115
return msg;

src/main/java/org/myrobotlab/service/LLM.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public class LLM extends Service<LLMConfig> implements TextListener, TextPublish
8787
protected String currentChannelName;
8888

8989
protected String currentChannelType;
90-
90+
9191
transient protected OllamaAPI api = null;
92-
92+
9393
protected String ollam4JUrl = "";
9494

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

141141
}
142142

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

254254
/***
255255
* Converts images into a default chat completion prompt
256+
*
256257
* @param imageUrls
257258
* @return
258259
*/
@@ -262,24 +263,25 @@ public Response getResponse(List<String> imageUrls) {
262263

263264
/**
264265
* convert images to array of bytes
266+
*
265267
* @param text
266268
* @param imageUrls
267269
* @return
268270
*/
269271
public Response getResponse(String text, List<String> imageUrls) {
270-
// List<byte[]> bimages = null;
271-
// if (images != null) {
272-
// bimages = new ArrayList<>();
273-
// for (String uri : images) {
274-
// if (uri.startsWith("file://")) {
275-
// try {
276-
// bimages.add(readUriContent(uri));
277-
// } catch (Exception e) {
278-
// error(e);
279-
// }
280-
// }
281-
// }
282-
// }
272+
// List<byte[]> bimages = null;
273+
// if (images != null) {
274+
// bimages = new ArrayList<>();
275+
// for (String uri : images) {
276+
// if (uri.startsWith("file://")) {
277+
// try {
278+
// bimages.add(readUriContent(uri));
279+
// } catch (Exception e) {
280+
// error(e);
281+
// }
282+
// }
283+
// }
284+
// }
283285
return getResponseStream(text, imageUrls);
284286
}
285287

@@ -293,7 +295,7 @@ public Response getResponseStream(String text, List<String> imageUrls) {
293295
if (config.sleeping) {
294296
return null;
295297
}
296-
298+
297299
// Create and format date and time strings
298300
LocalDateTime currentDateTime = LocalDateTime.now();
299301
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@@ -341,27 +343,28 @@ public Response getResponseStream(String text, List<String> imageUrls) {
341343
// files
342344

343345
// tools (lame)
344-
346+
345347
OptionsBuilder optionBuilder = new OptionsBuilder();
346348
Options options = optionBuilder.build();
347-
348349

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

351352
OllamaAPI ollamaApi = getOllamaApi();
352353
String responseText = null;
353-
354+
354355
if (imageUrls != null) {
355-
OllamaResult result = ollamaApi.generateWithImageURLs(config.model, text, imageUrls, options, handler);
356+
OllamaResult result = ollamaApi.generateWithImageURLs(config.model, text, imageUrls, options, handler);
356357
responseText = result.getResponse();
357358
} else {
358359
OllamaChatResult result = ollamaApi.chat(request, handler);
359360
history.add(new OllamaChatMessage(OllamaChatMessageRole.ASSISTANT, result.getResponse()));
360361
responseText = result.getResponse();
361362
}
362-
363-
// we are at the end of our response of streaming, and now the "result" will unblock signalling the end of the response
364-
// now we have to check to see if there is any extra text on the end that did not get published
363+
364+
// we are at the end of our response of streaming, and now the "result"
365+
// will unblock signalling the end of the response
366+
// now we have to check to see if there is any extra text on the end that
367+
// did not get published
365368
if (handler.sentenceBuilder[0] != null && handler.sentenceBuilder[0].toString().trim().length() > 0) {
366369
invoke("publishText", handler.sentenceBuilder[0].toString());
367370

@@ -374,11 +377,10 @@ public Response getResponseStream(String text, List<String> imageUrls) {
374377
utterance.channelBotName = currentBotName;
375378
utterance.channelName = currentChannelName;
376379
invoke("publishUtterance", utterance);
377-
378-
380+
379381
Response response = new Response("friend", getName(), handler.sentenceBuilder[0].toString(), null);
380382
invoke("publishResponse", response);
381-
383+
382384
}
383385

384386
Response response = new Response("friend", getName(), responseText, null);
@@ -433,12 +435,10 @@ public void accept(String message) {
433435
utterance.channelBotName = currentBotName;
434436
utterance.channelName = currentChannelName;
435437
invoke("publishUtterance", utterance);
436-
437-
438+
438439
Response response = new Response("friend", getName(), potentialSentence, null);
439440
invoke("publishResponse", response);
440441

441-
442442
// Keep any remaining text after the last sentence-ending character
443443
sentenceBuilder[0] = new StringBuilder(sentenceBuilder[0].substring(lastSentenceEndIndex + 1));
444444
}
@@ -729,7 +729,14 @@ public void onImage(ImageData img) {
729729
if (img.src.startsWith("/") || img.src.contains(":\\")) {
730730
// absolute path already
731731
fileUrl.append("file://");
732-
fileUrl.append(img.src);
732+
// Windows :()
733+
if (img.src != null) {
734+
fileUrl.append(img.src.replace("\\", "/"));
735+
}
736+
if (img.source != null) {
737+
fileUrl.append(img.source.replace("\\", "/"));
738+
}
739+
733740
} else {
734741
// assume relative
735742
File file = new File(img.src);
@@ -757,7 +764,7 @@ public static void main(String[] args) {
757764
webgui.startService();
758765

759766
Runtime.start("cv", "OpenCV");
760-
767+
761768
boolean done = true;
762769
if (done) {
763770
return;

0 commit comments

Comments
 (0)