diff --git a/src/interface.jl b/src/interface.jl index 458c551..8b4a6cb 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -8,24 +8,50 @@ using LLMMCTS, GeneralUtils # ---------------------------------------------- 100 --------------------------------------------- # -""" +""" Attempt to correct JSON string. # Arguments + - `config::Dict` + A config containing services and mqttbroker info # Return # Example ```jldoctest -julia> +julia> config = Dict( + :mqttServerInfo => Dict( + :description => "mqtt server info", + :port => 1883, + :broker => "mqtt.yiem.cc" + ), + :externalservice => Dict( + :text2textinstruct => Dict( + :mqtttopic => "/loadbalancer/requestingservice", + :description => "text to text service with instruct LLM", + :llminfo => Dict(:name => "llama3instruct") + ), + ) + ) +julia> expectJSON = + " + Here is an expected JSON format: + { + explain: ..., + plan: ..., + action: {name: ..., input: ...}, + expectation: ..., + observation: ... + } + " ``` # TODO - [] update docstring - - [] implement the function + - [x] implement the function # Signature """ -function jsoncorrection(config::Dict, jsonstring::String, context; maxattempt=3) +function jsoncorrection(config::Dict, jsonstring::String, example; maxattempt=3) initialstate = Dict{Symbol, Any}( :reward=> 0, @@ -41,7 +67,7 @@ function jsoncorrection(config::Dict, jsonstring::String, context; maxattempt=3) transitionargs = ( config=config, - context=context, + context=example, ) _, result = LLMMCTS.runMCTS(initialstate, transition, transitionargs; totalsample=1, maxdepth=(maxattempt-1), maxiterations=1, explorationweight=1.0) diff --git a/test/runtest.jl b/test/runtest.jl index 9b707d8..2038e3b 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -4,15 +4,15 @@ using FormatCorrector 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 = +expectJSON = """ Here is an expected JSON format: { - "explain": ..., - "plan": ..., - "action": {"name": ..., "input": ...}, - "expectation": ..., - "observation": ... + explain: ..., + plan: ..., + action: {name: ..., input: ...}, + expectation: ..., + observation: ... } """ @@ -31,7 +31,7 @@ config = Dict( ) ) -result = FormatCorrector.jsoncorrection(config, incorrectjson, context) +result = FormatCorrector.jsoncorrection(config, incorrectjson, expectJSON) println(result)