Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ddbb135b6b | |||
| afda364484 | |||
| af73d955eb | |||
| 39cf9a72a1 | |||
| 1c829ad854 | |||
| da98baddb6 | |||
| c5fbaabf42 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name = "YiemAgent"
|
name = "YiemAgent"
|
||||||
uuid = "e012c34b-7f78-48e0-971c-7abb83b6f0a2"
|
uuid = "e012c34b-7f78-48e0-971c-7abb83b6f0a2"
|
||||||
version = "0.7.0"
|
version = "0.7.2"
|
||||||
authors = ["narawat lamaiin <narawat@outlook.com>"]
|
authors = ["narawat lamaiin <narawat@outlook.com>"]
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|||||||
+36
-9
@@ -73,7 +73,7 @@ OrderedDict{String, Any} with 4 entries:
|
|||||||
"action_result" => "1) winery: Terrazze dell Etna, wine_name: Rose Brut.
|
"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}
|
) where {T<:agent}
|
||||||
@info "YiemAgent decisionMaker() start " @__LINE__
|
@info "YiemAgent decisionMaker() start " @__LINE__
|
||||||
# lessonDict = copy(JSON.parsefile("lesson.json"))
|
# lessonDict = copy(JSON.parsefile("lesson.json"))
|
||||||
@@ -187,7 +187,14 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
|
|||||||
@info "YiemAgent decisionMaker() end " @__LINE__
|
@info "YiemAgent decisionMaker() end " @__LINE__
|
||||||
return responsedict
|
return responsedict
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -395,15 +402,21 @@ function conversation(a::sommelier; userinput::Union{Dict{String, Any}, JSON.Obj
|
|||||||
addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg)
|
addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg)
|
||||||
|
|
||||||
items_info = []
|
items_info = []
|
||||||
|
send_item_ind = [] # index of the item being send to frontend
|
||||||
if haskey(a.memory["shortmem"], "items_info")
|
if haskey(a.memory["shortmem"], "items_info")
|
||||||
|
|
||||||
for (i, item) in enumerate(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"])
|
if haskey(item, "wine_name") && occursin(item["wine_name"], thoughtdict["action_input"])
|
||||||
push!(items_info, item)
|
push!(items_info, deepcopy(item))
|
||||||
deleteat!(a.memory["shortmem"]["items_info"], i)
|
push!(send_item_ind, i)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
# remove sent items
|
||||||
|
deleteat!(a.memory["shortmem"]["items_info"], send_item_ind)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
response_to_frontend = Dict{String, Any}(
|
response_to_frontend = Dict{String, Any}(
|
||||||
"role" => "assistant",
|
"role" => "assistant",
|
||||||
"content" => [
|
"content" => [
|
||||||
@@ -431,15 +444,21 @@ function conversation(a::sommelier; userinput::Union{Dict{String, Any}, JSON.Obj
|
|||||||
addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg)
|
addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg)
|
||||||
|
|
||||||
items_info = []
|
items_info = []
|
||||||
|
send_item_ind = [] # index of the item being send to frontend
|
||||||
if haskey(a.memory["shortmem"], "items_info")
|
if haskey(a.memory["shortmem"], "items_info")
|
||||||
|
|
||||||
for (i, item) in enumerate(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"])
|
if haskey(item, "wine_name") && occursin(item["wine_name"], thoughtdict["action_input"])
|
||||||
push!(items_info, item)
|
push!(items_info, deepcopy(item))
|
||||||
deleteat!(a.memory["shortmem"]["items_info"], i)
|
push!(send_item_ind, i)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
# remove sent items
|
||||||
|
deleteat!(a.memory["shortmem"]["items_info"], send_item_ind)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
response_to_frontend = Dict{String, Any}(
|
response_to_frontend = Dict{String, Any}(
|
||||||
"role" => "assistant",
|
"role" => "assistant",
|
||||||
"content" => [
|
"content" => [
|
||||||
@@ -527,7 +546,14 @@ function think(a::T)::NamedTuple{(:thoughtdict, :result_raw), Tuple{OrderedDict,
|
|||||||
result_raw = nothing
|
result_raw = nothing
|
||||||
if thoughtdict["action_name"] ∈ ["CHAT_BOX"]
|
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"
|
elseif thoughtdict["action_name"] == "END_CONVER_GUIDELINE"
|
||||||
|
|
||||||
@@ -784,6 +810,7 @@ function generatechat!(a::T; maxattempt::Integer=10
|
|||||||
@info "YiemAgent generatechat!() end " @__LINE__
|
@info "YiemAgent generatechat!() end " @__LINE__
|
||||||
return (thoughtdict=responsedict, result_raw=responsedict["action_input"])
|
return (thoughtdict=responsedict, result_raw=responsedict["action_input"])
|
||||||
end
|
end
|
||||||
|
@info "YiemAgent generatechat() failed to generate a thought " @__LINE__
|
||||||
error("YiemAgent generatechat() failed to generate a thought ", response)
|
error("YiemAgent generatechat() failed to generate a thought ", response)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user