This commit is contained in:
narawat lamaiin
2024-06-25 07:26:57 +07:00
parent 21e48c31ca
commit 69c42beeca
2 changed files with 36 additions and 10 deletions

View File

@@ -89,8 +89,22 @@ function transition(state::T1, args::NamedTuple
# only for the 1st transition # only for the 1st transition
if state[:errormsg] === nothing if state[:errormsg] === nothing
response, errormsg, reward, isterminal = executeJSON(state[:question]) response, errormsg, reward, isterminal = executeJSON(state[:question])
state[:response] = response if isterminal == true # question already correct
state[:errormsg] = errormsg # 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 end
explain, jsonstr = decisionMaker(state, config, context) explain, jsonstr = decisionMaker(state, config, context)
@@ -215,9 +229,17 @@ function decisionMaker(state, config, context)
_responseJsonStr = response[:response][:text] _responseJsonStr = response[:response][:text]
if length(split(_responseJsonStr, "Code:")) == 2 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 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 else
println("Trying to get Code part") println("Trying to get Code part")
end end
@@ -316,9 +338,6 @@ function executeJSON(jsonstring)
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("")
println("")
return (response=nothing, errormsg=errorMsg, reward=0, isterminal=false) return (response=nothing, errormsg=errorMsg, reward=0, isterminal=false)
end end
end end

View File

@@ -1,8 +1,9 @@
using FormatCorrector 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 = context =
""" """
Here is an expected JSON format: Here is an expected JSON format:
@@ -32,7 +33,13 @@ config = Dict(
result = FormatCorrector.jsoncorrection(config, incorrectjson, context) result = FormatCorrector.jsoncorrection(config, incorrectjson, context)
println("done") println(result)