From 06a518b37cdbb11515f32c1dd8401e85cff7e068 Mon Sep 17 00:00:00 2001 From: J S <49557684+svilupp@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:15:22 +0000 Subject: [PATCH] up --- src/messages.jl | 8 ++------ test/serialization.jl | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/messages.jl b/src/messages.jl index 2cbceb712..0a2400cc1 100644 --- a/src/messages.jl +++ b/src/messages.jl @@ -49,7 +49,7 @@ function UserMessage(content::T, end Base.@kwdef struct UserMessageWithImages{T <: AbstractString} <: AbstractChatMessage content::T - image_url::Vector{<:AbstractString} # no default! fail when not provided + image_url::Vector{String} # no default! fail when not provided variables::Vector{Symbol} = _extract_handlebar_variables(content) _type::Symbol = :usermessagewithimages UserMessageWithImages{T}(c, i, v, t) where {T <: AbstractString} = new(c, i, v, t) @@ -59,7 +59,7 @@ function UserMessageWithImages(content::T, image_url::Vector{<:AbstractString}, type::Symbol) where {T <: AbstractString} not_allowed_kwargs = intersect(variables, RESERVED_KWARGS) @assert length(not_allowed_kwargs)==0 "Error: Some placeholders are invalid, as they are reserved for `ai*` functions. Change: $(join(not_allowed_kwargs,","))" - return UserMessageWithImages{T}(content, image_url, variables, type) + return UserMessageWithImages{T}(content, string.(image_url), variables, type) end Base.@kwdef struct AIMessage{T <: Union{AbstractString, Nothing}} <: AbstractChatMessage content::T = nothing @@ -89,10 +89,6 @@ Base.var"=="(m1::AbstractMessage, m2::AbstractMessage) = false function Base.var"=="(m1::T, m2::T) where {T <: AbstractMessage} all([getproperty(m1, f) == getproperty(m2, f) for f in fieldnames(T)]) end -Base.length(t::AbstractMessage) = nfields(t) -function Base.iterate(t::AbstractMessage, iter = 1) - iter > nfields(t) ? nothing : (getfield(t, iter), iter + 1) -end ## Vision Models -- Constructor and Conversion "Construct `UserMessageWithImages` with 1 or more images. Images can be either URLs or local paths." diff --git a/test/serialization.jl b/test/serialization.jl index 21f75e69f..59066428f 100644 --- a/test/serialization.jl +++ b/test/serialization.jl @@ -1,4 +1,5 @@ -using PromptingTools: AIMessage, SystemMessage, UserMessage +using PromptingTools: AIMessage, + SystemMessage, UserMessage, UserMessageWithImages, AbstractMessage, DataMessage using PromptingTools: save_conversation, load_conversation using PromptingTools: save_template, load_template @@ -7,7 +8,9 @@ using PromptingTools: save_template, load_template messages = AbstractMessage[SystemMessage("System message 1"), UserMessage("User message"), AIMessage("AI message"), - DataMessage(; content = "Data message")] + UserMessageWithImages(; content = "a", image_url = String["b", "c"]), + DataMessage(; + content = "Data message")] tmp, _ = mktemp() save_conversation(tmp, messages) # Test load_conversation