diff --git a/src/llmUtil.jl b/src/llmUtil.jl index 4a8a58f..a021dd9 100644 --- a/src/llmUtil.jl +++ b/src/llmUtil.jl @@ -1,6 +1,6 @@ module llmUtil -export formatLLMtext, formatLLMtext_llama3instruct, jsoncorrection, deFormatLLMtext +export formatLLMtext, formatLLMtext_llama3instruct, jsoncorrection, deFormatLLMtext, extractthink using UUIDs, JSON3, Dates using GeneralUtils @@ -255,7 +255,7 @@ julia> normalText = YiemAgent.deFormatLLMtext(response, "granite3") "This is a sample system instruction." ``` """ -function deFormatLLMtext(text::String, formatname::String +function deFormatLLMtext(text::String, formatname::String; includethink::Bool=false )::String f = if formatname == "granite3" @@ -306,29 +306,33 @@ function deFormatLLMtext_granite3(text::String)::Union{Nothing, String} end -function deFormatLLMtext_qwen3(text::String; includethink::Bool=false)::Union{Nothing, String} - think = nothing - str = nothing - - if occursin("", text) - r = GeneralUtils.extractTextBetweenString(text, "", "") - if r[:success] - think = r[:text] - end - str = string(split(text, "")[2]) - end - - if includethink == true && occursin("", text) - result = "ModelThought: $think $str" - return result - elseif includethink == false && occursin("", text) - result = str - return result - else - return text - end +function deFormatLLMtext_qwen3(text::String)::Union{Nothing, String} + return text end +# function deFormatLLMtext_qwen3(text::String; includethink::Bool=false)::Union{Nothing, String} +# think = nothing +# str = nothing + +# if occursin("", text) +# r = GeneralUtils.extractTextBetweenString(text, "", "") +# if r[:success] +# think = r[:text] +# end +# str = string(split(text, "")[2]) +# end + +# if includethink == true && occursin("", text) +# result = "ModelThought: $think $str" +# return result +# elseif includethink == false && occursin("", text) +# result = str +# return result +# else +# return text +# end +# end + """ Attemp to correct LLM response's incorrect JSON response. @@ -419,7 +423,20 @@ function jsoncorrection(config::T1, input::T2, correctJsonExample::T3; end - +function extractthink(text::String) + think = nothing + str = nothing + if occursin("", text) + r = GeneralUtils.extractTextBetweenString(text, "", "") + if r[:success] + think = r[:text] + end + str = string(split(text, "")[2]) + else + str = text + end + return think, str +end diff --git a/src/util.jl b/src/util.jl index 2d4498b..def7c27 100644 --- a/src/util.jl +++ b/src/util.jl @@ -1305,13 +1305,19 @@ julia> recentElementsIndex(length(a), 0) 5:5 ``` """ -function recentElementsIndex(vectorlength::Integer, n::Integer) +function recentElementsIndex(vectorlength::Integer, n::Integer; includelatest::Bool=false) if n == 0 error("n must be greater than 0") end - start = max(1, vectorlength - n + 1) - return start:vectorlength + if includelatest + start = max(1, vectorlength - n + 1) + return start:vectorlength + else + startind = max(1, vectorlength - n) + endind = vectorlength -1 + return startind:endind + end end