updated listModelsFromLibrary API

updated `listModelsFromLibrary` API
This commit is contained in:
amithkoujalgi 2024-11-08 10:00:43 +05:30
parent 9c3fc49df1
commit 057f0babeb
No known key found for this signature in database
GPG Key ID: E29A37746AF94B70
3 changed files with 31 additions and 1333 deletions

File diff suppressed because it is too large Load Diff

View File

@ -194,16 +194,30 @@ public class OllamaAPI {
for (Element e : modelSections) {
LibraryModel model = new LibraryModel();
Elements names = e.select("div > h2 > span");
Elements desc = e.select("div > p");
Elements pullCounts = e.select("div:nth-of-type(2) > p > span:first-of-type > span:first-of-type");
Elements popularTags = e.select("div > div > span");
Elements tagCount = e.select("div:nth-of-type(2) > p > span:nth-of-type(2) > span:first-of-type");
Elements updatedAt = e.select("div:nth-of-type(2) > p > span:nth-of-type(3) > span:nth-of-type(2)");
Elements totalTags = e.select("div:nth-of-type(2) > p > span:nth-of-type(2) > span:first-of-type");
Elements lastUpdatedTime = e.select("div:nth-of-type(2) > p > span:nth-of-type(3) > span:nth-of-type(2)");
if (names.first() == null || names.isEmpty()) {
// if name cannot be extracted, skip.
continue;
}
Optional.ofNullable(names.first())
.map(Element::text)
.ifPresent(model::setName);
model.setDescription(Optional.ofNullable(desc.first()).map(Element::text).orElse(""));
model.setPopularTags(Optional.of(popularTags)
.map(tags -> tags.stream().map(Element::text).collect(Collectors.toList()))
.orElse(new ArrayList<>()));
model.setPullCount(Optional.ofNullable(pullCounts.first()).map(Element::text).orElse(""));
model.setTotalTags(Optional.ofNullable(totalTags.first())
.map(Element::text)
.map(Integer::parseInt)
.orElse(0));
model.setLastUpdated(Optional.ofNullable(lastUpdatedTime.first()).map(Element::text).orElse(""));
model.setName(names.first().text());
model.setPullCount(pullCounts.first().text());
model.setPopularTags(popularTags.stream().map(Element::text).collect(Collectors.toList()));
model.setNumTags(Integer.parseInt(tagCount.first().text()));
model.setUpdatedAt(updatedAt.first().text());
models.add(model);
}
return models;

View File

@ -8,8 +8,9 @@ import lombok.Data;
public class LibraryModel {
private String name;
private String description;
private String pullCount;
private int numTags;
private int totalTags;
private List<String> popularTags = new ArrayList<>();
private String updatedAt;
private String lastUpdated;
}