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

@@ -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