update
This commit is contained in:
114
src/util.jl
114
src/util.jl
@@ -118,59 +118,6 @@ function addNewMessage(a::T1, name::String, text::T2;
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
""" Convert a single chat dictionary into LLM model instruct format.
|
|
||||||
|
|
||||||
# Llama 3 instruct format example
|
|
||||||
<|begin_of_text|>
|
|
||||||
<|start_header_id|>system<|end_header_id|>
|
|
||||||
You are a helpful assistant.
|
|
||||||
<|eot_id|>
|
|
||||||
<|start_header_id|>user<|end_header_id|>
|
|
||||||
Get me an icecream.
|
|
||||||
<|eot_id|>
|
|
||||||
<|start_header_id|>assistant<|end_header_id|>
|
|
||||||
Go buy it yourself at 7-11.
|
|
||||||
<|eot_id|>
|
|
||||||
|
|
||||||
# Arguments
|
|
||||||
- `name::T`
|
|
||||||
message owner name e.f. "system", "user" or "assistant"
|
|
||||||
- `text::T`
|
|
||||||
|
|
||||||
# Return
|
|
||||||
- `formattedtext::String`
|
|
||||||
text formatted to model format
|
|
||||||
|
|
||||||
# Example
|
|
||||||
```jldoctest
|
|
||||||
julia> using Revise
|
|
||||||
julia> using YiemAgent
|
|
||||||
julia> d = Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",)
|
|
||||||
julia> formattedtext = YiemAgent.formatLLMtext_llama3instruct(d[:name], d[:text])
|
|
||||||
"<|begin_of_text|>\n <|start_header_id|>system<|end_header_id|>\n You are a helpful, respectful and honest assistant.\n <|eot_id|>\n"
|
|
||||||
```
|
|
||||||
|
|
||||||
# Signature
|
|
||||||
"""
|
|
||||||
function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString}
|
|
||||||
formattedtext =
|
|
||||||
if name == "system"
|
|
||||||
"""<|begin_of_text|>
|
|
||||||
<|start_header_id|>$name<|end_header_id|>
|
|
||||||
$text
|
|
||||||
<|eot_id|>
|
|
||||||
"""
|
|
||||||
else
|
|
||||||
"""
|
|
||||||
<|start_header_id|>$name<|end_header_id|>
|
|
||||||
$text
|
|
||||||
<|eot_id|>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
return formattedtext
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
""" Convert a single chat dictionary into LLM model instruct format.
|
""" Convert a single chat dictionary into LLM model instruct format.
|
||||||
|
|
||||||
@@ -217,6 +164,61 @@ function formatLLMtext_phi3instruct(name::T, text::T) where {T<:AbstractString}
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
""" Convert a single chat dictionary into LLM model instruct format.
|
||||||
|
|
||||||
|
# Llama 3 instruct format example
|
||||||
|
<|begin_of_text|>
|
||||||
|
<|start_header_id|>system<|end_header_id|>
|
||||||
|
You are a helpful assistant.
|
||||||
|
<|eot_id|>
|
||||||
|
<|start_header_id|>user<|end_header_id|>
|
||||||
|
Get me an icecream.
|
||||||
|
<|eot_id|>
|
||||||
|
<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
Go buy it yourself at 7-11.
|
||||||
|
<|eot_id|>
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
- `name::T`
|
||||||
|
message owner name e.f. "system", "user" or "assistant"
|
||||||
|
- `text::T`
|
||||||
|
|
||||||
|
# Return
|
||||||
|
- `formattedtext::String`
|
||||||
|
text formatted to model format
|
||||||
|
|
||||||
|
# Example
|
||||||
|
```jldoctest
|
||||||
|
julia> using Revise
|
||||||
|
julia> using YiemAgent
|
||||||
|
julia> d = Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",)
|
||||||
|
julia> formattedtext = YiemAgent.formatLLMtext_llama3instruct(d[:name], d[:text])
|
||||||
|
"<|begin_of_text|>\n <|start_header_id|>system<|end_header_id|>\n You are a helpful, respectful and honest assistant.\n <|eot_id|>\n"
|
||||||
|
```
|
||||||
|
|
||||||
|
Signature
|
||||||
|
"""
|
||||||
|
function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString}
|
||||||
|
formattedtext =
|
||||||
|
if name == "system"
|
||||||
|
"""
|
||||||
|
<|begin_of_text|>
|
||||||
|
<|start_header_id|>$name<|end_header_id|>
|
||||||
|
$text
|
||||||
|
<|eot_id|>\n
|
||||||
|
"""
|
||||||
|
else
|
||||||
|
"""
|
||||||
|
<|start_header_id|>$name<|end_header_id|>
|
||||||
|
$text
|
||||||
|
<|eot_id|>\n
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
return formattedtext
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
""" Convert a chat messages in vector of dictionary into LLM model instruct format.
|
""" Convert a chat messages in vector of dictionary into LLM model instruct format.
|
||||||
|
|
||||||
@@ -251,6 +253,8 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}},
|
|||||||
formatLLMtext_llama3instruct
|
formatLLMtext_llama3instruct
|
||||||
elseif formatname == "mistral"
|
elseif formatname == "mistral"
|
||||||
# not define yet
|
# not define yet
|
||||||
|
elseif formatname == "phi3instruct"
|
||||||
|
formatLLMtext_phi3instruct
|
||||||
else
|
else
|
||||||
error("$formatname template not define yet")
|
error("$formatname template not define yet")
|
||||||
end
|
end
|
||||||
@@ -260,6 +264,10 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}},
|
|||||||
str *= f(t[:name], t[:text])
|
str *= f(t[:name], t[:text])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if formatname == "phi3instruct"
|
||||||
|
str *= "<|assistant|>\n"
|
||||||
|
end
|
||||||
|
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user