feat(llm): LLMResult.tool_calls from OpenAI-shaped responses
Parse choices[0].message.tool_calls into the ask Result; empty list when absent. Offline gold covers tool_calls_from. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
46d78c6e15
commit
2d412e3bba
7 files changed
+83
-16
No files matched your search
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: llm tool_calls offline
|
||||
description: Parse OpenAI-shaped tool_calls into a list; no network.
|
||||
import openai:ext/ai/llm/openai.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**raw = "{\"choices\":[{\"finish_reason\":\"tool_calls\",\"message\":{\"role\":\"assistant\",\"content\":null,\"tool_calls\":[{\"id\":\"call_1\",\"type\":\"function\",\"function\":{\"name\":\"lookup\",\"arguments\":\"{\\\"q\\\":\\\"marqdo\\\"}\"}}]}}]}"**
|
||||
**data = > json.parse text=`raw`**
|
||||
**tc = > openai.tool_calls_from data=`data`**
|
||||
**n = > len value=`tc`**
|
||||
> print text=`n`
|
||||
**first = [1](tc)**
|
||||
> print text=[id](`first`)
|
||||
> print text=[type](`first`)
|
||||
**fn = [function](first)**
|
||||
> print text=[name](`fn`)
|
||||
|
||||
**empty_data = > json.parse text={"choices":[{"message":{"role":"assistant","content":"hi"}}]}**
|
||||
**empty = > openai.tool_calls_from data=`empty_data`**
|
||||
**en = > len value=`empty`**
|
||||
> print text=`en`
|
||||
+5
-5
@@ -4041,21 +4041,21 @@ fn ext_llm_meta_offline() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_llm_entry_prompt_offline() {
|
||||
fn ext_llm_tool_calls_offline() {
|
||||
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "tests/ext/llm-entry-prompt-offline.mq.md"])
|
||||
.args(["run", "tests/ext/llm-tool-calls-offline.mq.md"])
|
||||
.env("MARQDO_EXT", root.join("ext"))
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
.expect("run llm-entry-prompt-offline");
|
||||
.expect("run llm-tool-calls-offline");
|
||||
let code = output.status.code().unwrap_or(1);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert_eq!(code, 0, "llm-entry-prompt-offline stderr={stderr}");
|
||||
assert_eq!(code, 0, "llm-tool-calls-offline stderr={stderr}");
|
||||
assert_eq!(
|
||||
stdout.trim_end(),
|
||||
"Say hello to Marqdo.\n\n# main\n\n**raw = > sys.module_source**\n**p = > llm.prompt_body src=`raw`**\n> print text=`p`",
|
||||
"1\ncall_1\nfunction\nlookup\n0",
|
||||
"stdout={stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user