diff --git a/src/interface.jl b/src/interface.jl
index 0d90a73..9810a32 100755
--- a/src/interface.jl
+++ b/src/interface.jl
@@ -362,14 +362,15 @@ function selfAwareness(a::agentReflex)
$work
+
$(a.memory[:shortterm]["Plan 1:"])
Use the following format strictly:
- What do I know: based on observed results, repeat all the information you are gathering.
+ What do I know: based on observed results, repeat all the information you got.
Info match: explicitly state what information matches what variable in my plan.
- What am I missing: based on observed results, describe in detail what you are still missing compared to your plan.
+ What am I missing: based on observed results, describe in detail what you are still missing based on the plan.
P.S. do not mention any toolnames
@@ -448,7 +449,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
# aware = "Self-awareness: Based on action's input and observed results, check your progress against the plan. Then, repeat all the details of what you have been gathered. Finally, describe in detail what you are missing."
thought =
"Self-awareness: $selfaware
- Thought: based on self-awareness, think about what to do next and focus on what you missed first. (P.S. 1) let's think a single step. 2) pay attention to correct numeral calculation and commonsense.)
+ Thought: based on self-awareness, think about what to do next but focus on what you missed first. (P.S. 1) let's think a single step. 2) pay attention to correct numeral calculation and commonsense.)
"
end
@@ -458,6 +459,18 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
$(a.roles[a.role])
"""
+ winestocksearchresult = nothing
+ if haskey(a.memory, :winestocksearchresult) && a.memory[:winestockResult] !== nothing
+ winestocksearchresult =
+ """
+
+ $(a.memory[:winestocksearchresult])
+
+ """
+ else
+ winestocksearchresult = "\n"
+ end
+
prompt =
"""
<|system|>
@@ -470,6 +483,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
$(a.memory[:shortterm]["Plan 1:"])
+
Use the following format:
$thought
@@ -605,11 +619,13 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
"Check $latestTask:",]
headers = detectCharacters(response, headerToDetect)
chunkedtext = chunktext(response, headers)
-
+ println("")
+ @show chunkedtext
+
-
toolinput = chunkedtext["Actinput $latestTask:"]
+
# because tools has JSON input but sometime LLM output is not JSON, we need to check.
if occursin("{", toolinput)
act = GeneralUtils.getStringBetweenCharacters(response, '{', '}', endCharLocation="end")
@@ -870,9 +886,9 @@ function actor(a::agentReflex)
f = a.tools[toolname][:func]
toolresult = f(a, actorResult)
@show toolresult
- if toolname == "temp"
- a.winestockResult = toolresult
- a.memory[:shortterm]["Obs $latestTask:"] = "winestock search done, refers to "
+ if toolname == ""
+ a.memory[:shortterm]["Obs $latestTask:"] = "I found wines in "
+ a.memory[:winestockResult] = toolresult
a.memory[:log]["Obs $latestTask:"] = "winestock search done"
else
a.memory[:shortterm]["Obs $latestTask:"] = toolresult
@@ -981,7 +997,7 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString}
Evaluate your response using the evaluation guideline then give yourself a score out of 9 for your response.
- {"Evaluate": "Evaluate your response using the evaluation guideline.", "Score": 6}
+ {"Evaluate": "My response is detailed with good comparison between options.", "Score": 6}
<|assistant|>
@@ -993,12 +1009,13 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString}
println("")
score = nothing
while true
- response = sendReceivePrompt(a, prompt, timeout=180a)
+ response = sendReceivePrompt(a, prompt, timeout=180)
try
response = "{" * split(response, "}")[1] * "}"
@show response
@show jsonresponse = JSON3.read(response)
score = jsonresponse["Score"]
+ break
catch
println("retry grading")
end
diff --git a/src/llmfunction.jl b/src/llmfunction.jl
index 95e6777..946e975 100644
--- a/src/llmfunction.jl
+++ b/src/llmfunction.jl
@@ -115,66 +115,67 @@ end
```
"""
function winestock(a::agentReflex, actorResult::NamedTuple)
- @show query = actorResult[:toolinput]
- # prompt =
- # """
- # <|system|>
- #
- # Your are a helpful assistant.
- #
- #
- # 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
- #
- #
- # 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|>
+
+ Your are a helpful assistant.
+
+
+ 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
+
+
+ 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
- #
- #
- # 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;
- #
- #
- # 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;
- #
- #
- # <|query|>
- # $query
- #
- # <|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
+
+
+ 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;
+
+
+ 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;
+
+
+ <|query|>
+ $query
+
+ <|assistant|>
+ """
# prompt =
# """
@@ -234,66 +235,71 @@ function winestock(a::agentReflex, actorResult::NamedTuple)
# <|assistant|>
# """
- prompt =
- """
- [INST]
-
- Your are a helpful assistant.
-
-
- 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
-
+ # prompt =
+ # """
+ # [INST]
+ #
+ # Your are a helpful assistant.
+ #
+ #
+ # 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
+ #
-
- 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
-
+ #
+ # 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
+ #
- 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;
-
- [INST]
-
- $(actorResult[:selfaware])
-
-
- 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;
+ #
+ # [INST]
+ #
+ # $(actorResult[:selfaware])
+ #
+ # 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
diff --git a/src/type.jl b/src/type.jl
index cc7bd8e..fee779a 100644
--- a/src/type.jl
+++ b/src/type.jl
@@ -139,7 +139,6 @@ function agentReflex(
Required info you need for wine recommendation:
- occasion: ask the user
- type of food that will be served with wine: ask the user
- - ambient temperature at the serving location: ask the user
- type of wine (we have Rose, White, Red, Rose and Sparkling): ask the user
- wine sweetness level (dry to very sweet)
- wine intensity level (light to full bodied)