update
This commit is contained in:
120
src/interface.jl
120
src/interface.jl
@@ -300,21 +300,27 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
|
|||||||
end
|
end
|
||||||
|
|
||||||
# check whether all answer's key points are in responsedict
|
# check whether all answer's key points are in responsedict
|
||||||
_responsedictKey = keys(responsedict)
|
ispass, errormsg = checkAgentResponse_JSON(responsedict, requiredKeys)
|
||||||
responsedictKey = [i for i in _responsedictKey] # convert into a list
|
if !ispass
|
||||||
is_requiredKeys_in_responsedictKey = [i ∈ responsedictKey for i in requiredKeys]
|
errornote = errormsg
|
||||||
|
println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)> $responsedict", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||||
if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys)
|
|
||||||
errornote = "Your previous attempt has more key points than answer's required key points."
|
|
||||||
println("\nERROR YiemAgent decisionMaker() $errornote ----(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
|
||||||
elseif !all(is_requiredKeys_in_responsedictKey)
|
|
||||||
zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey)
|
|
||||||
missingkeys = [requiredKeys[i] for i in zeroind]
|
|
||||||
errornote = "$missingkeys are missing from your previous response"
|
|
||||||
println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
# _responsedictKey = keys(responsedict)
|
||||||
|
# responsedictKey = [i for i in _responsedictKey] # convert into a list
|
||||||
|
# is_requiredKeys_in_responsedictKey = [i ∈ responsedictKey for i in requiredKeys]
|
||||||
|
|
||||||
|
# if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys)
|
||||||
|
# errornote = "Your previous attempt has more key points than answer's required key points."
|
||||||
|
# println("\nERROR YiemAgent decisionMaker() $errornote ----(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
|
# continue
|
||||||
|
# elseif !all(is_requiredKeys_in_responsedictKey)
|
||||||
|
# zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey)
|
||||||
|
# missingkeys = [requiredKeys[i] for i in zeroind]
|
||||||
|
# errornote = "$missingkeys are missing from your previous response"
|
||||||
|
# println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
|
# continue
|
||||||
|
# end
|
||||||
|
|
||||||
if responsedict[:actionname] ∉ ["CHATBOX", "CHECKWINE", "PRESENTBOX", "ENDCONVERSATION"]
|
if responsedict[:actionname] ∉ ["CHATBOX", "CHECKWINE", "PRESENTBOX", "ENDCONVERSATION"]
|
||||||
errornote = "Your previous attempt didn't use the given functions"
|
errornote = "Your previous attempt didn't use the given functions"
|
||||||
@@ -538,19 +544,10 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext
|
|||||||
end
|
end
|
||||||
|
|
||||||
# check whether all answer's key points are in responsedict
|
# check whether all answer's key points are in responsedict
|
||||||
_responsedictKey = keys(responsedict)
|
ispass, errormsg = checkAgentResponse_JSON(responsedict, requiredKeys)
|
||||||
responsedictKey = [i for i in _responsedictKey] # convert into a list
|
if !ispass
|
||||||
is_requiredKeys_in_responsedictKey = [i ∈ responsedictKey for i in requiredKeys]
|
errornote = errormsg
|
||||||
|
println("\nERROR YiemAgent evaluator() $errornote --(not qualify response)> $responsedict", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||||
if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys)
|
|
||||||
errornote = "Your previous attempt has more key points than answer's required key points."
|
|
||||||
println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
|
||||||
elseif !all(is_requiredKeys_in_responsedictKey)
|
|
||||||
zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey)
|
|
||||||
missingkeys = [requiredKeys[i] for i in zeroind]
|
|
||||||
errornote = "$missingkeys are missing from your previous response"
|
|
||||||
println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -977,19 +974,10 @@ function presentbox(a::sommelier, thoughtDict; maxtattempt::Integer=10, recentev
|
|||||||
end
|
end
|
||||||
|
|
||||||
# check whether all answer's key points are in responsedict
|
# check whether all answer's key points are in responsedict
|
||||||
_responsedictKey = keys(responsedict)
|
ispass, errormsg = checkAgentResponse_JSON(responsedict, requiredKeys)
|
||||||
responsedictKey = [i for i in _responsedictKey] # convert into a list
|
if !ispass
|
||||||
is_requiredKeys_in_responsedictKey = [i ∈ responsedictKey for i in requiredKeys]
|
errornote = errormsg
|
||||||
|
println("\nERROR YiemAgent presentbox() $errornote --(not qualify response)> $responsedict", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||||
if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys)
|
|
||||||
errornote = "Your previous attempt has more key points than answer's required key points."
|
|
||||||
println("\nERROR YiemAgent presentbox() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
|
||||||
elseif !all(is_requiredKeys_in_responsedictKey)
|
|
||||||
zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey)
|
|
||||||
missingkeys = [requiredKeys[i] for i in zeroind]
|
|
||||||
errornote = "$missingkeys are missing from your previous response"
|
|
||||||
println("\nERROR YiemAgent presentbox() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1161,19 +1149,10 @@ function generatechat(a::sommelier, thoughtDict; maxattempt::Integer=10)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# check whether all answer's key points are in responsedict
|
# check whether all answer's key points are in responsedict
|
||||||
_responsedictKey = keys(responsedict)
|
ispass, errormsg = checkAgentResponse_JSON(responsedict, requiredKeys)
|
||||||
responsedictKey = [i for i in _responsedictKey] # convert into a list
|
if !ispass
|
||||||
is_requiredKeys_in_responsedictKey = [i ∈ responsedictKey for i in requiredKeys]
|
errornote = errormsg
|
||||||
|
println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)> $responsedict", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||||
if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys)
|
|
||||||
errornote = "Your previous attempt has more key points than answer's required key points."
|
|
||||||
println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
|
||||||
elseif !all(is_requiredKeys_in_responsedictKey)
|
|
||||||
zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey)
|
|
||||||
missingkeys = [requiredKeys[i] for i in zeroind]
|
|
||||||
errornote = "$missingkeys are missing from your previous response"
|
|
||||||
println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1327,16 +1306,15 @@ function generatechat(a::virtualcustomer;
|
|||||||
|
|
||||||
# check whether response has all header
|
# check whether response has all header
|
||||||
detected_kw = GeneralUtils.detectKeywordVariation(header, response)
|
detected_kw = GeneralUtils.detectKeywordVariation(header, response)
|
||||||
kwvalue = [i for i in values(detected_kw)]
|
missingkeys = [k for (k, v) in detected_kw if v === nothing]
|
||||||
zeroind = findall(x -> x == 0, kwvalue)
|
|
||||||
missingkeys = [header[i] for i in zeroind]
|
if !isempty(missingkeys)
|
||||||
if 0 ∈ values(detected_kw)
|
|
||||||
errornote = "$missingkeys are missing from your previous response"
|
errornote = "$missingkeys are missing from your previous response"
|
||||||
println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
println("\nERROR YiemAgent rolegenerator() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue
|
continue
|
||||||
elseif sum(values(detected_kw)) > length(header)
|
elseif sum([length(i) for i in values(detected_kw)]) > length(header)
|
||||||
errornote = "Your previous attempt has duplicated points"
|
errornote = "\nYour previous attempt has duplicated points according to the required response format"
|
||||||
println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
println("\nERROR YiemAgent rolegenerator() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1754,15 +1732,19 @@ function detectWineryName(a, text)
|
|||||||
println("\ndetectWineryName() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
println("\ndetectWineryName() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
try pprintln(response) catch e println(response) end
|
try pprintln(response) catch e println(response) end
|
||||||
|
|
||||||
# check whether response has all header
|
# check whether response has all header
|
||||||
detected_kw = GeneralUtils.detectKeywordVariation(header, response)
|
detected_kw = GeneralUtils.detectKeywordVariation(header, response)
|
||||||
if 0 ∈ values(detected_kw)
|
missingkeys = [k for (k, v) in detected_kw if v === nothing]
|
||||||
errornote = "\nYiemAgent detectWineryName() response does not have all header"
|
|
||||||
continue
|
if !isempty(missingkeys)
|
||||||
elseif sum(values(detected_kw)) > length(header)
|
errornote = "$missingkeys are missing from your previous response"
|
||||||
errornote = "\nYiemAgent detectWineryName() response has duplicated header"
|
println("\nERROR YiemAgent rolegenerator() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue
|
continue
|
||||||
end
|
elseif sum([length(i) for i in values(detected_kw)]) > length(header)
|
||||||
|
errornote = "\nYour previous attempt has duplicated points according to the required response format"
|
||||||
|
println("\nERROR YiemAgent rolegenerator() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
responsedict = GeneralUtils.textToDict(response, header;
|
responsedict = GeneralUtils.textToDict(response, header;
|
||||||
dictKey=dictkey, symbolkey=true)
|
dictKey=dictkey, symbolkey=true)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using GeneralUtils
|
|||||||
|
|
||||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||||
|
|
||||||
#[WORKING]
|
|
||||||
mutable struct appcontext
|
mutable struct appcontext
|
||||||
const connection::NATS.Connection
|
const connection::NATS.Connection
|
||||||
const text2textInstructLLMServiceSubject::String
|
const text2textInstructLLMServiceSubject::String
|
||||||
|
|||||||
44
src/util.jl
44
src/util.jl
@@ -1,7 +1,8 @@
|
|||||||
module util
|
module util
|
||||||
|
|
||||||
export clearhistory, addNewMessage, chatHistoryToText, eventdict, noises, createTimeline,
|
export clearhistory, addNewMessage, chatHistoryToText, eventdict, noises, createTimeline,
|
||||||
availableWineToText, createEventsLog, createChatLog
|
availableWineToText, createEventsLog, createChatLog, checkAgentResponse_JSON,
|
||||||
|
checkAgentResponse_text
|
||||||
|
|
||||||
using UUIDs, Dates, DataStructures, HTTP, JSON3
|
using UUIDs, Dates, DataStructures, HTTP, JSON3
|
||||||
using GeneralUtils
|
using GeneralUtils
|
||||||
@@ -411,12 +412,45 @@ function createChatLog(chatdict::T1; index::Union{UnitRange, Nothing}=nothing
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function checkAgentResponse_text(response::String, requiredHeader::T
|
||||||
|
)::Tuple where {T<:Array{String}}
|
||||||
|
detected_kw = GeneralUtils.detectKeywordVariation(requiredHeader, response)
|
||||||
|
missingkeys = [k for (k, v) in detected_kw if v === nothing]
|
||||||
|
ispass = false
|
||||||
|
errormsg = nothing
|
||||||
|
if !isempty(missingkeys)
|
||||||
|
errormsg = "$missingkeys are missing from your previous response"
|
||||||
|
ispass = false
|
||||||
|
elseif sum([length(i) for i in values(detected_kw)]) > length(requiredHeader)
|
||||||
|
errormsg = "Your previous attempt has duplicated points according to the required response format"
|
||||||
|
ispass = false
|
||||||
|
else
|
||||||
|
ispass = true
|
||||||
|
end
|
||||||
|
return (ispass, errormsg)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function checkAgentResponse_JSON(responsedict::Dict, requiredKeys::T
|
||||||
|
)::Tuple where {T<:Array{Symbol}}
|
||||||
|
_responsedictKey = keys(responsedict)
|
||||||
|
responsedictKey = [i for i in _responsedictKey] # convert into a list
|
||||||
|
is_requiredKeys_in_responsedictKey = [i ∈ responsedictKey for i in requiredKeys]
|
||||||
|
ispass = false
|
||||||
|
errormsg = nothing
|
||||||
|
if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys)
|
||||||
|
errormsg = "Your previous attempt has duplicated points according to the required response format"
|
||||||
|
ispass = false
|
||||||
|
elseif !all(is_requiredKeys_in_responsedictKey)
|
||||||
|
zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey)
|
||||||
|
missingkeys = [requiredKeys[i] for i in zeroind]
|
||||||
|
errormsg = "$missingkeys are missing from your previous response"
|
||||||
|
ispass = false
|
||||||
|
else
|
||||||
|
ispass = true
|
||||||
|
end
|
||||||
|
return (ispass, errormsg)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user