This commit is contained in:
narawat lamaiin
2025-05-14 21:21:35 +07:00
parent a0152a3c29
commit d0c26e52e8
4 changed files with 659 additions and 465 deletions

View File

@@ -1,7 +1,7 @@
module util
export clearhistory, addNewMessage, chatHistoryToText, eventdict, noises, createTimeline,
availableWineToText, createEventsLog
availableWineToText, createEventsLog, createChatLog
using UUIDs, Dates, DataStructures, HTTP, JSON3
using GeneralUtils
@@ -301,10 +301,10 @@ function createTimeline(events::T1; eventindex::Union{UnitRange, Nothing}=nothin
for (i, event) in zip(ind, events)
# If no outcome exists, format without outcome
if event[:outcome] === nothing
timeline *= "Event_$i $(event[:subject])> $(event[:actioninput])\n"
timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: Not done yet.\n"
# If outcome exists, include it in formatting
else
timeline *= "Event_$i $(event[:subject])> $(event[:actioninput]) $(event[:outcome])\n"
timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: $(event[:outcome])\n"
end
end
@@ -313,15 +313,15 @@ function createTimeline(events::T1; eventindex::Union{UnitRange, Nothing}=nothin
end
function createEventsLog(events::T1; eventindex::Union{UnitRange, Nothing}=nothing
function createEventsLog(events::T1; index::Union{UnitRange, Nothing}=nothing
) where {T1<:AbstractVector}
# Initialize empty log array
log = Dict{Symbol, String}[]
# Determine which indices to use - either provided range or full length
ind =
if eventindex !== nothing
[eventindex...]
if index !== nothing
[index...]
else
1:length(events)
end
@@ -338,7 +338,7 @@ function createEventsLog(events::T1; eventindex::Union{UnitRange, Nothing}=nothi
subject = event[:subject]
actioninput = event[:actioninput]
outcome = event[:outcome]
str = "$subject: $actioninput $outcome"
str = "Action: $actioninput Outcome: $outcome"
d = Dict{Symbol, String}(:name=>subject, :text=>str)
push!(log, d)
end
@@ -348,6 +348,31 @@ function createEventsLog(events::T1; eventindex::Union{UnitRange, Nothing}=nothi
end
function createChatLog(chatdict::T1; index::Union{UnitRange, Nothing}=nothing
) where {T1<:AbstractVector}
# Initialize empty log array
log = Dict{Symbol, String}[]
# Determine which indices to use - either provided range or full length
ind =
if index !== nothing
[index...]
else
1:length(chatdict)
end
# Iterate through events and format each one
for (i, event) in zip(ind, chatdict)
subject = event[:name]
text = event[:text]
d = Dict{Symbol, String}(:name=>subject, :text=>text)
push!(log, d)
end
return log
end
@@ -382,9 +407,6 @@ end