diff --git a/src/interface.jl b/src/interface.jl index 3133bb1..2942510 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -89,8 +89,22 @@ function transition(state::T1, args::NamedTuple # only for the 1st transition if state[:errormsg] === nothing response, errormsg, reward, isterminal = executeJSON(state[:question]) - state[:response] = response - state[:errormsg] = errormsg + if isterminal == true # question already correct + # make new state + newNodeKey = GeneralUtils.uuid4snakecase() + newstate = deepcopy(state) + newstate[:code] = state[:question] + newstate[:response] = response + newstate[:errormsg] = errormsg + newstate[:errorexplain] = "already correct JSON" + newstate[:reward] = reward + newstate[:isterminal] = isterminal + + return (newNodeKey=newNodeKey, newstate=newstate, progressvalue=10) + else # prep for entering correction loop so that decisionMaker has errormsg to work with + state[:response] = response + state[:errormsg] = errormsg + end end explain, jsonstr = decisionMaker(state, config, context) @@ -215,9 +229,17 @@ function decisionMaker(state, config, context) _responseJsonStr = response[:response][:text] if length(split(_responseJsonStr, "Code:")) == 2 - return split(_responseJsonStr, "Code:") + x = split(_responseJsonStr, "Code:") + if occursin("Why", x[2]) + error("88") + end + return x elseif length(split(_responseJsonStr, "Code\":")) == 2 - return split(_responseJsonStr, "Code\":") + x = split(_responseJsonStr, "Code\":") + if occursin("Why", x[2]) + error("88") + end + return x else println("Trying to get Code part") end @@ -316,9 +338,6 @@ function executeJSON(jsonstring) showerror(io, e) errorMsg = String(take!(io)) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) - println("") - - println("") return (response=nothing, errormsg=errorMsg, reward=0, isterminal=false) end end diff --git a/test/runtest.jl b/test/runtest.jl index 887d990..9b707d8 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -1,8 +1,9 @@ using FormatCorrector -incorrectjson = " \"explain\": \"The user is asking about wines that are suitable for pairing with lamb. I need to explore the database to find relevant information.\",\n \"plan\":\n 1) List all tables in the database using the function `listalltables` to get an idea of what data is available.\n \"action\": {\"name\": \"listalltables\", \"input\": null},\n \"expectation\": The list of all tables in the database,\n \"observation\": null\n}" - +incorrectjson = "{\n \"explain\": \"The user is asking for information about wines that can be paired with lamb. This seems like a straightforward question, but it's not clear which database tables will contain the relevant information. I'll start by listing all available tables to see if any of them have columns related to wine and food pairing.\",\n \"plan\":\n \"1) List all tables in the database using 'listalltables',\n 2) Check each table for columns related to wine and food pairing\",\n \"action\": {\"name\": \"listalltables\", \"input\": \"\"},\n \"expectation\": \"A list of all available tables in the database, which will help me identify potential tables that might contain relevant information.\",\n \"observation\": \"\"\n}" +# incorrectjson = "{\"t\":5}" + context = """ Here is an expected JSON format: @@ -32,7 +33,13 @@ config = Dict( result = FormatCorrector.jsoncorrection(config, incorrectjson, context) -println("done") +println(result) + + + + + +