This commit is contained in:
youremail@yourdomain.com
2023-12-24 06:35:34 +00:00
parent 01fdce2b12
commit cc50da91e8
3 changed files with 78 additions and 98 deletions

View File

@@ -4,7 +4,8 @@ module interface
export agentReact, agentReflex,
addNewMessage, clearMessage, removeLatestMsg, conversation, directconversation,
writeEvaluationGuideline, grading, analyze, selfReflext,
formulateUserresponse, extractinfo, updateEnvState, chat_mistral_openorca
formulateUserresponse, extractinfo, updateEnvState, chat_mistral_openorca,
recap
using JSON3, DataStructures, Dates, UUIDs, HTTP
using CommUtils, GeneralUtils
@@ -128,7 +129,7 @@ function chat_mistral_openorca(a::agentReflex)
$(a.roles[a.role])
Your earlier talk with the user:
$(a.earlierConversation)
<|/s|>
</s>
$conversation
<|assistant|>
"""
@@ -202,7 +203,7 @@ function planner_mistral_openorca(a::agentReflex)
Your job is to do the following:
Plan: first you should always think about your conversation with the user and your earlier work thoroughly then extract and devise a complete, task by task plan to achieve your objective (pay attention to correct numeral calculation and commonsense).
P.S.1 each task of the plan should be a single action.
<|/s|>
</s>
$conversation
<|assistant|>
Plan:
@@ -256,7 +257,7 @@ function updatePlan(a::agentReflex)
Plan: 1. Ask the user for their food type.
Obs: It will be Thai dishes.
Updated plan: 1. Ask the user for their food type (Thai dishes).
</s|>
</s>
Updated plan:
"""
@@ -304,7 +305,9 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
shorttermMemory = dictToString(a.memory[:shortterm], skiplist=["user:"])
# conversation = messagesToString_nomark(a.messages, addressAIas="I")
# conversation = conversationSummary(a)
# println("")
# @show conversationSum = conversation
# context =
# """
@@ -322,9 +325,9 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
<Your plan>
$(a.memory[:shortterm]["Plan 1:"])
</Your plan>
<Your earlier work's recap>
<Your earlier work's recap in JSON format>
$taskrecap
</Your earlier work's recap>
</Your earlier work's recap in JSON format>
<Your job>
Use the following format:
Thought: based on the plan and the recap of the plan, what to do? (pay attention to correct numeral calculation and commonsense).
@@ -332,16 +335,16 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
Actinput: your input to the action based on your thought (pay attention to the tool's input)
Obs: observed result of the action
P.S.1 ask user one by one question.
P.S.1 ask the user one by one question.
</Your job>
<|/s|>
</s>
<|assistant|>
Thought:
"""
prompt = replace(prompt, "{toolnames}" => toolnames)
println("")
@show prompt_actor = prompt
@show actor_prompt = prompt
response = nothing
chunkedtext = nothing
@@ -370,7 +373,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
headers = detectCharacters(response, headerToDetect)
println("")
@show response_actor = response
@show actor_response = response
headerToDetect = ["Plan $(a.attempt):",
"Thought $latestTask:",
@@ -925,7 +928,7 @@ function formulateUserresponse(a)
$work
From your talk with the user and your work, formulate a response for the user.
<|/s|>
</s>
<|assistant|>
response:
"""
@@ -1088,14 +1091,14 @@ function checkTaskCompletion(a)
</Example 1>
Let's think step by step.
</s|>
</s>
<|assistant|> After
"""
response = nothing
_response = nothing
_response = sendReceivePrompt(a, prompt, max_tokens=512)
@show checkTaskCompletion_raw = _response
_response = split(_response, "</s|>")[1]
_response = split(_response, "</")[1]
_response = split(_response, "\n\n")[1]
# response = "I " * split(_response, "{")[1] # sometime response have more than 1 {answer: done}
@@ -1110,9 +1113,46 @@ function checkTaskCompletion(a)
end
function recap(a)
@show a.memory[:shortterm]["Plan 1:"]
# stimulus = a.memory[:shortterm]["user:"]
work = dictToString(a.memory[:shortterm])
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)
# prompt =
# """
# <|system|>
# <Symbol meaning>
# Plan: a plan
# Thought: your thought
# Act: the action you took
# Actinput: the input to the action
# Obs: the result of the action
# </Symbol meaning>
# <Your earlier work>
# $work
# </Your earlier work>
# <Your job>
# Recap: list all your observed results in detail
# </Your job>
# Let's think step by step.
# </s>
# <|assistant|>
# Recap:
# """
prompt =
"""
@@ -1129,16 +1169,19 @@ function recap(a)
$work
</Your earlier work>
<Your job>
Recap: list all your observed results in detail
Extract info: extract info in details from ALL Actinput and corresponding observed result into JSON format
</Your job>
Let's think step by step.
</s|>
</s>
<|assistant|>
Recap:
Extracted info:
"""
response = sendReceivePrompt(a, prompt, max_tokens=512, temperature=0.0)
response = split(response, "</s|>")[1]
response = split(response, "</")[1]
response = split(response, "<|")[1]
response = split(response, "\n\n")[1]
return response
end