update
This commit is contained in:
@@ -1024,7 +1024,7 @@ julia> response = ChatAgent.conversation(newAgent, "Hi! how are you?")
|
|||||||
"""
|
"""
|
||||||
function conversation(a::sommelier; userinput::Union{Dict, Nothing}=nothing,
|
function conversation(a::sommelier; userinput::Union{Dict, Nothing}=nothing,
|
||||||
maximumMsg=50)
|
maximumMsg=50)
|
||||||
#[WORKING] add the ability to start the conversation by sommelier
|
|
||||||
# place holder
|
# place holder
|
||||||
actionname = nothing
|
actionname = nothing
|
||||||
result = nothing
|
result = nothing
|
||||||
@@ -1890,64 +1890,12 @@ function generatechat(a::companion; recentevents::Integer=10,
|
|||||||
end
|
end
|
||||||
error("generatechat failed to generate a response")
|
error("generatechat failed to generate a response")
|
||||||
end
|
end
|
||||||
# function generatechat(a::companion; converPartnerName::Union{String, Nothing}=nothing, maxattempt=10)
|
|
||||||
# response = nothing # placeholder for show when error msg show up
|
|
||||||
# errornote = "N/A"
|
|
||||||
# llmkwargs=Dict(
|
|
||||||
# :num_ctx => 32768,
|
|
||||||
# :temperature => 0.5,
|
|
||||||
# )
|
|
||||||
# for attempt in 1:maxattempt
|
|
||||||
# if attempt > 1
|
|
||||||
# println("\nYiemAgent generatechat() attempt $attempt/$maxattempt ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
# end
|
|
||||||
|
|
||||||
# systemmsg = a.systemmsg * "\nP.S. $errornote\n"
|
|
||||||
# _prompt =
|
|
||||||
# [
|
|
||||||
# Dict(:name => "system", :text => systemmsg),
|
|
||||||
# ]
|
|
||||||
# for i in a.chathistory
|
|
||||||
# tempdict = Dict{Symbol, String}()
|
|
||||||
# for j in keys(i)
|
|
||||||
# if j ∉ [:timestamp]
|
|
||||||
# tempdict[j] = i[j]
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# _prompt = vcat(_prompt, tempdict)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # put in model format
|
|
||||||
# _prompt = GeneralUtils.formatLLMtext(_prompt, a.llmFormatName)
|
|
||||||
|
|
||||||
# # replace user and assistant with partner name
|
|
||||||
# prompt = replace(_prompt, "|>user"=>"|>$(converPartnerName)")
|
|
||||||
# prompt = replace(prompt, "|>assistant"=>"|>$(a.name)")
|
|
||||||
|
|
||||||
# response = a.func[:text2textInstructLLM](prompt; llmkwargs=llmkwargs, senderId=a.id)
|
|
||||||
# response = replace(response, "<|im_start|>"=> "")
|
|
||||||
# response = GeneralUtils.deFormatLLMtext(response, a.llmFormatName)
|
|
||||||
# think, response = GeneralUtils.extractthink(response)
|
|
||||||
|
|
||||||
# # check whether LLM just repeat the previous dialogue
|
|
||||||
# for msg in a.chathistory
|
|
||||||
# if msg[:text] == response
|
|
||||||
# errornote = "In your previous attempt, you repeated the previous dialogue. Please try again."
|
|
||||||
# println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
# continue
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# return response
|
|
||||||
# end
|
|
||||||
# error("generatechat failed to generate a response")
|
|
||||||
# end
|
|
||||||
|
|
||||||
|
|
||||||
# modify it to work with customer object
|
# modify it to work with customer object
|
||||||
function generatechat(a::virtualcustomer;
|
function generatechat(a::virtualcustomer;
|
||||||
converPartnerName::Union{String, Nothing}=nothing, maxattempt=10, recentEventNum=10
|
converPartnerName::Union{String, Nothing}=nothing, maxattempt=10, recentEventNum=10
|
||||||
)
|
)
|
||||||
|
|
||||||
recent_ind = GeneralUtils.recentElementsIndex(length(a.memory[:events]), recentEventNum; includelatest=true)
|
recent_ind = GeneralUtils.recentElementsIndex(length(a.memory[:events]), recentEventNum; includelatest=true)
|
||||||
recentEventsDict = createEventsLog(a.memory[:events]; index=recent_ind)
|
recentEventsDict = createEventsLog(a.memory[:events]; index=recent_ind)
|
||||||
response = nothing # placeholder for show when error msg show up
|
response = nothing # placeholder for show when error msg show up
|
||||||
@@ -1985,15 +1933,6 @@ function generatechat(a::virtualcustomer;
|
|||||||
response = GeneralUtils.deFormatLLMtext(response, a.llmFormatName)
|
response = GeneralUtils.deFormatLLMtext(response, a.llmFormatName)
|
||||||
think, response = GeneralUtils.extractthink(response)
|
think, response = GeneralUtils.extractthink(response)
|
||||||
|
|
||||||
# check whether LLM just repeat the previous dialogue
|
|
||||||
for msg in a.chathistory
|
|
||||||
if msg[:text] == response
|
|
||||||
errornote = "In your previous attempt, you repeated the previous dialogue. Please try again."
|
|
||||||
println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# check whether response has all header
|
# check whether response has all header
|
||||||
detected_kw = GeneralUtils.detect_keyword(header, response)
|
detected_kw = GeneralUtils.detect_keyword(header, response)
|
||||||
kwvalue = [i for i in values(detected_kw)]
|
kwvalue = [i for i in values(detected_kw)]
|
||||||
@@ -2024,7 +1963,19 @@ function generatechat(a::virtualcustomer;
|
|||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# check whether LLM just repeat the previous dialogue
|
||||||
|
dublicate = false
|
||||||
|
for msg in a.chathistory
|
||||||
|
if msg[:text] == responsedict[:dialogue]
|
||||||
|
errornote = "In your previous attempt, you repeated the earlier dialogue. Please try again."
|
||||||
|
println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
|
dublicate = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if dublicate
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
# println("\n$prompt", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
# println("\n$prompt", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
# println("\n $response")
|
# println("\n $response")
|
||||||
|
|||||||
Reference in New Issue
Block a user