This commit is contained in:
narawat lamaiin
2024-07-16 15:32:26 +07:00
parent fdc50d1b90
commit 37a9a38796
4 changed files with 132 additions and 64 deletions

View File

@@ -1,6 +1,6 @@
module util
export clearhistory, addNewMessage, chatHistoryToString
export clearhistory, addNewMessage, vectorOfDictToText
using UUIDs, Dates, DataStructures, HTTP, MQTTClient, JSON3
using GeneralUtils
@@ -113,15 +113,43 @@ function addNewMessage(a::T1, name::String, text::T2;
end
function chatHistoryToString(a)
chatHistoryStr = ""
for i in a.chathistory
name = i[:name]
text = i[:text]
chatHistoryStr *= "$name> $text"
"""
# Arguments
- `v::Integer`
dummy variable
# Return
# Example
```jldoctest
julia>
```
# TODO
- [] update docstring
- [x] implement the function
# Signature
"""
function vectorOfDictToText(vecd::Vector; withkey=true)
text = ""
if withkey
for d in vecd
name = d[:name]
_text = d[:text]
text *= "$name> $_text \n"
end
else
for d in vecd
for (k, v) in d
text *= "$v \n"
end
end
end
return chatHistoryStr
return text
end
@@ -131,9 +159,6 @@ end
# """ Convert a single chat dictionary into LLM model instruct format.
# # Llama 3 instruct format example