update
This commit is contained in:
+2
-1
@@ -400,6 +400,7 @@ function conversation(a::sommelier; userinput::Union{Dict{String, Any}, JSON.Obj
|
||||
"content" => [Dict("type" => "text", "text" => thoughtdict["action_input"]),]
|
||||
)
|
||||
addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg)
|
||||
@info "YiemAgent conversation() 2-5 think count $loopcount " @__LINE__
|
||||
return thoughtdict["action_input"]
|
||||
# elseif thoughtdict["action_name"] ∈ ["CHAT_BOX"]
|
||||
# @info "YiemAgent conversation() 2-4 think count $loopcount " @__LINE__
|
||||
@@ -419,7 +420,7 @@ function conversation(a::sommelier; userinput::Union{Dict{String, Any}, JSON.Obj
|
||||
# )
|
||||
# addNewMessage(a, "assistant", assistant_response; maximumMsg=maximumMsg)
|
||||
|
||||
return thoughtdict["action_input"] #XXX change output from string to dict
|
||||
# return thoughtdict["action_input"] #XXX change output from string to dict
|
||||
else
|
||||
action_name = thoughtdict["action_name"]
|
||||
action_input = thoughtdict["action_input"]
|
||||
|
||||
+122
-117
@@ -396,123 +396,123 @@ function generatesql(a::T, searchterm::String,
|
||||
Do not wrap the SQL as it will be executed against the database directly and SQL must be ended with ';'.
|
||||
"""
|
||||
|
||||
table_schema =
|
||||
"""
|
||||
create table customer (
|
||||
customer_id uuid primary key default gen_random_uuid (),
|
||||
customer_firstname varchar(128),
|
||||
customer_lastname varchar(128),
|
||||
customer_displayname varchar(128) not null,
|
||||
customer_username varchar(128),
|
||||
customer_password varchar(128),
|
||||
customer_gender varchar(128),
|
||||
country varchar(128),
|
||||
telephone varchar(128),
|
||||
email varchar(128) not null,
|
||||
customer_birthdate varchar(128),
|
||||
note text,
|
||||
# table_schema =
|
||||
# """
|
||||
# create table customer (
|
||||
# customer_id uuid primary key default gen_random_uuid (),
|
||||
# customer_firstname varchar(128),
|
||||
# customer_lastname varchar(128),
|
||||
# customer_displayname varchar(128) not null,
|
||||
# customer_username varchar(128),
|
||||
# customer_password varchar(128),
|
||||
# customer_gender varchar(128),
|
||||
# country varchar(128),
|
||||
# telephone varchar(128),
|
||||
# email varchar(128) not null,
|
||||
# customer_birthdate varchar(128),
|
||||
# note text,
|
||||
|
||||
other_attributes jsonb,
|
||||
created_time timestamptz default current_timestamp,
|
||||
updated_time timestamptz default current_timestamp,
|
||||
description text
|
||||
);
|
||||
# other_attributes jsonb,
|
||||
# created_time timestamptz default current_timestamp,
|
||||
# updated_time timestamptz default current_timestamp,
|
||||
# description text
|
||||
# );
|
||||
|
||||
create table retailer (
|
||||
retailer_id uuid primary key default gen_random_uuid (),
|
||||
retailer_name varchar(128) not null,
|
||||
retailer_username varchar(128) not null,
|
||||
retailer_password varchar(128) not null,
|
||||
retailer_address text not null,
|
||||
country varchar(128) not null,
|
||||
contact_person varchar(128) not null,
|
||||
telephone varchar(128) not null,
|
||||
email varchar(128) not null,
|
||||
note text,
|
||||
# create table retailer (
|
||||
# retailer_id uuid primary key default gen_random_uuid (),
|
||||
# retailer_name varchar(128) not null,
|
||||
# retailer_username varchar(128) not null,
|
||||
# retailer_password varchar(128) not null,
|
||||
# retailer_address text not null,
|
||||
# country varchar(128) not null,
|
||||
# contact_person varchar(128) not null,
|
||||
# telephone varchar(128) not null,
|
||||
# email varchar(128) not null,
|
||||
# note text,
|
||||
|
||||
other_attributes jsonb,
|
||||
created_time timestamptz default current_timestamp,
|
||||
updated_time timestamptz default current_timestamp,
|
||||
description text
|
||||
);
|
||||
# other_attributes jsonb,
|
||||
# created_time timestamptz default current_timestamp,
|
||||
# updated_time timestamptz default current_timestamp,
|
||||
# description text
|
||||
# );
|
||||
|
||||
create table food (
|
||||
food_id uuid primary key default gen_random_uuid (),
|
||||
food_name varchar(128) not null,
|
||||
country varchar(128),
|
||||
spiciness integer,
|
||||
sweetness integer,
|
||||
sourness integer,
|
||||
savoriness integer,
|
||||
bitterness integer,
|
||||
serving_temperature integer,
|
||||
image_url jsonb,
|
||||
note text,
|
||||
other_attributes jsonb,
|
||||
# create table food (
|
||||
# food_id uuid primary key default gen_random_uuid (),
|
||||
# food_name varchar(128) not null,
|
||||
# country varchar(128),
|
||||
# spiciness integer,
|
||||
# sweetness integer,
|
||||
# sourness integer,
|
||||
# savoriness integer,
|
||||
# bitterness integer,
|
||||
# serving_temperature integer,
|
||||
# image_url jsonb,
|
||||
# note text,
|
||||
# other_attributes jsonb,
|
||||
|
||||
created_time timestamptz default current_timestamp,
|
||||
updated_time timestamptz default current_timestamp,
|
||||
description text
|
||||
);
|
||||
# created_time timestamptz default current_timestamp,
|
||||
# updated_time timestamptz default current_timestamp,
|
||||
# description text
|
||||
# );
|
||||
|
||||
create table wine (
|
||||
wine_id uuid primary key default gen_random_uuid (),
|
||||
seo_name varchar(128) not null,
|
||||
wine_name varchar(128) not null,
|
||||
winery varchar(128) not null,
|
||||
vintage integer not null,
|
||||
region varchar(128) not null,
|
||||
country varchar(128) not null,
|
||||
wine_type varchar(128) not null,
|
||||
grape varchar(128) not null,
|
||||
serving_temperature varchar(128) not null,
|
||||
intensity integer,
|
||||
sweetness integer,
|
||||
tannin integer,
|
||||
acidity integer,
|
||||
fizziness integer,
|
||||
tasting_notes text,
|
||||
image_url jsonb,
|
||||
manufacturer_sku text,
|
||||
note text,
|
||||
other_attributes jsonb,
|
||||
# create table wine (
|
||||
# wine_id uuid primary key default gen_random_uuid (),
|
||||
# seo_name varchar(128) not null,
|
||||
# wine_name varchar(128) not null,
|
||||
# winery varchar(128) not null,
|
||||
# vintage integer not null,
|
||||
# region varchar(128) not null,
|
||||
# country varchar(128) not null,
|
||||
# wine_type varchar(128) not null,
|
||||
# grape varchar(128) not null,
|
||||
# serving_temperature varchar(128) not null,
|
||||
# intensity integer,
|
||||
# sweetness integer,
|
||||
# tannin integer,
|
||||
# acidity integer,
|
||||
# fizziness integer,
|
||||
# tasting_notes text,
|
||||
# image_url jsonb,
|
||||
# manufacturer_sku text,
|
||||
# note text,
|
||||
# other_attributes jsonb,
|
||||
|
||||
created_time timestamptz default current_timestamp,
|
||||
updated_time timestamptz default current_timestamp,
|
||||
description text
|
||||
);
|
||||
# created_time timestamptz default current_timestamp,
|
||||
# updated_time timestamptz default current_timestamp,
|
||||
# description text
|
||||
# );
|
||||
|
||||
create table wine_food (
|
||||
wine_id uuid references wine(wine_id),
|
||||
food_id uuid references food(food_id),
|
||||
constraint wine_food_id primary key (wine_id, food_id),
|
||||
# create table wine_food (
|
||||
# wine_id uuid references wine(wine_id),
|
||||
# food_id uuid references food(food_id),
|
||||
# constraint wine_food_id primary key (wine_id, food_id),
|
||||
|
||||
created_time timestamptz default current_timestamp,
|
||||
updated_time timestamptz default current_timestamp
|
||||
);
|
||||
# created_time timestamptz default current_timestamp,
|
||||
# updated_time timestamptz default current_timestamp
|
||||
# );
|
||||
|
||||
CREATE TABLE retailer_wine (
|
||||
retailer_id uuid references retailer(retailer_id),
|
||||
wine_id uuid references wine(wine_id),
|
||||
constraint retailer_wine_id primary key (retailer_id, wine_id),
|
||||
price NUMERIC(10, 2),
|
||||
currency varchar(3) not null,
|
||||
# CREATE TABLE retailer_wine (
|
||||
# retailer_id uuid references retailer(retailer_id),
|
||||
# wine_id uuid references wine(wine_id),
|
||||
# constraint retailer_wine_id primary key (retailer_id, wine_id),
|
||||
# price NUMERIC(10, 2),
|
||||
# currency varchar(3) not null,
|
||||
|
||||
created_time timestamptz default current_timestamp,
|
||||
updated_time timestamptz default current_timestamp
|
||||
);
|
||||
# created_time timestamptz default current_timestamp,
|
||||
# updated_time timestamptz default current_timestamp
|
||||
# );
|
||||
|
||||
CREATE TABLE retailer_food (
|
||||
retailer_id uuid references retailer(retailer_id),
|
||||
food_id uuid references food(food_id),
|
||||
constraint retailer_food_id primary key (retailer_id, food_id),
|
||||
price NUMERIC(10, 2),
|
||||
currency varchar(3) not null,
|
||||
# CREATE TABLE retailer_food (
|
||||
# retailer_id uuid references retailer(retailer_id),
|
||||
# food_id uuid references food(food_id),
|
||||
# constraint retailer_food_id primary key (retailer_id, food_id),
|
||||
# price NUMERIC(10, 2),
|
||||
# currency varchar(3) not null,
|
||||
|
||||
created_time timestamptz default current_timestamp,
|
||||
updated_time timestamptz default current_timestamp
|
||||
);
|
||||
"""
|
||||
# created_time timestamptz default current_timestamp,
|
||||
# updated_time timestamptz default current_timestamp
|
||||
# );
|
||||
# """
|
||||
|
||||
requiredKeys = ["plan", "action_name", "action_input"]
|
||||
errornote = ""
|
||||
@@ -525,6 +525,16 @@ function generatesql(a::T, searchterm::String,
|
||||
return similarSQL_
|
||||
end
|
||||
|
||||
#CHANGE use find_related_tables_for_user_question and inject only related table schema instead
|
||||
# of hard code table schema. CPU embedding is too slow. use embedding service on GPU.
|
||||
related_tables = a.context.find_related_tables_for_user_question(searchterm)
|
||||
table_schema = ""
|
||||
for table in related_tables
|
||||
table_schema_df = GeneralUtils.get_db_table_schema(a.context.pg_conn_str, table)
|
||||
table_schema_str = sprint(show, table_schema_df) * "\n"
|
||||
table_schema = table_schema * table_schema_str
|
||||
end
|
||||
|
||||
context =
|
||||
"""
|
||||
<internal_context_for_assistant>
|
||||
@@ -823,11 +833,11 @@ function extractWineAttributes_1(a::T1, input::T2; maxattempt=10
|
||||
responsedict[k] = _v
|
||||
end
|
||||
|
||||
println("\n--- extractWineAttributes_1-1()")
|
||||
@show responsedict
|
||||
@info "---\n" @__LINE__
|
||||
# println("\n--- extractWineAttributes_1-1()")
|
||||
# @show responsedict
|
||||
# @info "---\n" @__LINE__
|
||||
|
||||
#WORKING check each attributes against database with BM25
|
||||
# check each attributes against each column in a database table with BM25
|
||||
for (k, v) in responsedict
|
||||
words_catalog = GeneralUtils.harvest_entity_catalog(a.context.pg_conn_str, "wine", k)
|
||||
resolved_word = GeneralUtils.resolve_entity(v, words_catalog;threshold=0.9)
|
||||
@@ -843,15 +853,10 @@ function extractWineAttributes_1(a::T1, input::T2; maxattempt=10
|
||||
end
|
||||
|
||||
result = result[1:end-2] # remove the ending ", "
|
||||
println("\n--- extractWineAttributes_1-2()")
|
||||
@show responsedict
|
||||
@show result
|
||||
@info "---\n" @__LINE__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# println("\n--- extractWineAttributes_1-2()")
|
||||
# @show responsedict
|
||||
# @show result
|
||||
# @info "---\n" @__LINE__
|
||||
return result
|
||||
end
|
||||
error("extractWineAttributes_1() failed to get a response")
|
||||
|
||||
@@ -16,7 +16,9 @@ mutable struct agentcontext
|
||||
insertSQLVectorDB::Function
|
||||
similarSommelierDecision::Function
|
||||
insertSommelierDecision::Function
|
||||
find_related_tables_for_user_question::Function
|
||||
pg_conn_str::String
|
||||
agentconfig::AbstractDict
|
||||
end
|
||||
|
||||
abstract type agent end
|
||||
|
||||
Reference in New Issue
Block a user