This commit is contained in:
narawat lamaiin
2024-04-28 08:17:17 +07:00
parent 43f7be1dc7
commit 9641d91594

View File

@@ -120,42 +120,37 @@ end
""" Convert a single chat dictionary into LLM model instruct format. """ Convert a single chat dictionary into LLM model instruct format.
Llama 3 instruct format example\n # Llama 3 instruct format example
----- <|begin_of_text|>
<|begin_of_text|> <|start_header_id|>system<|end_header_id|>
<|start_header_id|>system<|end_header_id|> You are a helpful assistant.
You are a helpful assistant. <|eot_id|>
<|eot_id|> <|start_header_id|>user<|end_header_id|>
<|start_header_id|>user<|end_header_id|> Get me an icecream.
Get me an icecream. <|eot_id|>
<|eot_id|> <|start_header_id|>assistant<|end_header_id|>
<|start_header_id|>assistant<|end_header_id|> Go buy it yourself at 7-11.
Go buy it yourself at 7-11. <|eot_id|>
<|eot_id|>
Arguments\n # Arguments
----- - `name::T`
name::T message owner name e.f. "system", "user" or "assistant"
message owner name e.f. "system", "user" or "assistant" - `text::T`
text::T
Return\n # Return
----- - `formattedtext::String`
formattedtext::String text formatted to model format
text formatted to model format
Example\n # Example
----- ```jldoctest
```jldoctest julia> using Revise
julia> using Revise julia> using YiemAgent
julia> using YiemAgent julia> d = Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",)
julia> d = Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",) julia> formattedtext = YiemAgent.formatLLMtext_llama3instruct(d[:name], d[:text])
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"
"<|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\n # Signature
-----
""" """
function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString} function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString}
formattedtext = formattedtext =
@@ -180,34 +175,30 @@ 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.
Arguments\n # Arguments
----- - `messages::Vector{Dict{Symbol, T}}`
messages::Vector{Dict{Symbol, T}} message owner name e.f. "system", "user" or "assistant"
message owner name e.f. "system", "user" or "assistant" - `formatname::T`
formatname::T format name to be used
format name to be used
Return\n # Return
----- - `formattedtext::String`
formattedtext::String text formatted to model format
text formatted to model format
Example\n # Example
----- ```jldoctest
```jldoctest julia> using Revise
julia> using Revise julia> using YiemAgent
julia> using YiemAgent julia> chatmessage = [
julia> chatmessage = [ Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",),
Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",), Dict(:name=> "user",:text=> "list me all planets in our solar system.",),
Dict(:name=> "user",:text=> "list me all planets in our solar system.",), Dict(:name=> "assistant",:text=> "I'm sorry. I don't know. You tell me.",),
Dict(:name=> "assistant",:text=> "I'm sorry. I don't know. You tell me.",), ]
] julia> formattedtext = YiemAgent.formatLLMtext(chatmessage, "llama3instruct")
julia> formattedtext = YiemAgent.formatLLMtext(chatmessage, "llama3instruct") "<|begin_of_text|>\n <|start_header_id|>system<|end_header_id|>\n You are a helpful, respectful and honest assistant.\n <|eot_id|>\n <|start_header_id|>user<|end_header_id|>\n list me all planets in our solar system.\n <|eot_id|>\n <|start_header_id|>assistant<|end_header_id|>\n I'm sorry. I don't know. You tell me.\n <|eot_id|>\n"
"<|begin_of_text|>\n <|start_header_id|>system<|end_header_id|>\n You are a helpful, respectful and honest assistant.\n <|eot_id|>\n <|start_header_id|>user<|end_header_id|>\n list me all planets in our solar system.\n <|eot_id|>\n <|start_header_id|>assistant<|end_header_id|>\n I'm sorry. I don't know. You tell me.\n <|eot_id|>\n" ```
```
Signature\n # Signature
-----
""" """
function formatLLMtext(messages::Vector{Dict{Symbol, T}}, function formatLLMtext(messages::Vector{Dict{Symbol, T}},
formatname::String="llama3instruct") where {T<:Any} formatname::String="llama3instruct") where {T<:Any}