update
This commit is contained in:
@@ -103,22 +103,22 @@ function formatLLMtext_phi4(name::T, text::T;
|
|||||||
formattedtext =
|
formattedtext =
|
||||||
if name == "system"
|
if name == "system"
|
||||||
"""
|
"""
|
||||||
<|im_start|>$name<|im_sep|>
|
<|system|>
|
||||||
$text
|
$text
|
||||||
<|im_end|>
|
<|end|>
|
||||||
"""
|
"""
|
||||||
else
|
else
|
||||||
"""
|
"""
|
||||||
<|im_start|>$name<|im_sep|>
|
<|assistant|>
|
||||||
$text
|
$text
|
||||||
<|im_end|>
|
<|end|>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
if assistantStarter
|
if assistantStarter
|
||||||
formattedtext *=
|
formattedtext *=
|
||||||
"""
|
"""
|
||||||
<|im_start|>assistant<|im_sep|>
|
<|assistant|>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
68
src/util.jl
68
src/util.jl
@@ -6,7 +6,7 @@ export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, rep
|
|||||||
dfToString, dataframe_to_json_list, dictToString, dictToString_noKey,
|
dfToString, dataframe_to_json_list, dictToString, dictToString_noKey,
|
||||||
dictToString_numbering, extract_triple_backtick_text,
|
dictToString_numbering, extract_triple_backtick_text,
|
||||||
countGivenWords, remove_french_accents, detect_keyword, extractTextBetweenCharacter,
|
countGivenWords, remove_french_accents, detect_keyword, extractTextBetweenCharacter,
|
||||||
convertCamelSnakeKebabCase
|
convertCamelSnakeKebabCase, fitrange, lastElementsIndex
|
||||||
|
|
||||||
using JSON3, DataStructures, Distributions, Random, Dates, UUIDs, MQTTClient, DataFrames
|
using JSON3, DataStructures, Distributions, Random, Dates, UUIDs, MQTTClient, DataFrames
|
||||||
|
|
||||||
@@ -1138,9 +1138,75 @@ return x === nothing ? false : true
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
""" Adjust a given range to fit within the bounds of a vector's length.
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
- `v::T1`
|
||||||
|
the input vector to check against
|
||||||
|
- `range::UnitRange`
|
||||||
|
the original range to be adjusted
|
||||||
|
|
||||||
|
# Return
|
||||||
|
- `adjusted_range::UnitRange`
|
||||||
|
a range that is constrained to the vector's length, preventing out-of-bounds indexing
|
||||||
|
|
||||||
|
# Example
|
||||||
|
|
||||||
|
julia> v = [1, 2, 3, 4, 5]
|
||||||
|
julia> fitrange(v, 3:10)
|
||||||
|
3:5
|
||||||
|
|
||||||
|
"""
|
||||||
|
function fitrange(v::T1, range::UnitRange) where {T1<:AbstractVector}
|
||||||
|
totalelements = length(v)
|
||||||
|
|
||||||
|
startind =
|
||||||
|
# check if user put start range greater than total event
|
||||||
|
if range.start > totalelements
|
||||||
|
totalelements
|
||||||
|
else
|
||||||
|
range.start
|
||||||
|
end
|
||||||
|
|
||||||
|
stopind =
|
||||||
|
if range.stop > totalelements
|
||||||
|
totalelements
|
||||||
|
else
|
||||||
|
range.stop
|
||||||
|
end
|
||||||
|
|
||||||
|
return startind:stopind
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
""" Find a unit range for a vector given a number of the most recent elements of interest.
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
- `v::AbstractVector`
|
||||||
|
the input vector to extract recent elements from
|
||||||
|
- `n::Integer`
|
||||||
|
the number of most recent elements to include in the range
|
||||||
|
|
||||||
|
# Return
|
||||||
|
- `UnitRange`
|
||||||
|
a range representing the last `n` elements of the vector
|
||||||
|
|
||||||
|
# Example
|
||||||
|
```jldoctest
|
||||||
|
julia> a = [1, 2, 3, 4, 5]
|
||||||
|
julia> lastElementsIndex(a, 3)
|
||||||
|
3:5
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
function lastElementsIndex(v::AbstractVector, n::Integer)
|
||||||
|
len = length(v)
|
||||||
|
if n == 0
|
||||||
|
return 1:len
|
||||||
|
end
|
||||||
|
|
||||||
|
start = max(1, len - n + 1)
|
||||||
|
return start:len
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,18 @@
|
|||||||
using Test
|
using Test
|
||||||
using GeneralUtils
|
using GeneralUtils
|
||||||
|
|
||||||
@testset "detect_keyword tests" begin
|
@testset "lastElementsIndex" begin
|
||||||
@test GeneralUtils.detect_keyword(["test"], "this is a test string") == Dict("test" => 1)
|
@test GeneralUtils.lastElementsIndex([1,2,3,4,5], 3) == 3:5
|
||||||
@test GeneralUtils.detect_keyword(["hello", "world"], "hello world") == Dict("hello" => 1, "world" => 1)
|
@test GeneralUtils.lastElementsIndex([1,2,3], 5) == 1:3
|
||||||
@test GeneralUtils.detect_keyword(["missing"], "no keyword here") == Dict("missing" => nothing)
|
@test GeneralUtils.lastElementsIndex([1], 1) == 1:1
|
||||||
@test GeneralUtils.detect_keyword(["a", "b"], "a a b b b") == Dict("a" => 2, "b" => 3)
|
@test GeneralUtils.lastElementsIndex(collect(1:10), 4) == 7:10
|
||||||
@test GeneralUtils.detect_keyword(String[], "empty keywords") == Dict{String, Any}()
|
@test GeneralUtils.lastElementsIndex(Float64[], 2) == 1:0
|
||||||
@test GeneralUtils.detect_keyword(["keyword"], "") == Dict("keyword" => nothing)
|
@test GeneralUtils.lastElementsIndex([1,2,3], 0) == length([1,2,3])+1:length([1,2,3])
|
||||||
@test GeneralUtils.detect_keyword(["case"], "CASE case Case cAsE") == Dict("case" => 4)
|
@test GeneralUtils.lastElementsIndex(["a","b","c"], 2) == 2:3
|
||||||
mixed_results = GeneralUtils.detect_keyword(["found", "notfound"], "found found found")
|
|
||||||
@test mixed_results["found"] == 3
|
|
||||||
@test mixed_results["notfound"] === nothing
|
|
||||||
|
|
||||||
special_chars = GeneralUtils.detect_keyword(["test!"], "test! test? test.")
|
|
||||||
@test special_chars["test!"] == 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user