Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svilupp committed Nov 26, 2024
1 parent 58ca841 commit a6fb649
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
46 changes: 46 additions & 0 deletions test/annotation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,49 @@ using PromptingTools: AnnotationMessage, SystemMessage, TracerMessage, UserMessa
@test all(!isabstractannotationmessage, rendered)
end
end

@testset "annotate!" begin
# Test basic annotation with single message
msg = UserMessage("Hello")
annotated = annotate!(msg, "metadata"; tags = [:test])
@test length(annotated) == 2
@test isabstractannotationmessage(annotated[1])
@test annotated[1].content == "metadata"
@test annotated[1].tags == [:test]
@test annotated[2].content == "Hello"

# Test annotation with vector of messages
messages = [
SystemMessage("System"),
UserMessage("User"),
AIMessage("AI")
]
annotated = annotate!(messages, "metadata"; comment = "test comment")
@test length(annotated) == 4
@test isabstractannotationmessage(annotated[1])
@test annotated[1].content == "metadata"
@test annotated[1].comment == "test comment"
@test annotated[2:end] == messages

# Test annotation with existing annotations
messages = [
AnnotationMessage("First annotation"),
SystemMessage("System"),
UserMessage("User"),
AnnotationMessage("Second annotation"),
AIMessage("AI")
]
annotated = annotate!(messages, "new metadata")
@test length(annotated) == 6
@test isabstractannotationmessage(annotated[1])
@test isabstractannotationmessage(annotated[4])
@test annotated[5].content == "new metadata"
@test annotated[6].content == "AI"

# Test annotation with extras
extras = Dict{Symbol, Any}(:key => "value")
annotated = annotate!(UserMessage("Hello"), "metadata"; extras = extras)
@test length(annotated) == 2
@test annotated[1].content == "metadata"
@test annotated[1].extras == extras
end
9 changes: 1 addition & 8 deletions test/messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using PromptingTools: isusermessage, issystemmessage, isdatamessage, isaimessage
istracermessage, isaitoolrequest, istoolmessage,
isabstractannotationmessage
using PromptingTools: TracerMessageLike, TracerMessage, align_tracer!, unwrap,
AbstractTracerMessage, AbstractTracer, pprint
AbstractTracerMessage, AbstractTracer, pprint, annotate!
using PromptingTools: TracerSchema, SaverSchema

@testset "Message constructors" begin
Expand Down Expand Up @@ -79,13 +79,6 @@ end
@test isabstractannotationmessage(msgs[1])
@test msgs[1].tags == [:debug]

# Test single message annotation
msg = UserMessage("Test")
result = annotate!(msg, "Annotation", comment = "Note")
@test length(result) == 2
@test isabstractannotationmessage(result[1])
@test result[1].comment == "Note"

# Test pretty printing
io = IOBuffer()
pprint(io, annotation)
Expand Down

0 comments on commit a6fb649

Please sign in to comment.