Skip to content

Commit

Permalink
fixed file uris
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Nov 11, 2024
1 parent 2c6fd9c commit 22552b7
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/main/java/org/myrobotlab/service/LLM.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -722,31 +724,30 @@ public void clearHistory() {
userMessages.clear();
}

@Override
public void onImage(ImageData img) {
StringBuilder fileUrl = new StringBuilder();
if (img.encoding == null && img.src != null && (!img.src.startsWith("file://") && !img.src.startsWith("http://") && !img.src.startsWith("https://"))) {
if (img.src.startsWith("/") || img.src.contains(":\\")) {
// absolute path already
fileUrl.append("file://");
// Windows :()
if (img.src != null) {
fileUrl.append(img.src.replace("\\", "/"));
}
if (img.source != null) {
fileUrl.append(img.source.replace("\\", "/"));
public static URI toFileURI(String filePath) throws URISyntaxException {
try {
URI uri = new URI(filePath);
if (uri.isAbsolute()) {
return uri;
}

} else {
// assume relative
File file = new File(img.src);
fileUrl.append("file://");
fileUrl.append(file.getAbsolutePath());
}
} catch (URISyntaxException e) {
}

Path path = Paths.get(filePath);

return path.toUri();
}

@Override
public void onImage(ImageData img) {
try {
String src = (img.src != null)?img.src:img.source;
List<String> urls = new ArrayList<>();
urls.add(fileUrl.toString());
urls.add(toFileURI(src).toASCIIString());
getResponse(urls);
} catch(Exception e) {
error(e);
}
}

public static void main(String[] args) {
Expand Down

0 comments on commit 22552b7

Please sign in to comment.