diff --git a/src/interface.jl b/src/interface.jl index eacc7ec..25eb349 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -395,15 +395,21 @@ function conversation(a::sommelier; userinput::Union{Dict{String, Any}, JSON.Obj addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg) items_info = [] + send_item_ind = [] # index of the item being send to frontend if haskey(a.memory["shortmem"], "items_info") + for (i, item) in enumerate(a.memory["shortmem"]["items_info"]) if haskey(item, "wine_name") && occursin(item["wine_name"], thoughtdict["action_input"]) - push!(items_info, item) - deleteat!(a.memory["shortmem"]["items_info"], i) + push!(items_info, deepcopy(item)) + push!(send_item_ind, i) + end end - end + # remove sent items + deleteat!(a.memory["shortmem"]["items_info"], send_item_ind) + end + response_to_frontend = Dict{String, Any}( "role" => "assistant", "content" => [ @@ -431,15 +437,21 @@ function conversation(a::sommelier; userinput::Union{Dict{String, Any}, JSON.Obj addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg) items_info = [] + send_item_ind = [] # index of the item being send to frontend if haskey(a.memory["shortmem"], "items_info") + for (i, item) in enumerate(a.memory["shortmem"]["items_info"]) if haskey(item, "wine_name") && occursin(item["wine_name"], thoughtdict["action_input"]) - push!(items_info, item) - deleteat!(a.memory["shortmem"]["items_info"], i) + push!(items_info, deepcopy(item)) + push!(send_item_ind, i) + end end - end + # remove sent items + deleteat!(a.memory["shortmem"]["items_info"], send_item_ind) + end + response_to_frontend = Dict{String, Any}( "role" => "assistant", "content" => [ @@ -527,7 +539,14 @@ function think(a::T)::NamedTuple{(:thoughtdict, :result_raw), Tuple{OrderedDict, result_raw = nothing if thoughtdict["action_name"] ∈ ["CHAT_BOX"] - thoughtdict, result_raw = generatechat!(a) + # sometime CHAT_BOX input is too short. + # if thoughtdict["action_input] < 20 character, use generatechat!() + if length(thoughtdict["action_input"]) < 20 + thoughtdict, result_raw = generatechat!(a) + else + thoughtdict["action_result"] = "Action result is the next user dialogue." + result_raw = thoughtdict["action_input"] + end elseif thoughtdict["action_name"] == "END_CONVER_GUIDELINE"