update
This commit is contained in:
+83
-21
@@ -122,10 +122,70 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
|
|||||||
errornote = "N/A"
|
errornote = "N/A"
|
||||||
response = nothing # placeholder for show when error msg show up
|
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(
|
msg = Dict(
|
||||||
"model" => "gemma-4-E4B-it-UD-Q4_K_XL",
|
"model"=> "gemma-4-E4B-it-UD-Q4_K_XL",
|
||||||
"messages" => a.chathistory,
|
"messages"=> a.chathistory,
|
||||||
"temperature" => 0.7
|
"temperature"=> 0.7,
|
||||||
|
"response_format"=> json_schema,
|
||||||
)
|
)
|
||||||
|
|
||||||
for attempt in 1:maxattempt
|
for attempt in 1:maxattempt
|
||||||
@@ -138,25 +198,27 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
|
|||||||
response = replace(response, '$' => "USD")
|
response = replace(response, '$' => "USD")
|
||||||
end
|
end
|
||||||
|
|
||||||
responsedict = nothing
|
# responsedict = nothing
|
||||||
try
|
# try
|
||||||
responsedict = Serde.parse_yaml(response)
|
# responsedict = Serde.parse_yaml(response)
|
||||||
catch e
|
# catch e
|
||||||
println("\nERROR YiemAgent decisionMaker() Error: $e --(not qualify response)-> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
# println("\nERROR YiemAgent decisionMaker() Error: $e --(not qualify response)-> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||||
continue
|
# continue
|
||||||
end
|
# end
|
||||||
|
|
||||||
# check whether all answer's key points are in responsedict
|
# # check whether all answer's key points are in responsedict
|
||||||
println("\n---")
|
# println("\n---")
|
||||||
println(responsedict)
|
# println(responsedict)
|
||||||
println("---\n")
|
# println("---\n")
|
||||||
ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys)
|
# ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys)
|
||||||
|
|
||||||
if !ispass
|
# if !ispass
|
||||||
errornote = errormsg
|
# errornote = errormsg
|
||||||
println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)-> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
# println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)-> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
|
||||||
continue
|
# continue
|
||||||
end
|
# end
|
||||||
|
|
||||||
|
responsedict = JSON.parse(response)
|
||||||
|
|
||||||
if responsedict["action_input"] == "CHAT_BOX" &&
|
if responsedict["action_input"] == "CHAT_BOX" &&
|
||||||
occursin("similar", responsedict["action_input"])
|
occursin("similar", responsedict["action_input"])
|
||||||
@@ -564,7 +626,7 @@ function think(a::T)::NamedTuple{(:thoughtdict, :result_raw), Tuple{OrderedDict,
|
|||||||
end
|
end
|
||||||
|
|
||||||
@info "YiemAgent think() end " @__LINE__
|
@info "YiemAgent think() end " @__LINE__
|
||||||
@show thoughtdict
|
# @show thoughtdict
|
||||||
println("---\n")
|
println("---\n")
|
||||||
return (thoughtdict=thoughtdict, result_raw=result_raw)
|
return (thoughtdict=thoughtdict, result_raw=result_raw)
|
||||||
end
|
end
|
||||||
|
|||||||
+21
-1
@@ -637,7 +637,8 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
|||||||
# your responsibility includes
|
# your responsibility includes
|
||||||
Fulfill the objective.
|
Fulfill the objective.
|
||||||
|
|
||||||
# you should only respond in YAML format as described below
|
# you should only respond in JSON format as described below
|
||||||
|
{
|
||||||
table_name_1:
|
table_name_1:
|
||||||
column_name_1:
|
column_name_1:
|
||||||
operator: "="
|
operator: "="
|
||||||
@@ -654,6 +655,7 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
|||||||
operator: "="
|
operator: "="
|
||||||
value: "..."
|
value: "..."
|
||||||
...
|
...
|
||||||
|
}
|
||||||
|
|
||||||
# here are some example
|
# here are some example
|
||||||
<user>
|
<user>
|
||||||
@@ -700,6 +702,24 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
|||||||
"""
|
"""
|
||||||
input = context * searchterm
|
input = context * searchterm
|
||||||
|
|
||||||
|
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(
|
msg = Dict(
|
||||||
"model" => "gemma-4-E4B-it-UD-Q4_K_XL",
|
"model" => "gemma-4-E4B-it-UD-Q4_K_XL",
|
||||||
"messages" => [
|
"messages" => [
|
||||||
|
|||||||
+1
-6
@@ -200,17 +200,12 @@ function sommelier(
|
|||||||
- Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store.
|
- Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store.
|
||||||
- Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store.
|
- Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store.
|
||||||
|
|
||||||
# you should then respond to the user with interleaving plan, action_name, action_input
|
# you should then respond to the user with interleaving plan, action_name, action_input in JSON format
|
||||||
1) "plan", Based on the current situation, state a complete action plan to complete the task and rationale. Be specific.
|
1) "plan", Based on the current situation, state a complete action plan to complete the task and rationale. Be specific.
|
||||||
2) "action_name", (Typically corresponds to the execution of the first step in your plan) Can be one of the available_actions name
|
2) "action_name", (Typically corresponds to the execution of the first step in your plan) Can be one of the available_actions name
|
||||||
3) "action_input", The input to the action you are about to perform according to your plan.
|
3) "action_input", The input to the action you are about to perform according to your plan.
|
||||||
After the action is executed you gets "action_result". It is the output from the action you selected.
|
After the action is executed you gets "action_result". It is the output from the action you selected.
|
||||||
|
|
||||||
# you should only respond in YAML format as described below
|
|
||||||
plan: "..."
|
|
||||||
action_name: "..."
|
|
||||||
action_input: "..."
|
|
||||||
|
|
||||||
# available actions
|
# available actions
|
||||||
"CHAT_BOX", which you can use to talk with the user. The input is dialogue you want to chat with the user according to your plan.
|
"CHAT_BOX", which you can use to talk with the user. The input is dialogue you want to chat with the user according to your plan.
|
||||||
"SEARCH_WINE_DATABASE", allows you to search information about wines you want in your inventory's database. The input is strictly supported search term including: retailer_name, wine price, winery, name, vintage, region, country, type of wine, grape varietal, tasting notes, occasion, food pairing, intensity, tannin, sweetness, and acidity.
|
"SEARCH_WINE_DATABASE", allows you to search information about wines you want in your inventory's database. The input is strictly supported search term including: retailer_name, wine price, winery, name, vintage, region, country, type of wine, grape varietal, tasting notes, occasion, food pairing, intensity, tannin, sweetness, and acidity.
|
||||||
|
|||||||
Reference in New Issue
Block a user