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

@@ -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