update
This commit is contained in:
@@ -364,203 +364,10 @@ julia> result = winestock(agent, input)
|
|||||||
"""
|
"""
|
||||||
function winestock(a::T1, input::T2
|
function winestock(a::T1, input::T2
|
||||||
)::Union{Tuple{String, Number, Number, Bool}, Tuple{String, Nothing, Number, Bool}} where {T1<:agent, T2<:AbstractString}
|
)::Union{Tuple{String, Number, Number, Bool}, Tuple{String, Nothing, Number, Bool}} where {T1<:agent, T2<:AbstractString}
|
||||||
|
|
||||||
# SELECT *
|
|
||||||
# FROM food
|
|
||||||
# WHERE 'China' = ANY(food_name)
|
|
||||||
# OR 'India' = ANY(food_name);
|
|
||||||
|
|
||||||
wineattributes = extractWineAttributes(a, input)
|
wineattributes = extractWineAttributes(a, input)
|
||||||
|
result = SQLLLM.query(Dict(:text=> wineattributes), a.executeSQL, a.text2textInstructLLM)
|
||||||
systemmsg =
|
return result
|
||||||
"""
|
|
||||||
As a helpful sommelier, your mission is to write SQL queries that search the PostgreSQL database for wines based on user input.
|
|
||||||
|
|
||||||
The database has the following tables (schema):
|
|
||||||
1. Table wine (
|
|
||||||
wine_id uuid primary key,
|
|
||||||
wine_name varchar,
|
|
||||||
brand varchar,
|
|
||||||
manufacturer varchar,
|
|
||||||
region varchar,
|
|
||||||
country varchar,
|
|
||||||
wine_type varchar,
|
|
||||||
grape_variety varchar,
|
|
||||||
serving_temperature varchar,
|
|
||||||
intensity integer,
|
|
||||||
sweetness integer,
|
|
||||||
tannin integer,
|
|
||||||
acidity integer,
|
|
||||||
fizziness integer,
|
|
||||||
|
|
||||||
other_attributes jsonb,
|
|
||||||
|
|
||||||
created_at timestamptz,
|
|
||||||
updated_at timestamptz,
|
|
||||||
description text
|
|
||||||
)
|
|
||||||
|
|
||||||
2. Table food (
|
|
||||||
food_id uuid primary key,
|
|
||||||
food_name varchar,
|
|
||||||
country varchar,
|
|
||||||
spicy integer,
|
|
||||||
sweet integer,
|
|
||||||
sour integer,
|
|
||||||
umami integer,
|
|
||||||
bitter integer,
|
|
||||||
serving_temperature integer,
|
|
||||||
other_attributes jsonb,
|
|
||||||
|
|
||||||
created_at timestamptz,
|
|
||||||
updated_at timestamptz,
|
|
||||||
description text
|
|
||||||
)
|
|
||||||
|
|
||||||
3. 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_at timestamptz,
|
|
||||||
updated_at timestamptz
|
|
||||||
)
|
|
||||||
|
|
||||||
You should only respond in JSON format as describe below:
|
|
||||||
{
|
|
||||||
"SQL":
|
|
||||||
{
|
|
||||||
"sweetness": "sweetness level",
|
|
||||||
"acidity": "acidity level",
|
|
||||||
"tannin": "tannin level",
|
|
||||||
"intensity": "intensity level"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Here are some examples:
|
|
||||||
|
|
||||||
user: {"sweetness": 2,"acidity": 3,"tannin": 1,"intensity": 5, "food": "Thai"}
|
|
||||||
assistant:
|
|
||||||
{
|
|
||||||
"SQL":
|
|
||||||
}
|
|
||||||
|
|
||||||
Let's begin!
|
|
||||||
"""
|
|
||||||
|
|
||||||
systemmsg =
|
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
usermsg =
|
|
||||||
"""
|
|
||||||
$input
|
|
||||||
"""
|
|
||||||
|
|
||||||
chathistory =
|
|
||||||
[
|
|
||||||
Dict(:name=> "system", :text=> systemmsg),
|
|
||||||
Dict(:name=> "user", :text=> usermsg)
|
|
||||||
]
|
|
||||||
|
|
||||||
# put in model format
|
|
||||||
prompt = formatLLMtext(chathistory, "llama3instruct")
|
|
||||||
prompt *=
|
|
||||||
"""
|
|
||||||
<|start_header_id|>assistant<|end_header_id|>
|
|
||||||
{
|
|
||||||
"""
|
|
||||||
|
|
||||||
pprint(prompt)
|
|
||||||
externalService = config[:externalservice][:text2textinstruct]
|
|
||||||
|
|
||||||
# send formatted input to user using GeneralUtils.sendReceiveMqttMsg
|
|
||||||
msgMeta = GeneralUtils.generate_msgMeta(
|
|
||||||
externalService[:mqtttopic],
|
|
||||||
senderName= "virtualWineUserChatbox",
|
|
||||||
senderId= string(uuid4()),
|
|
||||||
receiverName= "text2textinstruct",
|
|
||||||
mqttBroker= config[:mqttServerInfo][:broker],
|
|
||||||
mqttBrokerPort= config[:mqttServerInfo][:port],
|
|
||||||
msgId = string(uuid4()) #CHANGE remove after testing finished
|
|
||||||
)
|
|
||||||
|
|
||||||
outgoingMsg = Dict(
|
|
||||||
:msgMeta=> msgMeta,
|
|
||||||
:payload=> Dict(
|
|
||||||
:text=> prompt,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
attempt = 0
|
|
||||||
for attempt in 1:5
|
|
||||||
try
|
|
||||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=120)
|
|
||||||
_responseJsonStr = response[:response][:text]
|
|
||||||
expectedJsonExample =
|
|
||||||
"""
|
|
||||||
Here is an expected JSON format:
|
|
||||||
{
|
|
||||||
"attributes":
|
|
||||||
{
|
|
||||||
"...": "...",
|
|
||||||
"...": "...",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
responseJsonStr = jsoncorrection(config, _responseJsonStr, expectedJsonExample)
|
|
||||||
_responseDict = copy(JSON3.read(responseJsonStr))
|
|
||||||
responseDict = _responseDict[:attributes]
|
|
||||||
|
|
||||||
return responseDict
|
|
||||||
catch e
|
|
||||||
io = IOBuffer()
|
|
||||||
showerror(io, e)
|
|
||||||
errorMsg = String(take!(io))
|
|
||||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
|
||||||
println("")
|
|
||||||
@warn "Error occurred: $errorMsg\n$st"
|
|
||||||
println("")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
error("wineattributes_wordToNumber() failed to get a response")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# winesStr =
|
|
||||||
# """
|
|
||||||
# 1: El Enemigo Cabernet Franc 2019
|
|
||||||
# 2: Tantara Chardonnay 2017
|
|
||||||
# """
|
|
||||||
# result =
|
|
||||||
# """
|
|
||||||
# I found the following wines in our stock:
|
|
||||||
# {
|
|
||||||
# $winesStr
|
|
||||||
# }
|
|
||||||
# """
|
|
||||||
# return result, nothing, 0, false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Revise # remove when this package is completed
|
using Revise # remove when this package is completed
|
||||||
using YiemAgent, GeneralUtils, JSON3, MQTTClient, Dates, UUIDs
|
using YiemAgent, GeneralUtils, JSON3, MQTTClient, Dates, UUIDs, LibPQ
|
||||||
using Base.Threads
|
using Base.Threads
|
||||||
|
|
||||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||||
|
|||||||
Reference in New Issue
Block a user