This commit is contained in:
2025-03-11 00:14:51 +07:00
parent 25385c0798
commit 512fa4fd9d
3 changed files with 44 additions and 12 deletions

View File

@@ -586,10 +586,13 @@ function sendReceiveMqttMsg(mqttInstance::mqttClientInstance_v2, receivechannel:
)::NamedTuple where {T<:Any} )::NamedTuple where {T<:Any}
timepass = nothing timepass = nothing
attempts = 1 attempts = 0
while attempts <= maxattempt while attempts <= maxattempt
attempts += 1
if attempts > 1 if attempts > 1
println("attempts $attempts ", @__FILE__, " ", @__LINE__) println("\nsendReceiveMqttMsg() attempts $attempts ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
pprintln(outgoingMsg)
println("--------------\n")
end end
sendMqttMsg(mqttInstance, outgoingMsg) sendMqttMsg(mqttInstance, outgoingMsg)
@@ -616,8 +619,6 @@ function sendReceiveMqttMsg(mqttInstance::mqttClientInstance_v2, receivechannel:
end end
sleep(1) sleep(1)
end end
attempts += 1
end end
return (success=false, return (success=false,

View File

@@ -42,7 +42,8 @@ julia> formattedtext = YiemAgent.formatLLMtext_llama3instruct(d[:name], d[:text]
Signature Signature
""" """
function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString} function formatLLMtext_llama3instruct(name::T, text::T;
assistantStarter::Bool=true) where {T<:AbstractString}
formattedtext = formattedtext =
if name == "system" if name == "system"
""" """
@@ -58,6 +59,13 @@ function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString
""" """
end end
if assistantStarter
formattedtext *=
"""
<|start_header_id|>assistant<|end_header_id|>
"""
end
return formattedtext return formattedtext
end end
# function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString} # function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString}
@@ -80,6 +88,32 @@ end
# return formattedtext # return formattedtext
# end # end
function formatLLMtext_qwen(name::T, text::T;
assistantStarter::Bool=true) where {T<:AbstractString}
formattedtext =
if name == "system"
"""
<|im_start|>$name
$text
<|im_end|>
"""
else
"""
<|im_start|>$name
$text
<|im_end|>
"""
end
if assistantStarter
formattedtext *=
"""
<|im_start|>assistant
"""
end
return formattedtext
end
""" Convert a chat messages in vector of dictionary into LLM model instruct format. """ Convert a chat messages in vector of dictionary into LLM model instruct format.
@@ -116,7 +150,9 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}}; formatname::String="ll
elseif formatname == "mistral" elseif formatname == "mistral"
# not define yet # not define yet
elseif formatname == "phi3instruct" elseif formatname == "phi3instruct"
formatLLMtext_phi3instruct # not define yet
elseif formatname == "qwen"
formatLLMtext_qwen
else else
error("$formatname template not define yet") error("$formatname template not define yet")
end end
@@ -126,11 +162,6 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}}; formatname::String="ll
str *= f(t[:name], t[:text]) str *= f(t[:name], t[:text])
end end
# add <|assistant|> so that the model don't generate it and I don't need to clean it up later
if formatname == "phi3instruct"
str *= "<|assistant|>\n"
end
return str return str
end end

View File

@@ -319,7 +319,7 @@ function textToDict(text::String, detectKeywords::Vector{String};
od1[key] = str od1[key] = str
remainingtext = remainingtext[1:keywordidx[1]-1] remainingtext = remainingtext[1:keywordidx[1]-1]
else else
error("""keyword "$keyword" not found in the provided text""") error("""keyword "$keyword" not found in the provided text: $text </end of error note>""")
end end
end end