This commit is contained in:
2026-07-24 15:51:32 +07:00
parent 7ec3edfd77
commit caed2a82d6
3 changed files with 22 additions and 21 deletions
+16 -15
View File
@@ -302,10 +302,16 @@ function search_wine_database!(a::T, thoughtdict::AbstractDict; useSQLLLM::Bool=
else
# direct query with possible sql instead of SQLLLM.
sql = predefined_wine_search_sql(a, thoughtdict["action_input"])
hard_conditions, vector_search_words = wine_search_term_classification(a, thoughtdict["action_input"])
# do hard filter
# sql = generatesql(a, inventoryquery)
println("\nSQL: $sql ", @__FILE__, ":", @__LINE__, " $(Dates.now()) \n")
sql = predefined_wine_search_sql(hard_conditions)
@info "\nsql: $sql, \nvector_search_words: $vector_search_words"
textresult, sql_result_df, success, _ = SQLexecution(a.context.executeSQL, sql)
#WORKING do vector search
GeneralUtils.find_text_vector_similarity(vector_search_words, "wine")
items = nothing
if sql_result_df !== nothing
@@ -619,9 +625,9 @@ julia> thoughtdict =
```
julia> predefined_wine_search_sql(agent, thoughtdict["action_input"])
"""
function predefined_wine_search_sql(a::T, searchterm::String,
function wine_search_term_classification(a::T, searchterm::String,
; maxattempt=10
)::String where {T<:agent}
) where {T<:agent}
systemmsg =
"""
@@ -641,7 +647,7 @@ function predefined_wine_search_sql(a::T, searchterm::String,
The "extracted_info" key must contain an array of objects. Each object must contain:
1) "table_name": The name of the table.
2) "column_name": The specific column being filtered.
3) "operator": The comparison operator (e.g., "=", ">", "LIKE").
3) "operator": The comparison operator (e.g., "=", ">").
4) "value": The value to compare against.
If the user does not specify any filters, return an empty array for "extracted_info": {"extracted_info": []}.
@@ -668,7 +674,7 @@ function predefined_wine_search_sql(a::T, searchterm::String,
{
"table_name": "car_info",
"column_name": "drive_feeling",
"operator": "ILIKE",
"operator": "=",
"value": "fast and furious"
},
{
@@ -781,7 +787,7 @@ function predefined_wine_search_sql(a::T, searchterm::String,
println("\n ", responsedict)
@info "before BM25 " @__LINE__
#WORKING to ensure user input is correct
# to ensure user input is correct
for entry in responsedict["extracted_info"]
table_name = entry["table_name"]::String
column_name = entry["column_name"]::String
@@ -802,11 +808,12 @@ function predefined_wine_search_sql(a::T, searchterm::String,
# Build new list of hard condition entries
hard_conditions = JSON.Object{String, Any}[]
vector_search = JSON.Object{String, Any}[]
for entry in responsedict["extracted_info"]
if entry["operator"] hard_operators
push!(hard_conditions, entry)
else
vector_search_words = vector_search_words * entry["value"] * ", "
push!(vector_search, entry)
end
end
responsedict = hard_conditions
@@ -814,14 +821,8 @@ function predefined_wine_search_sql(a::T, searchterm::String,
println("")
@show responsedict
@info "predefined_wine_search_sql() " @__LINE__
#WORKING do vector search
println("")
@show vector_search_words
# error(9999)
sql = predefined_wine_search_sql(responsedict)
return sql
return (hard_conditions=hard_conditions, vector_search=vector_search)
end
error("SQLLLM DecisionMaker() failed to generate a thought \n", response)
end