diff --git a/Manifest.toml b/Manifest.toml index d4441f8..44f5eb7 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.12.6" manifest_format = "2.0" -project_hash = "d7f9863f8330aa2e4c1c2fe1efc04d3b0e6bb33b" +project_hash = "c825feef41198c770952e1181ec41e9f2aa0c3c0" [[deps.Accessors]] deps = ["CompositionsBase", "ConstructionBase", "Dates", "InverseFunctions", "MacroTools"] @@ -229,7 +229,7 @@ version = "1.11.0" deps = ["CSV", "DataFrames", "DataStructures", "Dates", "Distributions", "HTTP", "JSON", "NATS", "PrettyPrinting", "Random", "Revise", "SHA", "UUIDs"] path = "." uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe" -version = "0.4.7" +version = "0.4.10" [[deps.HTTP]] deps = ["Base64", "CodecZlib", "Dates", "EnumX", "PrecompileTools", "Random", "Reseau", "SHA", "URIs", "UUIDs", "Zlib_jll"] diff --git a/Project.toml b/Project.toml index 453e49a..dd9233d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "GeneralUtils" uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe" -version = "0.4.9" +version = "0.4.10" authors = ["tonaerospace "] [deps] diff --git a/src/llmUtil.jl b/src/llmUtil.jl index 11cd0c4..95dda24 100644 --- a/src/llmUtil.jl +++ b/src/llmUtil.jl @@ -546,13 +546,7 @@ julia> clean_json_response(text) """ function clean_json_response(text::String) removelist = ["{", "}", "```", "json", "\n"] - for i in removelist - while occursin(i, text) - text = replace(text, i => "") - end - end - text = '{' * text * '}' - return text + return '{' * removestring(text, removelist) * '}' end diff --git a/src/util.jl b/src/util.jl index 2f3da23..5159d3f 100644 --- a/src/util.jl +++ b/src/util.jl @@ -5,7 +5,7 @@ export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, rep dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString, dfToString, dataframe_to_json_list, dictToString, dictToString_noKey, issomething, dictToString_numbering, extract_triple_backtick_text, - countGivenWords, remove_french_accents, + countGivenWords, remove_french_accents, removestring, extractTextBetweenCharacter, extractTextBetweenString, convertCamelSnakeKebabCase, fitrange, recentElementsIndex, nonRecentElementsIndex @@ -1139,9 +1139,38 @@ function nonRecentElementsIndex(vectorlength::Integer, n::Integer) return 1:(vectorlength-n) end +""" Remove specified substrings from text. +Removes all occurrences of each string in `removelist` from the input text +by repeatedly replacing them with empty strings until none remain. +# Arguments +- `text::String` + The input string to modify. +- `removelist::Vector{String}` + A vector of substrings to remove from the text. +# Return +- `String`: The text with all specified substrings removed. + +# Examples +```jldoctest +julia> using GeneralUtils +julia> removestring("hello world", ["l", " "]) +"heoword" +julia> removestring("foo bar baz", ["bar", " "]) +"foobaz" +``` +""" +function removestring(text::String, removelist::Vector{String})::String + for i in removelist + while occursin(i, text) + text = replace(text, i => "") + end + end + + return string(text) +end