update
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -173,7 +173,8 @@ function agentReflex(
|
||||
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.
|
||||
P.S.2 ask the user what you want to know if you didn't ask yet.
|
||||
</Your job>
|
||||
""",
|
||||
:actorOriginal=>
|
||||
|
||||
90
src/utils.jl
90
src/utils.jl
@@ -1,6 +1,6 @@
|
||||
module utils
|
||||
|
||||
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalTaskInPlan,
|
||||
export sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalTaskInPlan,
|
||||
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
|
||||
isUsePlans, conversationSummary, checkReasonableness, replaceHeaders,
|
||||
addShortMem!, splittext, dictToString, removeHeaders, keepOnlyKeys, experience,
|
||||
@@ -12,49 +12,6 @@ using ..type
|
||||
|
||||
#------------------------------------------------------------------------------------------------100
|
||||
|
||||
function makeSummary(a::T1, input::T2) where {T1<:agent, T2<:AbstractString}
|
||||
summary = "Nothing."
|
||||
prompt =
|
||||
"""
|
||||
<|im_start|>system
|
||||
Input text:
|
||||
$input
|
||||
|
||||
Your job is to determine now whether you can make a summary of the input text by choosing one of following choices:
|
||||
If you cannot make a summary say, "{No}".
|
||||
If you can make a summary say, "{Yes}".
|
||||
<|im_end|>
|
||||
"""
|
||||
prompt = replace(prompt, "{input}" => input)
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
result = GeneralUtils.getStringBetweenCharacters(result, "{", "}")
|
||||
if result == "Yes" # seperate summary part
|
||||
prompt =
|
||||
"""
|
||||
<|im_start|>system
|
||||
Input text:
|
||||
$input
|
||||
Your job is to make a concise summary of the input text.
|
||||
<|im_end|>
|
||||
"""
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
if result[1:1] == "\n"
|
||||
summary = result[2:end]
|
||||
else
|
||||
summary = result
|
||||
end
|
||||
end
|
||||
input_summary = input
|
||||
@show input_summary
|
||||
@show summary
|
||||
|
||||
return summary
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Send a msg to registered mqtt topic within mqttClient.
|
||||
|
||||
@@ -496,43 +453,22 @@ end
|
||||
```
|
||||
"""
|
||||
function conversationSummary(a::T) where {T<:agent}
|
||||
conversation = messagesToString_nomark(a.messages, addressAIas="I")
|
||||
prompt =
|
||||
"""
|
||||
<|im_start|>system
|
||||
You talked with a user earlier.
|
||||
Now you make a detailed bullet summary of the conversation from your perspective.
|
||||
<|system|>
|
||||
Your conversation with the user:
|
||||
$conversation
|
||||
|
||||
Your job is to paraphrase a conversation from your perspective.
|
||||
You must refers to yourself by "I" in the summary.
|
||||
|
||||
Here are the conversation:
|
||||
{conversation}
|
||||
<|im_end|>
|
||||
|
||||
<|/s|>
|
||||
<|assistant|>
|
||||
Paraphrase:
|
||||
"""
|
||||
conversation = ""
|
||||
summary = ""
|
||||
if length(a.messages)!= 0
|
||||
for msg in a.messages[1:end-1]
|
||||
role = msg[:role]
|
||||
content = msg[:content]
|
||||
|
||||
if role == "user"
|
||||
conversation *= "$role: $content\n"
|
||||
elseif role == "assistant"
|
||||
conversation *= "I: $content\n"
|
||||
else
|
||||
error("undefied condition role = $role $(@__LINE__)")
|
||||
end
|
||||
end
|
||||
|
||||
prompt = replace(prompt, "{conversation}" => conversation)
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
summary = result === nothing ? "N/A" : result
|
||||
summary = split(summary, "<|im_end|>")[1]
|
||||
if summary[1:1] == "\n"
|
||||
summary = summary[2:end]
|
||||
end
|
||||
end
|
||||
@show summary
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
summary = split(result, "<|/s|>")[1]
|
||||
summary =
|
||||
return summary
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user