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

@@ -3,7 +3,7 @@ module interface
export addNewMessage, conversation, decisionMaker, reflector, generatechat,
generalconversation, detectWineryName, generateSituationReport
using JSON3, DataStructures, Dates, UUIDs, HTTP, Random, PrettyPrinting, Serialization,
using JSON, DataStructures, Dates, UUIDs, HTTP, Random, PrettyPrinting, Serialization,
DataFrames, CSV
using GeneralUtils
using ..type, ..util, ..llmfunction
@@ -100,7 +100,7 @@ julia> output_thoughtDict = Dict(
function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
) where {T<:agent}
println("\nExecuting YiemAgent decisionMaker()")
# lessonDict = copy(JSON3.read("lesson.json"))
# lessonDict = copy(JSON.parsefile("lesson.json"))
# lesson =
# if isempty(lessonDict)
@@ -118,7 +118,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
# did previously. Use them to improve your strategy to help the user.
# Here are some lessons in JSON format:
# $(JSON3.write(lessons))
# $(JSON.json(lessons))
# When providing the thought and action for the current trial, that into account these failed
# trajectories and make sure not to repeat the same mistakes and incorrect answers.
@@ -293,7 +293,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
response = strip(response)
responsedict = nothing
try
responsedict = copy(JSON3.read(response))
responsedict = copy(JSON.parsefile(response))
catch
println("\nERROR YiemAgent decisionMaker() failed to parse response: $response", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
@@ -399,15 +399,15 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
# decisionlist = [responsedict]
# println("Creating file $filepath")
# open(filepath, "w") do io
# JSON3.pretty(io, decisionlist)
# JSON.pretty(io, decisionlist)
# end
# else
# # read the file and append new data
# decisionlist = copy(JSON3.read(filepath))
# decisionlist = copy(JSON.parsefile(filepath))
# push!(decisionlist, responsedict)
# println("Appending new data to file $filepath")
# open(filepath, "w") do io
# JSON3.pretty(io, decisionlist)
# JSON.pretty(io, decisionlist)
# end
# end
# println("\nYiemAgent decisionMaker() saved to disk is done. agent $(a.id)")
@@ -536,7 +536,7 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext
responsedict = nothing
try
responsedict = copy(JSON3.read(response))
responsedict = copy(JSON.parsefile(response))
catch
println("\nERROR YiemAgent generatechat() failed to parse response: $response", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
@@ -568,15 +568,15 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext
# decisionlist = [responsedict]
# println("Creating file $filepath")
# open(filepath, "w") do io
# JSON3.pretty(io, decisionlist)
# JSON.pretty(io, decisionlist)
# end
# else
# # read the file and append new data
# decisionlist = copy(JSON3.read(filepath))
# decisionlist = copy(JSON.parsefile(filepath))
# push!(decisionlist, responsedict)
# println("Appending new data to file $filepath")
# open(filepath, "w") do io
# JSON3.pretty(io, decisionlist)
# JSON.pretty(io, decisionlist)
# end
# end
@@ -597,7 +597,7 @@ end
# Example
```jldoctest
julia> using JSON3, UUIDs, Dates, FileIO, MQTTClient, ChatAgent
julia> using JSON, UUIDs, Dates, FileIO, MQTTClient, ChatAgent
julia> const mqttBroker = "mqtt.yiem.cc"
julia> mqttclient, connection = MakeConnection(mqttBroker, 1883)
julia> tools=Dict( # update input format
@@ -966,7 +966,7 @@ function presentbox(a::sommelier, thoughtDict; maxtattempt::Integer=10, recentev
responsedict = nothing
try
responsedict = copy(JSON3.read(response))
responsedict = copy(JSON.parsefile(response))
catch
println("\nERROR YiemAgent presentbox() failed to parse response: $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
@@ -1141,7 +1141,7 @@ function generatechat(a::sommelier, thoughtDict; maxattempt::Integer=10)
responsedict = nothing
try
responsedict = copy(JSON3.read(response))
responsedict = copy(JSON.parsefile(response))
catch
println("\nERROR YiemAgent generatechat() failed to parse response: $response", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue

View File

@@ -4,7 +4,7 @@ export virtualWineUserChatbox, jsoncorrection, checkwine, # recommendbox,
virtualWineUserRecommendbox, userChatbox, userRecommendbox, extractWineAttributes_1,
extractWineAttributes_2, paraphrase
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, Dates, DataFrames
using HTTP, JSON, URIs, Random, PrettyPrinting, UUIDs, Dates, DataFrames
using GeneralUtils, SQLLLM
using ..type, ..util
@@ -237,7 +237,7 @@ function virtualWineUserChatbox(config::T1, input::T2, virtualCustomerChatHistor
}
"""
responseJsonStr = jsoncorrection(config, _responseJsonStr, expectedJsonExample)
responseDict = copy(JSON3.read(responseJsonStr))
responseDict = copy(JSON.parsefile(responseJsonStr))
text::AbstractString = responseDict[:text]
select::Union{Nothing, Number} = responseDict[:select] == "null" ? nothing : responseDict[:select]
@@ -471,7 +471,7 @@ function extractWineAttributes_1(a::T1, input::T2; maxattempt=10
responsedict = nothing
try
responsedict = copy(JSON3.read(response))
responsedict = copy(JSON.parsefile(response))
catch
println("\nERROR YiemAgent extractWineAttributes_1() failed to parse response: $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
@@ -750,7 +750,7 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
responsedict = nothing
try
responsedict = copy(JSON3.read(response))
responsedict = copy(JSON.parsefile(response))
catch
println("\nERROR YiemAgent extractWineAttributes_2() failed to parse response: $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
@@ -867,7 +867,7 @@ function paraphrase(text2textInstructLLM::Function, text::String)
Let's begin!
"""
#[PENDING] use JSON3 the same as extractWineAttributes_1 is better. change this function to use the same format use decisionMaker
#[PENDING] use JSON the same as extractWineAttributes_1 is better. change this function to use the same format use decisionMaker
header = ["Paraphrase:"]
dictkey = ["paraphrase"]
@@ -919,7 +919,7 @@ function paraphrase(text2textInstructLLM::Function, text::String)
dictKey=dictkey, symbolkey=true)
for i [:paraphrase]
if length(JSON3.write(responsedict[i])) == 0
if length(JSON.json(responsedict[i])) == 0
error("$i is empty ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
end
end
@@ -979,7 +979,7 @@ function jsoncorrection(config::T1, input::T2, correctJsonExample::T3;
for attempt in 1:maxattempt
try
d = copy(JSON3.read(incorrectjson))
d = copy(JSON.parsefile(incorrectjson))
correctjson = incorrectjson
return correctjson
catch e

View File

@@ -2,7 +2,7 @@ module type
export agent, sommelier, companion, virtualcustomer, appcontext
using Dates, UUIDs, DataStructures, JSON3, NATS
using Dates, UUIDs, DataStructures, JSON, NATS
using GeneralUtils
# ---------------------------------------------- 100 --------------------------------------------- #

View File

@@ -4,7 +4,7 @@ export clearhistory, addNewMessage, chatHistoryToText, eventdict, noises, create
availableWineToText, createEventsLog, createChatLog, checkAgentResponse_JSON,
checkAgentResponse_text
using UUIDs, Dates, DataStructures, HTTP, JSON3
using UUIDs, Dates, DataStructures, HTTP, JSON
using GeneralUtils
using ..type