From 9b4587f848a5b5483c02df1c1dd9cca5752f62ec Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Sun, 28 Apr 2024 08:55:47 +0700 Subject: [PATCH] update --- src/util.jl | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/util.jl b/src/util.jl index fd885d2..134bda2 100644 --- a/src/util.jl +++ b/src/util.jl @@ -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.