This commit is contained in:
2024-01-19 13:11:08 +00:00
parent b419a5629c
commit c31d2e009d
3 changed files with 149 additions and 127 deletions

View File

@@ -115,66 +115,67 @@ end
```
"""
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"]
query = JSON3.write(actorResult[:toolinput])
@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"]
# 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|>
# """
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\": 50}
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\": 22}
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 =
# """
@@ -234,66 +235,71 @@ function winestock(a::agentReflex, actorResult::NamedTuple)
# <|assistant|>
# """
prompt =
"""
<s>[INST]
<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>
# prompt =
# """
# <s>[INST]
# <About yourself>
# Your are a helpful assistant.
# </About yourself>
# <You have the following conversion table>
# Database table name by wine type:
# Red = table for wine type "red"
# White = table for wine type "white"
# Sparkling = table for wine type "sparkling"
# Rose = table for wine type "rose"
# Dessert = table for wine type "dessert"
# Fortified = table for wine type "fortified"
# 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>
<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>
# <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"]
# Consult the conversion table then write a specific SQL command using the query info to search a database table.
# List of keywords not allowed in SQL: ["BETWEEN", "--", "WHEN", "IN"]
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>
[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]
"""
# 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
# [/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>
# [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
@@ -351,7 +357,7 @@ function winestock(a::agentReflex, actorResult::NamedTuple)
if length(wines) == 0
result =
"""
Wine not found.
No wine match my search query.
"""
else
# write wines dictionary in to string