SimpleChatTC:ChatMessageEx: Better tool result extractor
This commit is contained in:
parent
61b70bfa5d
commit
7dbbc46390
|
|
@ -91,7 +91,7 @@ class ChatMessageEx {
|
||||||
* Extract the elements of the all in one tool call result string
|
* Extract the elements of the all in one tool call result string
|
||||||
* @param {string} allInOne
|
* @param {string} allInOne
|
||||||
*/
|
*/
|
||||||
static extractToolCallResultAllInOne(allInOne) {
|
static extractToolCallResultAllInOneSimpleMinded(allInOne) {
|
||||||
const regex = /<tool_response>\s*<id>(.*?)<\/id>\s*<name>(.*?)<\/name>\s*<content>([\s\S]*?)<\/content>\s*<\/tool_response>/si;
|
const regex = /<tool_response>\s*<id>(.*?)<\/id>\s*<name>(.*?)<\/name>\s*<content>([\s\S]*?)<\/content>\s*<\/tool_response>/si;
|
||||||
const caught = allInOne.match(regex)
|
const caught = allInOne.match(regex)
|
||||||
let data = { tool_call_id: "Error", name: "Error", content: "Error" }
|
let data = { tool_call_id: "Error", name: "Error", content: "Error" }
|
||||||
|
|
@ -105,6 +105,29 @@ class ChatMessageEx {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the elements of the all in one tool call result string
|
||||||
|
* This should potentially account for content tag having xml content within to an extent.
|
||||||
|
* @param {string} allInOne
|
||||||
|
*/
|
||||||
|
static extractToolCallResultAllInOne(allInOne) {
|
||||||
|
const dParser = new DOMParser();
|
||||||
|
const got = dParser.parseFromString(allInOne, 'text/xml');
|
||||||
|
const parseErrors = got.querySelector('parseerror')
|
||||||
|
if (parseErrors) {
|
||||||
|
console.debug("WARN:ChatMessageEx:ExtractToolCallResultAllInOne:", parseErrors.textContent.trim())
|
||||||
|
}
|
||||||
|
const id = got.querySelector('id')?.textContent.trim();
|
||||||
|
const name = got.querySelector('name')?.textContent.trim();
|
||||||
|
const content = got.querySelector('content')?.textContent.trim();
|
||||||
|
let data = {
|
||||||
|
tool_call_id: id? id : "Error",
|
||||||
|
name: name? name : "Error",
|
||||||
|
content: content? content : "Error"
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set extra members into the ns object
|
* Set extra members into the ns object
|
||||||
* @param {string | number} key
|
* @param {string | number} key
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue