From 512fa4fd9d09788a2458581d5cc350e0aeffdcd8 Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Tue, 11 Mar 2025 00:14:51 +0700 Subject: [PATCH] update --- src/communication.jl | 9 +++++---- src/llmUtil.jl | 45 +++++++++++++++++++++++++++++++++++++------- src/util.jl | 2 +- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/communication.jl b/src/communication.jl index dd278b1..fc1027f 100644 --- a/src/communication.jl +++ b/src/communication.jl @@ -586,10 +586,13 @@ function sendReceiveMqttMsg(mqttInstance::mqttClientInstance_v2, receivechannel: )::NamedTuple where {T<:Any} timepass = nothing - attempts = 1 + attempts = 0 while attempts <= maxattempt + attempts += 1 if attempts > 1 - println("attempts $attempts ", @__FILE__, " ", @__LINE__) + println("\nsendReceiveMqttMsg() attempts $attempts ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + pprintln(outgoingMsg) + println("--------------\n") end sendMqttMsg(mqttInstance, outgoingMsg) @@ -616,8 +619,6 @@ function sendReceiveMqttMsg(mqttInstance::mqttClientInstance_v2, receivechannel: end sleep(1) end - - attempts += 1 end return (success=false, diff --git a/src/llmUtil.jl b/src/llmUtil.jl index 54f4f75..b0a90f7 100644 --- a/src/llmUtil.jl +++ b/src/llmUtil.jl @@ -42,7 +42,8 @@ julia> formattedtext = YiemAgent.formatLLMtext_llama3instruct(d[:name], d[:text] 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 = if name == "system" """ @@ -58,6 +59,13 @@ function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString """ end + if assistantStarter + formattedtext *= + """ + <|start_header_id|>assistant<|end_header_id|> + """ + end + return formattedtext end # function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString} @@ -80,6 +88,32 @@ end # return formattedtext # 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. @@ -116,7 +150,9 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}}; formatname::String="ll elseif formatname == "mistral" # not define yet elseif formatname == "phi3instruct" - formatLLMtext_phi3instruct + # not define yet + elseif formatname == "qwen" + formatLLMtext_qwen else error("$formatname template not define yet") end @@ -126,11 +162,6 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}}; formatname::String="ll str *= f(t[:name], t[:text]) 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 end diff --git a/src/util.jl b/src/util.jl index 4a38244..8021f85 100644 --- a/src/util.jl +++ b/src/util.jl @@ -319,7 +319,7 @@ function textToDict(text::String, detectKeywords::Vector{String}; od1[key] = str remainingtext = remainingtext[1:keywordidx[1]-1] else - error("""keyword "$keyword" not found in the provided text""") + error("""keyword "$keyword" not found in the provided text: $text """) end end