update
This commit is contained in:
+41
-24
@@ -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("<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
|
||||
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("<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.
|
||||
|
||||
@@ -419,7 +423,20 @@ function jsoncorrection(config::T1, input::T2, correctJsonExample::T3;
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user