Skip to content

Commit 6e23833

Browse files
committed
fix: patch to handle json parsing issues in flm
1 parent 1badec5 commit 6e23833

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
diff --git a/src/cpp/server/model_manager.cpp b/src/cpp/server/model_manager.cpp
2+
index 19371d57..a5d9e077 100644
3+
--- a/src/cpp/server/model_manager.cpp
4+
+++ b/src/cpp/server/model_manager.cpp
5+
@@ -1456,8 +1456,10 @@ std::vector<std::string> ModelManager::get_flm_installed_models() {
6+
#endif
7+
8+
// Parse output: { "models": [ { "name": "modelname:tag", ... }, ... ] }
9+
+ // FLM may emit log lines to stdout before the JSON, so find the first '{'.
10+
try {
11+
- json j = JsonUtils::parse(output);
12+
+ size_t json_start = output.find('{');
13+
+ json j = JsonUtils::parse(json_start != std::string::npos ? output.substr(json_start) : output);
14+
if (j.contains("models") && j["models"].is_array()) {
15+
for (const auto& model : j["models"]) {
16+
if (model.contains("name") && model["name"].is_string()) {
17+
@@ -1537,8 +1539,10 @@ std::vector<ModelInfo> ModelManager::get_flm_available_models() {
18+
#endif
19+
20+
// Parse output: { "models": [ { "name": "modelname:tag", "footprint": 1.23, ... }, ... ] }
21+
+ // FLM may emit log lines to stdout before the JSON, so find the first '{'.
22+
try {
23+
- json j = JsonUtils::parse(output);
24+
+ size_t json_start = output.find('{');
25+
+ json j = JsonUtils::parse(json_start != std::string::npos ? output.substr(json_start) : output);
26+
if (j.contains("models") && j["models"].is_array()) {
27+
for (const auto& m : j["models"]) {
28+
if (m.contains("name") && m["name"].is_string()) {
29+
diff --git a/src/cpp/server/system_info.cpp b/src/cpp/server/system_info.cpp
30+
index 9b60150e..df8c37cd 100644
31+
--- a/src/cpp/server/system_info.cpp
32+
+++ b/src/cpp/server/system_info.cpp
33+
@@ -1489,8 +1489,11 @@ std::string SystemInfo::get_flm_version() {
34+
#endif
35+
36+
// Parse JSON output: { "version": "0.9.34" }
37+
+ // FLM may emit log lines to stdout before the JSON (e.g. "[FLM] Using custom model list path: ...")
38+
+ // so find the first '{' and parse from there.
39+
try {
40+
- json j = JsonUtils::parse(output);
41+
+ size_t json_start = output.find('{');
42+
+ json j = JsonUtils::parse(json_start != std::string::npos ? output.substr(json_start) : output);
43+
if (j.contains("version") && j["version"].is_string()) {
44+
std::string version = j["version"].get<std::string>();
45+
// If the version doesn't start with 'v', prepend it

snap/snapcraft.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ parts:
215215
VERSION=$(git describe --tags --abbrev=10)
216216
craftctl set version=$VERSION
217217
fi
218+
for patch in $CRAFT_PROJECT_DIR/snap/local/patches/*.patch; do
219+
patch -p1 --forward --reject-file=- < "$patch" || true
220+
done
218221
override-build: |
219222
craftctl default
220223

0 commit comments

Comments
 (0)