update
This commit is contained in:
+179
@@ -0,0 +1,179 @@
|
||||
module utils
|
||||
|
||||
export clearhistory, availableWineToText, prepareContext
|
||||
|
||||
using UUIDs, Dates, DataStructures, HTTP, JSON
|
||||
using GeneralUtils
|
||||
using ..type
|
||||
|
||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||
|
||||
"""
|
||||
Clear agent chat history.
|
||||
|
||||
Empties the conversation history, short-term memory, events log, and chatbox.
|
||||
|
||||
# Arguments
|
||||
- `a::T`: An agent instance (subtype of `agent`)
|
||||
|
||||
# Returns
|
||||
- `nothing`
|
||||
|
||||
# Notes
|
||||
- Does not clear long-term memory; use `[PENDING] clear memory` when implemented.
|
||||
|
||||
# Examples
|
||||
```jldoctest
|
||||
julia> YiemAgent.clearhistory(agent)
|
||||
```
|
||||
"""
|
||||
function clearhistory(a::T) where {T<:agent}
|
||||
empty!(a.chathistory)
|
||||
empty!(a.memory["shortmem"])
|
||||
empty!(a.memory["events"])
|
||||
a.memory["chatbox"] = ""
|
||||
end
|
||||
|
||||
|
||||
"""
|
||||
Convert a vector of wine dictionaries to a formatted text string.
|
||||
|
||||
# Arguments
|
||||
- `vecd::Vector`: A vector of dictionaries, each representing a wine with key-value pairs
|
||||
|
||||
# Returns
|
||||
- A formatted string where each wine is numbered and each key-value pair is comma-separated
|
||||
in the format: `"1) key1:value1,key2:value2 key3:value3 2) ..."`
|
||||
|
||||
# Examples
|
||||
```jldoctest
|
||||
julia> vecd = [Dict("wine_name" => "Chateau A", "price" => "50")]
|
||||
julia> YiemAgent.availableWineToText(vecd)
|
||||
"1) wine_name:Chateau A,price:50 "
|
||||
```
|
||||
"""
|
||||
function availableWineToText(vecd::Vector)::String
|
||||
# Initialize an empty string to hold the final text
|
||||
rowtext = ""
|
||||
# Loop through each dictionary in the input vector
|
||||
for (i, d) in enumerate(vecd)
|
||||
# Iterate over all key-value pairs in the dictionary
|
||||
temp = []
|
||||
for (k, v) in d
|
||||
# Append the formatted string to the text variable
|
||||
t = "$k:$v"
|
||||
push!(temp, t)
|
||||
end
|
||||
_rowtext = join(temp, ',')
|
||||
rowtext *= "$i) $_rowtext "
|
||||
end
|
||||
|
||||
return rowtext
|
||||
end
|
||||
|
||||
|
||||
|
||||
"""
|
||||
prepareContext(state::agentState) -> Vector{agentMessage}
|
||||
|
||||
Returns a deep copy of the messages from the given `agentState`, ready
|
||||
to be sent to the LLM. Override this function to inject additional
|
||||
context — such as retrieved documents, current time, user preferences,
|
||||
or any other relevant information — into the message list before
|
||||
formatting and calling the LLM.
|
||||
|
||||
By default, returns an exact copy of `state.messages` without
|
||||
modification.
|
||||
|
||||
# Arguments
|
||||
- `state::agentState`: The current agent state containing conversation history
|
||||
|
||||
# Returns
|
||||
- `Vector{agentMessage}`: A deep copy of the messages to be sent to the LLM
|
||||
|
||||
# Examples
|
||||
```julia
|
||||
# Default: returns a deep copy of messages
|
||||
prepareContext(state) == deepcopy(state.messages)
|
||||
|
||||
# Override to inject system context:
|
||||
# function Base.prepareContext(state::agentState)
|
||||
# msgs = deepcopy(state.messages)
|
||||
# pushfirst!(msgs, textMessage("system", "You are a helpful assistant."))
|
||||
# return msgs
|
||||
# end
|
||||
```
|
||||
"""
|
||||
function prepareContext(state::agentState)::Vector{agentMessage}
|
||||
messages = deepcopy(state.messages) # messages that will be send to LLM
|
||||
|
||||
#TODO adjust/modify and inject additional context into messages
|
||||
|
||||
return messages
|
||||
end
|
||||
|
||||
|
||||
function formatMsgForLLM()
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end # module util
|
||||
Reference in New Issue
Block a user