Skip to content

Commit bcedafc

Browse files
committed
fix: fixed ollama json decoding of payload
1 parent 653fb9c commit bcedafc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

nerve-core/src/agent/generator/ollama.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ impl Client for OllamaClient {
196196

197197
if let Some(args) = call.function.arguments.as_ref() {
198198
for (name, value) in args {
199-
let str_val = value.to_string().trim_matches('"').to_string();
199+
let mut content = value.to_string();
200+
if let serde_json::Value::String(escaped_json) = &value {
201+
content = escaped_json.to_string();
202+
}
203+
204+
let str_val = content.trim_matches('"').to_string();
200205
if name == "payload" {
201206
payload = Some(str_val);
202207
} else {

nerve-core/src/agent/namespaces/filesystem/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,16 @@ impl Action for AppendToFile {
207207

208208
let content_to_append = if extension == "json" || extension == "jsonl" {
209209
// parse the payload as a JSON object
210-
if let Ok(value) = serde_json::from_str::<serde_json::Value>(&payload) {
210+
let parsed = serde_json::from_str::<serde_json::Value>(&payload);
211+
if let Ok(value) = parsed {
211212
// reconvert to make sure it's on a single line
212213
serde_json::to_string(&value).unwrap()
213214
} else {
214-
log::error!("can't parse payload as JSON: {}", payload);
215+
log::error!(
216+
"can't parse payload as JSON: {} - {}",
217+
parsed.err().unwrap(),
218+
payload
219+
);
215220
serde_json::to_string(&InvalidJSON { data: payload }).unwrap()
216221
}
217222
} else {

0 commit comments

Comments
 (0)