update
This commit is contained in:
@@ -114,16 +114,132 @@ end
|
||||
julia> score = grading(agent, guideline, shorttermMemory)
|
||||
```
|
||||
"""
|
||||
function winestock(a::agentReflex, query::Dict)
|
||||
query = JSON3.write(query)
|
||||
@show query
|
||||
function winestock(a::agentReflex, actorResult::NamedTuple)
|
||||
@show query = actorResult[:toolinput]
|
||||
# prompt =
|
||||
# """
|
||||
# <|system|>
|
||||
# <About yourself>
|
||||
# Your are a helpful assistant.
|
||||
# </About yourself>
|
||||
# <You have the following conversion table>
|
||||
# Intensity level:
|
||||
# intensity = 1, light bodied
|
||||
# intensity = 2, light-medium bodied
|
||||
# intensity = 3, medium bodied
|
||||
# intensity = 4, medium-full bodied
|
||||
# intensity = 5, full bodied
|
||||
# Sweetness level:
|
||||
# sweetness = 1, dry
|
||||
# sweetness = 2, off-dry
|
||||
# sweetness = 3, semi-sweet
|
||||
# sweetness = 4, sweet
|
||||
# sweetness = 5, very sweet
|
||||
# Tannin level:
|
||||
# tannin = 1, low tannin
|
||||
# tannin = 2, low-medium tannin
|
||||
# tannin = 3, medium tannin
|
||||
# tannin = 4, medium-high tannin
|
||||
# tannin = 5, high tannin
|
||||
# Acidity level:
|
||||
# acidity = 1, low acidity
|
||||
# acidity = 2, low-medium acidity
|
||||
# acidity = 3, medium acidity
|
||||
# acidity = 4, medium-high acidity
|
||||
# acidity = 5, high acidity
|
||||
# </You have the following conversion table>
|
||||
# <Your job>
|
||||
# Consult the conversion table then write a specific SQL command using only available info from a JSON-format query.
|
||||
# List of keywords not allowed in SQL: ["BETWEEN", "--", "WHEN", "IN"]
|
||||
|
||||
# Use the following format:
|
||||
# Think: How do I map the info in the query to conversion table
|
||||
# Info map: based on conversion table, map the info in query to appropriate variables
|
||||
# SQL: write a specific SQL command
|
||||
# </Your job>
|
||||
# <Example 1>
|
||||
# query: {\"wine type\": \"white\", \"wine characteristics\": \"full-bodied | off-dry | low acidity | low to medium tannin\", \"price\": {\"max\": \"50\"}}
|
||||
# Think: 1) low to medium tannin is not explicitly stated, but assuming it falls within the range of low-medium tannin.
|
||||
# Info map: {\"wine type\": \"white\", \"intensity\": 5, \"sweetness\": 2, \"tannin\": 2, \"acidity\": 1, \"price\": {\"max\": \"50 USD\"}}
|
||||
# SQL: SELECT * FROM White WHERE intensity = 5 AND sweetness = 2 AND acidity = 1 AND tannin = 2 AND price <= 50;
|
||||
# </Example 1>
|
||||
# <Example 2>
|
||||
# query: {\"wine characteristics\":\"low-bodied | a little sweet | low-medium tannin\",\"price\":\"22 USD\",\"occasion\":\"anniversary\",\"wine type\":\"Rose\",\"food\":\"American dishes\"}
|
||||
# Think: 1) medium sweet is not explicitly stated, but assuming it falls within the range of dry and off-dry.
|
||||
# Info map: {\"wine type\": \"Rose\", \"intensity\": 1, \"sweetness\": 3, \"tannin\": 2, \"acidity\": 3, \"price\": {\"max\": \"22 USD\"}}
|
||||
# SQL: SELECT * FROM Rose WHERE intensity = 1 AND tannin = 2 AND (sweetness = 1 OR sweetness = 2) AND price <= 22;
|
||||
# </Example 2>
|
||||
# </s>
|
||||
# <|query|>
|
||||
# $query
|
||||
# </s>
|
||||
# <|assistant|>
|
||||
# """
|
||||
|
||||
# prompt =
|
||||
# """
|
||||
# <|system|>
|
||||
# <About yourself>
|
||||
# Your are a helpful assistant.
|
||||
# </About yourself>
|
||||
# <You have the following conversion table>
|
||||
# Intensity level:
|
||||
# intensity = 1, light bodied
|
||||
# intensity = 2, light-medium bodied
|
||||
# intensity = 3, medium bodied
|
||||
# intensity = 4, medium-full bodied
|
||||
# intensity = 5, full bodied
|
||||
# Sweetness level:
|
||||
# sweetness = 1, dry
|
||||
# sweetness = 2, off-dry
|
||||
# sweetness = 3, semi-sweet
|
||||
# sweetness = 4, sweet
|
||||
# sweetness = 5, very sweet
|
||||
# Tannin level:
|
||||
# tannin = 1, low tannin
|
||||
# tannin = 2, low-medium tannin
|
||||
# tannin = 3, medium tannin
|
||||
# tannin = 4, medium-high tannin
|
||||
# tannin = 5, high tannin
|
||||
# Acidity level:
|
||||
# acidity = 1, low acidity
|
||||
# acidity = 2, low-medium acidity
|
||||
# acidity = 3, medium acidity
|
||||
# acidity = 4, medium-high acidity
|
||||
# acidity = 5, high acidity
|
||||
# </You have the following conversion table>
|
||||
# <Your job>
|
||||
# Consult the conversion table then write a specific SQL command using the info from the user.
|
||||
# List of keywords not allowed in SQL: ["BETWEEN", "--", "WHEN", "IN"]
|
||||
|
||||
# Use the following format:
|
||||
# Think: How do I map the info in the query to conversion table
|
||||
# Info map: based on conversion table, map the info in query to appropriate variables
|
||||
# SQL: write a specific SQL command
|
||||
# </Your job>
|
||||
# <Example 1>
|
||||
# Think: 1) low to medium tannin is not explicitly stated, but assuming it falls within the range of low-medium tannin.
|
||||
# Info map: {\"wine type\": \"white\", \"intensity\": 5, \"sweetness\": 2, \"tannin\": 2, \"acidity\": 1, \"price\": {\"max\": \"50 USD\"}}
|
||||
# SQL: SELECT * FROM White WHERE intensity = 5 AND sweetness = 2 AND acidity = 1 AND tannin = 2 AND price <= 50;
|
||||
# </Example 1>
|
||||
# <Example 2>
|
||||
# Think: 1) medium sweet is not explicitly stated, but assuming it falls within the range of dry and off-dry.
|
||||
# Info map: {\"wine type\": \"Rose\", \"intensity\": 1, \"sweetness\": 3, \"tannin\": 2, \"acidity\": 3, \"price\": {\"max\": \"22 USD\"}}
|
||||
# SQL: SELECT * FROM Rose WHERE intensity = 1 AND tannin = 2 AND (sweetness = 1 OR sweetness = 2) AND price <= 22;
|
||||
# </Example 2>
|
||||
# </s>
|
||||
# <|user's info|>
|
||||
# $(actorResult[:selfaware])
|
||||
# </s>
|
||||
# <|assistant|>
|
||||
# """
|
||||
|
||||
prompt =
|
||||
"""
|
||||
<|system|>
|
||||
<s>[INST]
|
||||
<About yourself>
|
||||
Your are a helpful assistant.
|
||||
</About yourself>
|
||||
|
||||
<You have the following conversion table>
|
||||
Intensity level:
|
||||
intensity = 1, light bodied
|
||||
@@ -150,24 +266,35 @@ function winestock(a::agentReflex, query::Dict)
|
||||
acidity = 4, medium-high acidity
|
||||
acidity = 5, high acidity
|
||||
</You have the following conversion table>
|
||||
<Your job>
|
||||
Consult the conversion table then write a specific SQL command using only available info from a JSON-format query.
|
||||
|
||||
<query info>
|
||||
The user is planning a wedding party and needs a bottle of wine for the occasion.\n - Thai dishes will be served at the wedding party.\n - The ambient temperature at the serving location is around 22 degrees Celsius.\n - The user prefers a red wine with medium-bodied, dry and low to medium tannin.\n - The user prefers a medium acidity level for the wine.\n - The user's budget for the bottle of wine is around 15 USD.\n\n Info match:\n - Occasion: wedding party\n - Type of food: Thai dishes\n - Ambient temperature: around 22 degrees Celsius\n - Preferred type of wine: red\n - Wine sweetness level: dry\n - Wine intensity level: medium-bodied\n - Wine tannin level: low to medium\n - Wine acidity level: medium\n - Wine price range: around 15 USD\n\n
|
||||
<query info>
|
||||
|
||||
Consult the conversion table then write a specific SQL command using the query info.
|
||||
List of keywords not allowed in SQL: ["BETWEEN", "--", "WHEN", "IN"]
|
||||
</Your job>
|
||||
<Example 1>
|
||||
query: {\"wine type\": \"white\", \"wine characteristics\": \"full-bodied | off-dry | low acidity | medium tannin\", \"price\": {\"max\": \"50\"}}
|
||||
assistant: SELECT * FROM White WHERE intensity = 5 AND sweetness = 2 AND acidity = 1 AND tannin = 3 AND price <= 50;
|
||||
</Example 1>
|
||||
<Example 2>
|
||||
query: {\"wine characteristics\":\"low-bodied | semi-sweet | low-medium tannin\",\"price\":\"22 USD\",\"occasion\":\"anniversary\",\"wine type\":\"Rose\",\"food\":\"American dishes\"}
|
||||
assistant: SELECT * FROM Rose WHERE intensity = 1 AND sweetness = 3 AND (tannin = 2 OR tannin = 3) AND price <= 22;
|
||||
</Example 2>
|
||||
|
||||
Use the following format:
|
||||
Extract: extract the info from your work
|
||||
Think: How do I map the info in the query to conversion table
|
||||
Info map: based on conversion table, map the info in query to appropriate variables
|
||||
SQL: write a specific SQL command
|
||||
[/INST]
|
||||
Think: 1) low to medium tannin is not explicitly stated, but assuming it falls within the range of low-medium tannin.
|
||||
Info map: {\"wine type\": \"white\", \"intensity\": 5, \"sweetness\": 2, \"tannin\": 2, \"acidity\": 1, \"price\": {\"max\": \"50 USD\"}}
|
||||
SQL: SELECT * FROM White WHERE intensity = 5 AND sweetness = 2 AND acidity = 1 AND tannin = 2 AND price <= 50;
|
||||
</s>
|
||||
<|query|>
|
||||
$query
|
||||
</s>
|
||||
<|assistant|>
|
||||
[INST]
|
||||
<query info>
|
||||
$(actorResult[:selfaware])
|
||||
<query info>
|
||||
|
||||
Consult the conversion table then write a specific SQL command using the query info.
|
||||
List of keywords not allowed in SQL: ["BETWEEN", "--", "WHEN", "IN"]
|
||||
[/INST]
|
||||
"""
|
||||
|
||||
|
||||
println("")
|
||||
@show db_prompt = prompt
|
||||
_sql = nothing
|
||||
@@ -175,6 +302,7 @@ function winestock(a::agentReflex, query::Dict)
|
||||
_sql = sendReceivePrompt(a, prompt, max_tokens=256, temperature=0.2,
|
||||
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
|
||||
_sql = split(_sql, ";")[1] * ";"
|
||||
@show _sql
|
||||
# check for valid SQL command
|
||||
check_1 = occursin("BETWEEN", _sql)
|
||||
check_2 = occursin("--", _sql)
|
||||
@@ -183,8 +311,10 @@ function winestock(a::agentReflex, query::Dict)
|
||||
if check_1 == false && check_2 == false && check_3 == false
|
||||
break
|
||||
end
|
||||
println("illegal SQL command")
|
||||
println("invalid SQL command")
|
||||
end
|
||||
|
||||
_sql = split(_sql, "SQL:")[end]
|
||||
println("")
|
||||
@show db_sql = replace(_sql, '\n'=>"")
|
||||
|
||||
@@ -246,6 +376,138 @@ function winestock(a::agentReflex, query::Dict)
|
||||
end
|
||||
|
||||
|
||||
# function winestock(a::agentReflex, query::Dict)
|
||||
# query = JSON3.write(query)
|
||||
# @show query
|
||||
# prompt =
|
||||
# """
|
||||
# <|system|>
|
||||
# <About yourself>
|
||||
# Your are a helpful assistant.
|
||||
# </About yourself>
|
||||
|
||||
# <You have the following conversion table>
|
||||
# Intensity level:
|
||||
# intensity = 1, light bodied
|
||||
# intensity = 2, light-medium bodied
|
||||
# intensity = 3, medium bodied
|
||||
# intensity = 4, medium-full bodied
|
||||
# intensity = 5, full bodied
|
||||
# Sweetness level:
|
||||
# sweetness = 1, dry
|
||||
# sweetness = 2, off-dry
|
||||
# sweetness = 3, semi-sweet
|
||||
# sweetness = 4, sweet
|
||||
# sweetness = 5, very sweet
|
||||
# Tannin level:
|
||||
# tannin = 1, low tannin
|
||||
# tannin = 2, low-medium tannin
|
||||
# tannin = 3, medium tannin
|
||||
# tannin = 4, medium-high tannin
|
||||
# tannin = 5, high tannin
|
||||
# Acidity level:
|
||||
# acidity = 1, low acidity
|
||||
# acidity = 2, low-medium acidity
|
||||
# acidity = 3, medium acidity
|
||||
# acidity = 4, medium-high acidity
|
||||
# acidity = 5, high acidity
|
||||
# </You have the following conversion table>
|
||||
# <Your job>
|
||||
# Consult the conversion table then write a specific SQL command using only available info from a JSON-format query.
|
||||
# List of keywords not allowed in SQL: ["BETWEEN", "--", "WHEN", "IN"]
|
||||
# </Your job>
|
||||
# <Example 1>
|
||||
# query: {\"wine type\": \"white\", \"wine characteristics\": \"full-bodied | off-dry | low acidity | medium tannin\", \"price\": {\"max\": \"50\"}}
|
||||
# assistant: SELECT * FROM White WHERE intensity = 5 AND sweetness = 2 AND acidity = 1 AND tannin = 3 AND price <= 50;
|
||||
# </Example 1>
|
||||
# <Example 2>
|
||||
# query: {\"wine characteristics\":\"low-bodied | semi-sweet | low-medium tannin\",\"price\":\"22 USD\",\"occasion\":\"anniversary\",\"wine type\":\"Rose\",\"food\":\"American dishes\"}
|
||||
# assistant: SELECT * FROM Rose WHERE intensity = 1 AND sweetness = 3 AND (tannin = 2 OR tannin = 3) AND price <= 22;
|
||||
# </Example 2>
|
||||
# </s>
|
||||
# <|query|>
|
||||
# $query
|
||||
# </s>
|
||||
# <|assistant|>
|
||||
# """
|
||||
# println("")
|
||||
# @show db_prompt = prompt
|
||||
# _sql = nothing
|
||||
# while true
|
||||
# _sql = sendReceivePrompt(a, prompt, max_tokens=256, temperature=0.2,
|
||||
# stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
|
||||
# _sql = split(_sql, ";")[1] * ";"
|
||||
# # check for valid SQL command
|
||||
# check_1 = occursin("BETWEEN", _sql)
|
||||
# check_2 = occursin("--", _sql)
|
||||
# check_3 = occursin("IN", _sql)
|
||||
|
||||
# if check_1 == false && check_2 == false && check_3 == false
|
||||
# break
|
||||
# end
|
||||
# println("illegal SQL command")
|
||||
# end
|
||||
# println("")
|
||||
# @show db_sql = replace(_sql, '\n'=>"")
|
||||
|
||||
# # 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
|
||||
|
||||
|
||||
# body = newsql
|
||||
# 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
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user