This commit is contained in:
2023-12-11 05:20:49 +00:00
parent 71986d5c9e
commit c590c49a1d
4 changed files with 85 additions and 35 deletions

View File

@@ -38,13 +38,13 @@ using ..type, ..utils
""" Add new message to agent.
Args:
Arguments:
Return:
```jldoctest
julia> addNewMessage(agent1, "user", "Where should I go to buy snacks")
````
```
"""
function addNewMessage(a::T1, role::String, content::T2) where {T1<:agent, T2<:AbstractString}
if role a.availableRole # guard against typo
@@ -608,7 +608,7 @@ end
"""
Actor function.
Args:
Arguments:
a, one of ChatAgent's agent.
plan, a step by step plan to respond
@@ -731,7 +731,7 @@ end
""" Write evaluation guideline.
Args:
Arguments:
a, one of ChatAgent's agent.
usermsg, stimulus e.g. question, task and etc.
@@ -773,7 +773,7 @@ end
""" Determine a score out of 10 according to evaluation guideline.
Args:
Arguments:
a, one of ChatAgent's agent.
guidelines, an evaluation guideline.
shorttermMemory, a short term memory that logs what happened.
@@ -840,7 +840,7 @@ end
""" Analize work.
Args:
Arguments:
a, one of ChatAgent's agent.
Return:
@@ -893,7 +893,7 @@ end
""" Write a lesson drawn from evaluation.
Args:
Arguments:
a, one of ChatAgent's agent.
report, a report resulted from analyzing shorttermMemory
@@ -947,7 +947,7 @@ end
""" Formulate a respond from work for user's stimulus.
Args:
Arguments:
a, one of ChatAgent's agent.
Return:
@@ -1004,7 +1004,7 @@ end
""" Determine whether LLM should go to next step.
Args:
Arguments:
a, one of ChatAgent's agent.
Return:
@@ -1111,39 +1111,31 @@ end
#WORKING
""" Determine whether LLM should go to next step.
""" Extract important info from text into key-value pair text.
Args:
Arguments:
a, one of ChatAgent's agent.
text, a text you want to extract info
Return:
"Yes" or "no" decision to go next step.
a text with important info are in key-value format.
# Example
```jldoctest
julia> using ChatAgent, CommUtils
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user:" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
julia> decision = goNogo(agent)
"Yes"
julia> text = "We are holding a wedding party at the beach."
julia> extract(agent, text)
"location=beach, event=wedding party"
```
"""
function extractinfo(a, msg)
function extractinfo(a, text::T) where {T<:AbstractString}
prompt =
"""
<|im_start|>system
User message:
$msg
$text
Your job is to extract important info from user's message into keys and values using this format: key=value ,.
p.s.1 you can extract many key-value pairs.

View File

@@ -10,7 +10,7 @@ using ..type, ..utils
"""
Search wikipedia.
Args:
Arguments:
query (string): The query to search for
Returns:

View File

@@ -10,7 +10,65 @@ using CommUtils
abstract type agent end
""" A LLM agent with self reflect capabilities.
# Example
```jldoctest
julia> using ChatAgent
julia> mqttClientSpec = (
clientName= "someclient", # name of this client
clientID= "$(uuid4())",
broker= "mqtt.yiem.ai",
pubtopic= (imgAI="img/api/v0.0.1/gpu/request",
txtAI="txt/api/v0.1.0/gpu/request"),
subtopic= (imgAI="agent/api/v0.1.0/img/respond",
txtAI="agent/api/v0.1.0/txt/respond"),
keepalive= 30,
)
julia> msgMeta = Dict(
:msgPurpose=> "updateStatus",
:from=> "agent",
:to=> "llmAI",
:requestrespond=> "request",
:sendto=> "", # destination topic
:replyTo=> "agent/api/v0.1.0/txt/respond", # requester ask responder to send reply to this topic
:repondToMsgId=> "", # responder is responding to this msg id
:taskstatus=> "", # "complete", "fail", "waiting" or other status
:timestamp=> Dates.now(),
:msgId=> "$(uuid4())",
)
julia> tools=Dict(
:chatbox=>Dict(
:name => "chatbox",
:description => "Useful only for when you need to ask the user for more info or context. Do not ask the user their own question.",
:input => "Input should be a text.",
:output => "" ,
:func => nothing,
),
:wikisearch=>Dict(
:name => "wikisearch",
:description => "Useful for when you need to search an encyclopedia.",
:input => "Input is keywords and not a question.",
:output => "",
:func => ChatAgent.wikisearch, # put function here
),
:winestock=>Dict(
:name => "wineStock",
:description => "useful for when you need to search your wine stock by wine description, price, name or ID.",
:input => "Input is a search query.",
:output => "Output are Wine name, description, price and ID" ,
:func => ChatAgent.winestock,
),
)
julia> agent = ChatAgent.agentReflex(
"Jene",
role=:assistant,
mqttClientSpec=mqttClientSpec,
msgMeta=msgMeta,
tools=tools
)
```
"""
@kwdef mutable struct agentReflex <: agent
availableRole::AbstractVector = ["system", "user", "assistant"]
agentName::String = "Jene" # ex. Jene

View File

@@ -542,7 +542,7 @@ end
""" Add chunked text to a short term memory of a chat agent
Args:
Arguments:
shortMem = short memory of a chat agent,
chunkedtext = a dict contains text
@@ -574,7 +574,7 @@ end
""" Split text using all keywords in a list. Start spliting from rightmost of the text.
Args:
Arguments:
text = a text you want to split
list = a list of keywords you want to split
@@ -625,7 +625,7 @@ end
""" Add step number to header in a text
Args:
Arguments:
text = a text you want to split
headers = a list of keywords you want to add step and substep to
@@ -659,7 +659,7 @@ end
""" Convert short term memory into 1 continous string.
Args:
Arguments:
shortMemory = a short term memory of a ChatAgent's agent
skiplist = a list of keys in memory you want to skip
@@ -718,7 +718,7 @@ end
""" Remove headers of specific step from memory.
Args:
Arguments:
shortMemory = a short term memory of a ChatAgent's agent
skipHeaders = a list of keys in memory you want to skip
step = a step number you want to remove
@@ -783,7 +783,7 @@ end
""" Keep only specified keys in a dictionary. All non-specified keys will be removed.
Args:
Arguments:
dict = a dictionary
keys = keys you want to keep in a dict
@@ -823,7 +823,7 @@ end
""" Convert experience dict into 1 string for LLM to use.
Args:
Arguments:
dict = a dictionary contain past experience
Return: