add extract_number()
This commit is contained in:
@@ -367,24 +367,24 @@ function actor_mistral_openorca(a::agentReflex, usermsg::T) where {T<:AbstractSt
|
||||
for (toolname, v) in a.tools
|
||||
toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
|
||||
toollines *= toolline
|
||||
toolnames *= "$toolname,"
|
||||
toolnames *= "$toolname, "
|
||||
end
|
||||
prompt = replace(prompt, "{toolnames}" => toolnames)
|
||||
prompt = replace(prompt, "{tools}" => "You have access to the following tools:\n$toollines")
|
||||
|
||||
context =
|
||||
"""
|
||||
{earlierConversation}
|
||||
{env state}
|
||||
{longterm memory}
|
||||
"""
|
||||
context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)")
|
||||
# context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)")
|
||||
context = replace(context, "{env state}" => "")
|
||||
context = replace(context, "{longterm memory}" => "")
|
||||
|
||||
prompt = replace(prompt, "{context}" => context)
|
||||
|
||||
prompt = replace(prompt, "{usermsg}" => "Stimulus: $usermsg")
|
||||
@show prompt
|
||||
error("actor_mistral_openorca done")
|
||||
return prompt
|
||||
end
|
||||
@@ -628,6 +628,8 @@ function work(a::agentReflex, usermsg::String)
|
||||
@show prompt
|
||||
respond = sendReceivePrompt(a, prompt)
|
||||
plan = split(respond, "<|im_end|>")[1]
|
||||
plan = split(plan, "Response:")[1]
|
||||
|
||||
@show plan
|
||||
totalsteps = checkTotalStepInPlan(a, plan)
|
||||
logmsg = "<|im_start|>assistant:\n$plan\n"
|
||||
@@ -688,6 +690,7 @@ function conversationSummary(a::T) where {T<:agent}
|
||||
<|im_start|>system
|
||||
You talked with a user earlier.
|
||||
Now you make a detailed bullet summary of the conversation from your perspective.
|
||||
Use "I" when refers to yourself in the summary.
|
||||
|
||||
Here are the conversation:
|
||||
{conversation}
|
||||
@@ -1150,8 +1153,8 @@ function checkTotalStepInPlan(a::agent, plan::T) where {T<:AbstractString}
|
||||
You are a helpful assistant.
|
||||
Your job is to determine how many steps in a user plan.
|
||||
|
||||
Use the following format only:
|
||||
{total step number}
|
||||
Use the following format to answer:
|
||||
Total step number is {}
|
||||
<|im_end|>
|
||||
|
||||
<|im_start|>user
|
||||
@@ -1161,8 +1164,7 @@ function checkTotalStepInPlan(a::agent, plan::T) where {T<:AbstractString}
|
||||
|
||||
"""
|
||||
respond = sendReceivePrompt(a, prompt)
|
||||
result = GeneralUtils.getStringBetweenCharacters(respond, "{", "}")
|
||||
result = parse(Int, result)
|
||||
result = extract_number(respond)
|
||||
|
||||
return result
|
||||
end
|
||||
@@ -1170,6 +1172,20 @@ end
|
||||
|
||||
|
||||
|
||||
function extract_number(text::T) where {T<:AbstractString}
|
||||
regex = r"\d+" # regular expression to match one or more digits
|
||||
match = Base.match(regex, text) # find the first match in the text
|
||||
if match !== nothing
|
||||
number = parse(Int, match.match)
|
||||
return number
|
||||
else
|
||||
error("No number found in the text")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1202,11 +1218,6 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ function agentReflex(
|
||||
"""Use the following format:
|
||||
Stimulus: the input user gives to you and you must respond
|
||||
Thought: your should always think about what to do (pay attention to correct numeral calculation and commonsense).
|
||||
Act: the action to take that match your thought, should be one of {toolnames}
|
||||
Act: the action to take that match your thought, should be one of [{toolnames}]
|
||||
ActInput: the input to the action (pay attention to the tool's input)
|
||||
|
||||
Begin!""",
|
||||
|
||||
Reference in New Issue
Block a user