diff --git a/src/interface.jl b/src/interface.jl
index 0d3e7b5..9b41889 100755
--- a/src/interface.jl
+++ b/src/interface.jl
@@ -134,7 +134,7 @@ function chat_mistral_openorca(a::agentReflex)
<|assistant|>
"""
- response = sendReceivePrompt(a, prompt)
+ response = sendReceivePrompt(a, prompt, timeout=180)
response = split(response, "<|im_end|>")[1]
return response
@@ -268,6 +268,24 @@ function updatePlan(a::agentReflex)
end
function actor_mistral_openorca(a::agentReflex, taskrecap="")
+ getonlykeys = ["Actinput", "Obs"]
+ worknoplan = similar(a.memory[:shortterm])
+ for (k, v) in a.memory[:shortterm]
+ count = 0
+ for i in getonlykeys
+ if occursin(i, k)
+ count += 1
+ end
+ end
+ if count != 0
+ worknoplan[k] = v
+ end
+ end
+
+ work = dictToString(worknoplan)
+
+
+
"""
general prompt format:
@@ -320,8 +338,9 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
aware = ""
if taskrecap != ""
start = "Self-awareness"
- aware = "Self-awareness: based on the recap and the plan, state your current understanding of the matter."
- # aware = "Self-awareness: based on the recap, check your progress against the plan and assess the current situation to identify tasks that you need to address."
+ # aware = "Self-awareness: based on the recap, assess your progress against the plan then identify areas where you need to address."
+ # aware = "Self-awareness: based on the recap and the plan, state your current understanding of the matter in details then identify areas where you need to address."
+ aware = "Self-awareness: based on earlier conversation with the user, check your progress against the plan then assess the current situation to identify tasks that you need to address."
end
winestockResult = ""
@@ -344,20 +363,17 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
$(a.memory[:shortterm]["Plan 1:"])
-
- $taskrecap
-
- $winestockResult
Use the following format:
$aware
- Thought: based on the plan and self-awareness, What to do? (P.S. ask the user one by one question, pay attention to correct numeral calculation and commonsense)
- Act: an action to take based on your thought, must be one of [{toolnames}]
+ Thought: based on the plan and self-awareness, What to do? (P.S.1 pay attention to correct numeral calculation and commonsense.)
+ Act: an action to take, must be one of [{toolnames}]
Actinput: your input to the action based on your thought (pay attention to the tool's input)
Obs: observed result of the action
<|assistant|>
+ $work
$start:
"""
prompt = replace(prompt, "{toolnames}" => toolnames)
@@ -373,7 +389,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
while true # while Thought or Act is empty, run actor again
# tempcounter += 0.1
@show tempcounter
- response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=tempcounter)
+ response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=tempcounter, timeout=180)
response = splittext(response, ["Obs", "<|im_end|>"])
latestTask = shortMemLatestTask(a.memory[:shortterm]) +1
@@ -443,6 +459,201 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
return toolname, toolinput, chunkedtext
end
+# function actor_mistral_openorca(a::agentReflex, taskrecap="")
+# getonlykeys = ["Actinput", "Obs"]
+# worknoplan = similar(a.memory[:shortterm])
+# for (k, v) in a.memory[:shortterm]
+# count = 0
+# for i in getonlykeys
+# if occursin(i, k)
+# count += 1
+# end
+# end
+# if count != 0
+# worknoplan[k] = v
+# end
+# end
+
+# work = dictToString(worknoplan)
+
+
+
+# """
+# general prompt format:
+
+# "
+# <|im_start|>system
+# {role}
+# {tools}
+# {thinkingFormat}
+# <|im_end|>
+# {context}
+# <|im_start|>user
+# {usermsg}
+# <|im_end|>
+# <|im_start|>assistant
+
+# "
+
+# Note:
+# {context} =
+# "
+# {earlierConversation}
+# {env state}
+# {shortterm memory}
+# {longterm memory}
+# "
+# """
+# #BUG BIG output from winestock cause recap() to fail.
+# #BUG2 LLM repeat winestock search without recommending wine
+# toolnames = ""
+# toollines = ""
+# for (toolname, v) in a.tools
+# toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
+# toollines *= toolline
+# toolnames *= "$toolname, "
+# end
+
+# # shorttermMemory = dictToString(a.memory[:shortterm], skiplist=["user:"])
+
+# # conversation = conversationSummary(a)
+# # println("")
+# # @show conversationSum = conversation
+
+# # context =
+# # """
+# # Your talk with the user:
+# # $conversation
+# # """
+
+# start = "Thought"
+# aware = ""
+# if taskrecap != ""
+# start = "Self-awareness"
+# # aware = "Self-awareness: based on the recap, assess your progress against the plan then identify areas where you need to address."
+# # aware = "Self-awareness: based on the recap and the plan, state your current understanding of the matter in details then identify areas where you need to address."
+# aware = "Self-awareness: based on the recap, check your progress against the plan and assess the current situation to identify tasks that you need to address."
+# end
+
+# winestockResult = ""
+# if a.winestockResult != ""
+# winestockResult =
+# """
+#
+# $(a.winestockResult)
+#
+# """
+# end
+
+# prompt =
+# """
+# <|system|>
+# $(a.roles[a.role])
+#
+# $toollines
+#
+#
+# $(a.memory[:shortterm]["Plan 1:"])
+#
+#
+# $work
+#
+# $winestockResult
+#
+# Use the following format:
+# $aware
+# Thought: based on the plan and self-awareness, What to do? (P.S.1 pay attention to correct numeral calculation and commonsense.)
+# Act: an action to take based on your thought, must be one of [{toolnames}]
+# Actinput: your input to the action based on your thought (pay attention to the tool's input)
+# Obs: observed result of the action
+#
+#
+# <|assistant|>
+# $start:
+# """
+# prompt = replace(prompt, "{toolnames}" => toolnames)
+
+# println("")
+# @show actor_prompt = prompt
+
+# response = nothing
+# chunkedtext = nothing
+# latestTask = nothing
+
+# tempcounter = 0.2
+# while true # while Thought or Act is empty, run actor again
+# # tempcounter += 0.1
+# @show tempcounter
+# response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=tempcounter)
+# response = splittext(response, ["Obs", "<|im_end|>"])
+
+# latestTask = shortMemLatestTask(a.memory[:shortterm]) +1
+
+# if start == "Thought"
+# response = "Thought $latestTask: " * response
+# else
+# response = "Self-awareness $latestTask: " * response
+# end
+
+# headerToDetect = ["Question:", "Plan:", "Self-awareness:", "Thought:",
+# "Act:", "Actinput:", "Obs:", "...",
+# "Answer:", "Conclusion:", "Summary:"]
+
+# # replace headers with headers with correct attempt and task number
+# response = replaceHeaders(response, headerToDetect, latestTask)
+# response = split(response, "<|")[1]
+# response = split(response, "")[1]
+
+# headers = detectCharacters(response, headerToDetect)
+
+# println("")
+
+
+# headerToDetect = ["Plan $(a.attempt):",
+# "Self-awareness $latestTask:",
+# "Thought $latestTask:",
+# "Act $latestTask:",
+# "Actinput $latestTask:",
+# "Obs $latestTask:",
+# "Check $latestTask:",]
+# headers = detectCharacters(response, headerToDetect)
+# chunkedtext = chunktext(response, headers)
+
+# # assuming length more than 10 character means LLM has valid thinking
+# @show iskey_Thought = haskey(chunkedtext, "Thought $latestTask:")
+# @show iskey_Act = haskey(chunkedtext, "Act $latestTask:")
+# @show iskey_Actinput = haskey(chunkedtext, "Actinput $latestTask:")
+# if iskey_Thought && iskey_Act && iskey_Actinput
+# if chunkedtext["Thought $latestTask:"] != " " && chunkedtext["Act $latestTask:"] != " " &&
+# length(chunkedtext["Actinput $latestTask:"]) > 5
+# break
+# end
+# end
+# end
+
+# toolname = toolNameBeingCalled(chunkedtext["Act $latestTask:"], a.tools)
+# toolinput = chunkedtext["Actinput $latestTask:"]
+
+# # change trailing number to continue a.memory[:shortterm]
+# headerToDetect = ["Question:", "Plan:", "Self-awareness:", "Thought:",
+# "Act:", "Actinput:", "Obs:", "...",
+# "Answer:", "Conclusion:", "Summary:"]
+# response = replaceHeaders(response, headerToDetect, latestTask)
+# println("")
+# @show actor_response = response
+# headerToDetect = ["Plan $(a.attempt):",
+# "Thought $latestTask:",
+# "Act $latestTask:",
+# "Actinput $latestTask:",
+# "Obs $latestTask:",
+# "Check $latestTask:",]
+# headers = detectCharacters(response, headerToDetect)
+# chunkedtext = chunktext(response, headers)
+# chunkedtext = delete!(chunkedtext, "Self-awareness $latestTask")
+
+# return toolname, toolinput, chunkedtext
+# end
+
"""
@@ -1162,6 +1373,14 @@ function recap(a)
work = dictToString(worknoplan)
+ toolnames = ""
+ toollines = ""
+ for (toolname, v) in a.tools
+ toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
+ toollines *= toolline
+ toolnames *= "$toolname, "
+ end
+
# prompt =
# """
# <|system|>
@@ -1186,6 +1405,8 @@ function recap(a)
# Recap:
# """
+
+
prompt =
"""
<|system|>
@@ -1197,12 +1418,14 @@ function recap(a)
Actinput: the input to the action
Obs: the result of the action
-
+
+ $toollines
+
$work
- Extract info: extract each info in details from your earlier work into a bullet summary.
+ Extract info: extract each info in details from your earlier work according to the Actinput context.
Let's think step by step.
diff --git a/src/llmfunction.jl b/src/llmfunction.jl
index 2fa6349..5fb16a1 100644
--- a/src/llmfunction.jl
+++ b/src/llmfunction.jl
@@ -89,6 +89,7 @@ function winestock(a::agentReflex, phrase::T) where {T<:AbstractString}
# """
result =
"""
+ I found the following wines
{
1: {
wine name: Louis Latou - Corton-Charlamagne,