Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ddbb135b6b | |||
| afda364484 | |||
| af73d955eb | |||
| 39cf9a72a1 | |||
| 1c829ad854 | |||
| da98baddb6 | |||
| c5fbaabf42 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
name = "YiemAgent"
|
||||
uuid = "e012c34b-7f78-48e0-971c-7abb83b6f0a2"
|
||||
version = "0.7.0"
|
||||
version = "0.7.2"
|
||||
authors = ["narawat lamaiin <narawat@outlook.com>"]
|
||||
|
||||
[deps]
|
||||
|
||||
+34
-7
@@ -73,7 +73,7 @@ OrderedDict{String, Any} with 4 entries:
|
||||
"action_result" => "1) winery: Terrazze dell Etna, wine_name: Rose Brut.
|
||||
```
|
||||
"""
|
||||
function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
|
||||
function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
|
||||
) where {T<:agent}
|
||||
@info "YiemAgent decisionMaker() start " @__LINE__
|
||||
# lessonDict = copy(JSON.parsefile("lesson.json"))
|
||||
@@ -187,7 +187,14 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
|
||||
@info "YiemAgent decisionMaker() end " @__LINE__
|
||||
return responsedict
|
||||
end
|
||||
error("DecisionMaker failed to generate a thought ", response)
|
||||
|
||||
# in case decisionMaker failed, force to use generatechat!()
|
||||
responsedict = OrderedDict(
|
||||
"plan"=> "N/A",
|
||||
"action_name"=> "CHAT_BOX",
|
||||
"action_input"=> "N/A"
|
||||
)
|
||||
return responsedict
|
||||
end
|
||||
|
||||
|
||||
@@ -395,13 +402,19 @@ 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
|
||||
# remove sent items
|
||||
deleteat!(a.memory["shortmem"]["items_info"], send_item_ind)
|
||||
|
||||
end
|
||||
|
||||
response_to_frontend = Dict{String, Any}(
|
||||
@@ -431,13 +444,19 @@ 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
|
||||
# remove sent items
|
||||
deleteat!(a.memory["shortmem"]["items_info"], send_item_ind)
|
||||
|
||||
end
|
||||
|
||||
response_to_frontend = Dict{String, Any}(
|
||||
@@ -527,7 +546,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"
|
||||
|
||||
@@ -784,6 +810,7 @@ function generatechat!(a::T; maxattempt::Integer=10
|
||||
@info "YiemAgent generatechat!() end " @__LINE__
|
||||
return (thoughtdict=responsedict, result_raw=responsedict["action_input"])
|
||||
end
|
||||
@info "YiemAgent generatechat() failed to generate a thought " @__LINE__
|
||||
error("YiemAgent generatechat() failed to generate a thought ", response)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user