This commit is contained in:
narawat lamaiin
2024-04-27 08:35:35 +07:00
parent aacae344c2
commit 4a41b0feb4
5 changed files with 121 additions and 123 deletions

View File

@@ -1,6 +1,7 @@
module util
export clearhistory, addNewMessage, formatLLMtext, formatLLMtext_llama3instruct
export clearhistory, addNewMessage, formatLLMtext, formatLLMtext_llama3instruct,
syntaxcheck_json, iterativeprompting
using UUIDs, Dates, DataStructures, HTTP, MQTTClient, JSON3
using GeneralUtils
@@ -228,7 +229,105 @@ end
""" Check JSON format correctness, provide
Arguments\n
-----
jsonstring::T
Return\n
-----
Example\n
-----
```jldoctest
julia>
```
TODO\n
-----
[] update docstring
[WORKING] implement the function
Signature\n
-----
"""
function syntaxcheck_json(jsonstring::T)::NamedTuple where {T<:AbstractString}
error("--> syntaxcheck_json")
# success, result, errormsg, st = GeneralUtils.showstracktrace(JSON3.read, jsonstring)
# if !success # gives feedback
# else
# end
# return (success, result, critique)
end
"""
Arguments\n
-----
Return\n
-----
Example\n
-----
```jldoctest
julia>
```
TODO\n
-----
[] update docstring
[WORKING] implement the function
Signature\n
-----
"""
function iterativeprompting(a::T, prompt::String, verification::Function) where {T<:agent}
msgMeta = GeneralUtils.generate_msgMeta(
a.config[:externalService][:text2textinstruct],
senderName= "iterativeprompting",
senderId= a.id,
receiverName= "text2textinstruct",
)
outgoingMsg = Dict(
:msgMeta=> msgMeta,
:payload=> Dict(
:text=> prompt,
)
)
# iteration loop
while true
# send prompt to LLM
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
error("--> iterativeprompting")
# check for correctness and get feedback
# if correct
# break
# else
# # get LLM critique
# # add critique to prompt
# end
end
return response
end