update
This commit is contained in:
+83
-21
@@ -122,10 +122,70 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
|
||||
errornote = "N/A"
|
||||
response = nothing # placeholder for show when error msg show up
|
||||
|
||||
"""
|
||||
{
|
||||
"model": "your-model.gguf",
|
||||
"messages": [ ... ],
|
||||
"response_format": {
|
||||
"type": "json_schema",
|
||||
"json_schema": {
|
||||
"name": "agent_action",
|
||||
"strict": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"think": {
|
||||
"type": "string",
|
||||
"description": "Your step-by-step reasoning process. Explain why you are choosing this action."
|
||||
},
|
||||
"action_name": {
|
||||
"type": "string",
|
||||
"enum": ["search_web", "get_weather", "calculate_math"],
|
||||
"description": "The exact name of the tool to execute."
|
||||
},
|
||||
"action_input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"query": { "type": ["string", "null"], "description": "For search_web" },
|
||||
"location": { "type": ["string", "null"], "description": "For get_weather" },
|
||||
"equation": { "type": ["string", "null"], "description": "For calculate_math" }
|
||||
},
|
||||
"required": ["query", "location", "equation"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["think", "action_name", "action_input"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
# strict output format
|
||||
json_schema = Dict(
|
||||
"type"=> "json_schema",
|
||||
"json_schema"=> Dict(
|
||||
"name"=> "user_profile",
|
||||
"strict"=> true,
|
||||
"schema"=> Dict(
|
||||
"type"=> "object",
|
||||
"properties"=> Dict(
|
||||
"plan"=> Dict("type"=> "string"),
|
||||
"action_name"=> Dict("type"=> "string"),
|
||||
"action_input"=> Dict("type"=> "string"),
|
||||
),
|
||||
"required"=> ["plan", "action_name", "action_input"],
|
||||
"additionalProperties"=> false
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
msg = Dict(
|
||||
"model" => "gemma-4-E4B-it-UD-Q4_K_XL",
|
||||
"messages" => a.chathistory,
|
||||
"temperature" => 0.7
|
||||
"model"=> "gemma-4-E4B-it-UD-Q4_K_XL",
|
||||
"messages"=> a.chathistory,
|
||||
"temperature"=> 0.7,
|
||||
"response_format"=> json_schema,
|
||||
)
|
||||
|
||||
for attempt in 1:maxattempt
|
||||
@@ -138,25 +198,27 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
|
||||
response = replace(response, '$' => "USD")
|
||||
end
|
||||
|
||||
responsedict = nothing
|
||||
try
|
||||
responsedict = Serde.parse_yaml(response)
|
||||
catch e
|
||||
println("\nERROR YiemAgent decisionMaker() Error: $e --(not qualify response)-> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||
continue
|
||||
end
|
||||
# responsedict = nothing
|
||||
# try
|
||||
# responsedict = Serde.parse_yaml(response)
|
||||
# catch e
|
||||
# println("\nERROR YiemAgent decisionMaker() Error: $e --(not qualify response)-> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||
# continue
|
||||
# end
|
||||
|
||||
# check whether all answer's key points are in responsedict
|
||||
println("\n---")
|
||||
println(responsedict)
|
||||
println("---\n")
|
||||
ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys)
|
||||
# # check whether all answer's key points are in responsedict
|
||||
# println("\n---")
|
||||
# println(responsedict)
|
||||
# println("---\n")
|
||||
# ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys)
|
||||
|
||||
if !ispass
|
||||
errornote = errormsg
|
||||
println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)-> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||
continue
|
||||
end
|
||||
# if !ispass
|
||||
# errornote = errormsg
|
||||
# println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)-> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||
# continue
|
||||
# end
|
||||
|
||||
responsedict = JSON.parse(response)
|
||||
|
||||
if responsedict["action_input"] == "CHAT_BOX" &&
|
||||
occursin("similar", responsedict["action_input"])
|
||||
@@ -564,7 +626,7 @@ function think(a::T)::NamedTuple{(:thoughtdict, :result_raw), Tuple{OrderedDict,
|
||||
end
|
||||
|
||||
@info "YiemAgent think() end " @__LINE__
|
||||
@show thoughtdict
|
||||
# @show thoughtdict
|
||||
println("---\n")
|
||||
return (thoughtdict=thoughtdict, result_raw=result_raw)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user