diff --git a/ballerina/agent.bal b/ballerina/agent.bal index 9ca6649..80b6611 100644 --- a/ballerina/agent.bal +++ b/ballerina/agent.bal @@ -16,8 +16,8 @@ import ballerina/io; import ballerina/lang.value; +import ballerina/lang.regexp; import ballerina/log; -import ballerina/regex; # Parsed response from the LLM. type NextTool record {| @@ -53,7 +53,6 @@ public class AgentIterator { } { return self.executor; } - } public class AgentExecutor { @@ -101,7 +100,7 @@ public class AgentExecutor { isCompleted: true }; } - string[] content = regex:split(llmResponse + "", "```"); + string[] content = regexp:split(re `${"```"}`, llmResponse + ""); if content.length() < 3 { log:printWarn("Unexpected LLM response is given", llmResponse = llmResponse); return error LlmActionParseError("Unable to extract the tool due to invalid generation", llmResponse = llmResponse, instruction = "Tool execution failed due to invalid generation. Regenerate following the given format."); @@ -348,8 +347,8 @@ isolated function normalizeLlmResponse(string llmResponse) returns string { } } } - thought = regex:replace(thought, "```json", "```"); - thought = regex:replaceAll(thought, "\"\\{\\}\"", "{}"); - thought = regex:replaceAll(thought, "\\\\\"", "\""); + thought = regexp:replace(re `${"```"}json`, thought, "```"); // replace ```json + thought = regexp:replaceAll(re `"\{\}"`, thought, "{}"); // replace "{}" + thought = regexp:replaceAll(re `\\"`, thought, "\""); // replace \" return thought; } diff --git a/ballerina/http_utils.bal b/ballerina/http_utils.bal index cb35df7..f424243 100644 --- a/ballerina/http_utils.bal +++ b/ballerina/http_utils.bal @@ -15,8 +15,8 @@ // under the License. import ballerina/http; +import ballerina/lang.regexp; import ballerina/mime; -import ballerina/regex; import ballerina/url; type QueryParamEncoding record { @@ -233,7 +233,7 @@ isolated function getParamEncodedPath(HttpTool tool, map? parameters) retu } json parameterValue = parameters.get(paramName); string value = check getSimpleStyleParams(paramName, parameterValue); - pathWithParams = regex:replaceAll(pathWithParams, string `\{${paramName}\}`, value); + pathWithParams = regexp:replaceAll(re `\{${paramName}\}`, pathWithParams, value); } else { if parameters.hasKey(paramName) { queryParams[paramName] = parameters.get(paramName); @@ -265,7 +265,7 @@ isolated function extractResponsePayload(string path, http:Response response) re json|xml|error body; string contentType = response.getContentType(); - match regex:split(contentType, ";")[0].trim() { + match regexp:split(re `;`, contentType)[0].trim() { mime:APPLICATION_JSON|mime:APPLICATION_XML|mime:TEXT_PLAIN|mime:TEXT_HTML|mime:TEXT_XML => { body = response.getTextPayload(); } diff --git a/ballerina/tests/mock-tools.bal b/ballerina/tests/mock-tools.bal index d4af828..bd75fe0 100644 --- a/ballerina/tests/mock-tools.bal +++ b/ballerina/tests/mock-tools.bal @@ -1,4 +1,4 @@ -import ballerina/regex; +import ballerina/lang.regexp; type SearchParams record {| string query; @@ -11,10 +11,10 @@ type CalculatorParams record {| // create two mock tools isolated function searchToolMock(*SearchParams params) returns string { string query = params.query.trim().toLowerAscii(); - if regex:matches(query, ".*girlfriend.*") { + if regexp:isFullMatch(re `.*girlfriend.*`, query) { return "Camila Morrone"; - } else if regex:matches(query, ".*age.*") { + } else if regexp:isFullMatch(re `.*age.*`, query) { return "25 years"; } else { diff --git a/ballerina/tool.bal b/ballerina/tool.bal index 50424e3..2e3dfe4 100644 --- a/ballerina/tool.bal +++ b/ballerina/tool.bal @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -import ballerina/regex; +import ballerina/lang.regexp; type AgentTool record {| string name; @@ -110,7 +110,7 @@ isolated function registerTool(map toolMap, Tool[] tools) AgentTool agentTool = { name: tool.name, - description: regex:replaceAll(tool.description, "\n", " "), + description: regexp:replaceAll(re `\n`, tool.description, ". "), variables: variables, constants: constants, caller: tool.caller diff --git a/ballerina/toolkit.bal b/ballerina/toolkit.bal index 022c057..3b14806 100644 --- a/ballerina/toolkit.bal +++ b/ballerina/toolkit.bal @@ -44,14 +44,6 @@ public type ParameterSchema record {| JsonSubSchema schema; |}; -// # Defines a HTTP parameter schema (can be query parameter or path parameters). -// public type Parameters record {| -// # A list of mandatory parameters -// string[] required?; -// # A map of parameter names and their types -// map schemas; -// |}; - # Defines an HTTP tool. This is a special type of tool that can be used to invoke HTTP resources. public type HttpTool record {| # Name of the Http resource tool @@ -259,4 +251,3 @@ public isolated class HttpServiceToolKit { return extractResponsePayload(path, optionsResult); } } -