use JSON instead

This commit is contained in:
2026-06-21 08:51:39 +07:00
parent b5a00bc694
commit 99b2fda461
11 changed files with 254 additions and 226 deletions

View File

@@ -1,5 +1,5 @@
using Revise
using JSON, JSON3, Dates, UUIDs, PrettyPrinting, LibPQ, Base64, DataFrames, DataStructures
using JSON, JSON, Dates, UUIDs, PrettyPrinting, LibPQ, Base64, DataFrames, DataStructures
using YiemAgent, GeneralUtils
using Base.Threads
@@ -8,8 +8,8 @@ using Base.Threads
# load config
config = JSON3.read("/appfolder/app/dev/YiemAgent/test/config.json")
# config = copy(JSON3.read("../mountvolume/config.json"))
config = JSON.parsefile("/appfolder/app/dev/YiemAgent/test/config.json")
# config = copy(JSON.parsefile("../mountvolume/config.json"))
function executeSQL(sql::T) where {T<:AbstractString}
@@ -180,7 +180,7 @@ function similarSommelierDecision(recentevents::T1; maxdistance::Integer=3
println("\n~~~ found similar decision. row id $rowid, distance $distance ", @__FILE__, " ", @__LINE__)
output_b64 = df[1, :function_output_base64] # pick the closest match
_output_str = String(base64decode(output_b64))
output = copy(JSON3.read(_output_str))
output = copy(JSON.parsefile(_output_str))
return output
else
println("\n~~~ similar decision not found, max distance $maxdistance ", @__FILE__, " ", @__LINE__)
@@ -200,7 +200,7 @@ function insertSommelierDecision(recentevents::T1, decision::T2; maxdistance::In
if row == 0 || distance > maxdistance # no close enough SQL stored in the database
recentevents_embedding = getEmbedding(recentevents)[1]
recentevents = replace(recentevents, "'" => "")
decision_json = JSON3.write(decision)
decision_json = JSON.json(decision)
decision_base64 = base64encode(decision_json)
decision = replace(decision_json, "'" => "")
@@ -456,14 +456,14 @@ function main()
lastAssistantAction = agent.memory[:events][end][:thought][:actionname]
if lastAssistantAction == "ENDCONVERSATION" # store thoughtDict
# save a.memory[:shortmem][:decisionlog] to disk using JSON3
# save a.memory[:shortmem][:decisionlog] to disk using JSON
println("\nsaving agent.memory[:shortmem][:decisionlog] to disk")
date = "$(Dates.now())"
date = replace(date, ':'=>'.')
filename = "agent_decision_log_$(date)_$(agent.id).json"
filepath = "/appfolder/mountvolume/appdata/log/$filename"
open(filepath, "w") do io
JSON3.pretty(io, agent.memory[:shortmem][:decisionlog])
JSON.pretty(io, agent.memory[:shortmem][:decisionlog])
end
# check how many file in /appfolder/mountvolume/appdata/log/ folder now