This commit is contained in:
narawat lamaiin
2024-04-28 08:55:47 +07:00
parent 9641d91594
commit 9b4587f848

View File

@@ -1,7 +1,7 @@
module util
export clearhistory, addNewMessage, formatLLMtext, formatLLMtext_llama3instruct,
syntaxcheck_json, iterativeprompting
export clearhistory, addNewMessage, formatLLMtext, syntaxcheck_json, iterativeprompting,
formatLLMtext_llama3instruct, formatLLMtext_phi3instruct
using UUIDs, Dates, DataStructures, HTTP, MQTTClient, JSON3
using GeneralUtils
@@ -172,6 +172,51 @@ function formatLLMtext_llama3instruct(name::T, text::T) where {T<:AbstractString
end
""" Convert a single chat dictionary into LLM model instruct format.
# Llama 3 instruct format example
<|system|>
You are a helpful AI assistant.<|end|>
<|user|>
I am going to Paris, what should I see?<|end|>
<|assistant|>
Paris, the capital of France, is known for its stunning architecture, art museums."<|end|>
<|user|>
What is so great about #1?<|end|>
<|assistant|>
# 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_phi3instruct(d[:name], d[:text])
```
Signature
"""
function formatLLMtext_phi3instruct(name::T, text::T) where {T<:AbstractString}
formattedtext =
"""
<|$name|>
$text<|end|>\n
"""
return formattedtext
end
""" Convert a chat messages in vector of dictionary into LLM model instruct format.