From da983f28741057e5ccbed3659050d57ed7173004 Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Sun, 26 Nov 2023 14:35:05 +0000 Subject: [PATCH] update --- src/interface.jl | 84 ++++++++++++++++++++++++++++++++++++++---------- src/type.jl | 2 +- src/utils.jl | 2 +- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index b65743f..66e4b00 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -644,7 +644,8 @@ function work(a::agentReflex, usermsg::String) elseif actorstate == "all steps done" println("all steps done") #WORKING give answer to the question - respond = formulateRespond() + respond = formulateRespond(a, a.memory[:shortterm]) + a.memory[:shortterm] *= "Respond: $respond\n" #TODO evaluate. if score < 8/10 try again. headerToDetect = ["user:", "assistant:", ] @@ -652,13 +653,13 @@ function work(a::agentReflex, usermsg::String) chunkedtext = chunktext(a.memory[:shortterm], headers) stimulus = chunkedtext["user:"] guideline = writeEvaluationGuideline(a, stimulus) - score = grading(a, guideline, a.memory[:shortterm]) + @show guideline + score = grading(a, guideline, respond) @show score if score >= 8 # good enough answer @show a.memory[:shortterm] - a.memory[:shortterm] = "" - a.thoughtlog = "" - respond = msgToUser + # a.memory[:shortterm] = "" + # a.thoughtlog = "" break else # self evaluate and reflect then try again report = analyze(a, a.memory[:shortterm]) @@ -831,7 +832,7 @@ julia> score = grading(agent, guideline, shorttermMemory) 2 ``` """ -function grading(a, guideline::T, shorttermMemory::T) where {T<:AbstractString} +function grading(a, guideline::T, text::T) where {T<:AbstractString} prompt = """ <|im_start|>system @@ -839,21 +840,21 @@ function grading(a, guideline::T, shorttermMemory::T) where {T<:AbstractString} chatbox: Useful for when you need to ask a customer for more context. Input should be a conversation to customer. wikisearch: Useful for when you need to search an encyclopedia Input is keywords and not a question. - Evaluation guideline: $guideline - Your work: - $shorttermMemory + Your respond: $text You job are: - 1. Evaluate your work using the evaluation guideline. - 2. Give yourself a score out of 10 for your work. - Use the following format to answer: Score {}/10. + 1. Evaluate your respond using the evaluation guideline and an example respond. + 2. Give yourself a score out of 10 for your respond. + + Use the following format to answer: + {Evaluation} Score {}/10. <|im_end|> """ - + println("prompt 11 ", prompt) respond = sendReceivePrompt(a, prompt) - println("grading = ", respond) + println("grading respond 11 = $respond") _score = split(respond[end-5:end], "/")[1] _score = split(_score, " ")[end] score = parse(Int, _score) @@ -967,10 +968,59 @@ function selfReflext(a, report::T) where {T<:AbstractString} end -""" -""" #WORKING +""" Formulate a respond from work for user's stimulus. + +Args: + a, one of ChatAgent's agent. + +Return: + A respond for user's stimulus. + +# Example + +```jldoctest +julia> using ChatAgent, CommUtils +julia> agent = ChatAgent.agentReflex("Jene") +julia> shorttermMemory = + " + user: What's AMD latest product? + assistant: Plan 1: To provide the user with information about AMD's latest product, I will search for the most recent product release from AMD. + 1. Search for \"AMD latest product\" using wikisearch tool. + 2. Identify the most recent product release mentioned in the search results. + 3. Provide the user with the name of the latest product. + + Thought 1: The user wants to know about the latest AMD products, so I should use the wikisearch tool to find information on this topic. + Act 1: wikisearch + ActInput 1: \"AMD latest product\" + Obs 1: No info available." +julia> report = formulateRespond(agent, shorttermMemory) +``` +""" function formulateRespond(a, shorttermMemory::T) where {T<:AbstractString} - + prompt = + """ + <|im_start|>system + You have access to the following tools: + chatbox: Useful for when you need to ask a customer for more context. Input should be a conversation to customer. + wikisearch: Useful for when you need to search an encyclopedia Input is keywords and not a question. + + Symbol: + Stimulus: the input user gives to you and you must respond + Plan: a plan + Thought: your thought + Act: the action you took + ActInput: the input to the action + Obs: the result of the action + + Your work: + $shorttermMemory + + From your work, formulate a respond for user's stimulus. + <|im_end|> + """ + + respond = sendReceivePrompt(a, prompt) + return respond end diff --git a/src/type.jl b/src/type.jl index 09fe5d3..ec7903f 100644 --- a/src/type.jl +++ b/src/type.jl @@ -95,7 +95,7 @@ function agentReflex( :planner=> """Use the following format: Stimulus: the input user gives to you and you must respond - Plan: first you should always think about the stimulus and the info you have thoroughly then extract and devise a step by step plan to respond (pay attention to correct numeral calculation and commonsense). + Plan: first you should always think about the stimulus and the info you have thoroughly then extract and devise a step by step plan to prepare a respond (pay attention to correct numeral calculation and commonsense). """, :actor=> """Use the following format: diff --git a/src/utils.jl b/src/utils.jl index a6dd42c..e9bdb64 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -28,7 +28,7 @@ function makeSummary(a::T1, input::T2) where {T1<:agent, T2<:AbstractString} <|im_start|>assistant """ - prompt = replace(prompt, "{input}" => usermsg) + prompt = replace(prompt, "{input}" => input) result = sendReceivePrompt(a, prompt) result = GeneralUtils.getStringBetweenCharacters(result, "{", "}") if result == "yes"