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