This commit is contained in:
2024-01-15 08:00:04 +00:00
parent 745e9e85fc
commit 67b226e4e8
6 changed files with 151 additions and 96 deletions

View File

@@ -2,7 +2,7 @@ module llmfunction
export wikisearch, winestock
using HTTP, JSON3, URIs
using HTTP, JSON3, URIs, Random
using GeneralUtils
using ..type, ..utils
#------------------------------------------------------------------------------------------------100
@@ -124,7 +124,7 @@ function winestock(a::agentReflex, query::Dict)
Your are a helpful assistant.
</About yourself>
<You have the following wine classification info>
<You have the following conversion table>
Intensity level:
intensity = 1, light bodied
intensity = 2, light-medium bodied
@@ -149,9 +149,10 @@ function winestock(a::agentReflex, query::Dict)
acidity = 3, medium acidity
acidity = 4, medium-high acidity
acidity = 5, high acidity
</You have the following wine classification info>
</You have the following conversion table>
<Your job>
Write a SQL command using data from a JSON-format query.
Consult the conversion table then write a specific SQL command from a JSON-format query.
List of keywords not allowed in SQL: ["BETWEEN", "--"]
</Your job>
<Example 1>
query: {\"wine type\": \"white\", \"wine characteristics\": \"full-bodied | off-dry | low acidity | medium tannin\", \"price\": {\"max\": \"50\"}}
@@ -169,34 +170,74 @@ function winestock(a::agentReflex, query::Dict)
"""
println("")
@show db_prompt = prompt
response = sendReceivePrompt(a, prompt, max_tokens=256, temperature=0.4,
_sql = nothing
while true
_sql = sendReceivePrompt(a, prompt, max_tokens=256, temperature=0.2,
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
println("")
@show db_response = response
# check for valid SQL command
check_1 = occursin("BETWEEN", _sql)
check_2 = occursin("--", _sql)
# remove any blank character in front of a string
newresponse = nothing
for i in eachindex(response)
if response[i] != ' '
newresponse = response[i:end]
if check_1 == false && check_2 == false
break
end
end
response = newresponse
println("")
@show db_sql = _sql
error("winestock done")
body =
"""
INSERT INTO $tablename
$(JSON3.write(insertdata));
"""
# remove any blank character in front of a string
newsql = nothing
for i in eachindex(_sql)
if _sql[i] != ' '
newsql = _sql[i:end]
break
end
end
sql = split(newsql, ";")[1] * ";"
body = sql
uri = URI(scheme="http", host="192.168.88.12", port="9010", path="/sql", userinfo="root:root")
r = HTTP.request("POST", uri, ["Accept" => "application/json", "NS"=>"yiem", "DB"=>"Blossom_wines"], body)
println("")
@show r.body
@show r
a.memory[:r] = r
result = copy(JSON3.read(r.body))
wines = shuffle(result[1][:result]) # shuffle in case there are more than 1 result
println("")
@show wines
# choose only 2 wines
if length(wines) > 2
println("$(length(wines)) wines found")
wines = wines[1:2]
end
result = nothing
if length(wines) == 0
result =
"""
Wine not found.
"""
else
# write wines dictionary in to string
wines_str = ""
for (i, wine) in enumerate(wines)
winename = wine[:wine_name]
wines_str *= "$i: $(JSON3.write(wines[i])),"
end
result =
"""
I found the following wines in our stock:
{
$wines_str
}
"""
end
@show result
return result
end
@@ -225,15 +266,6 @@ end