-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ConversationMemory and AnnotationMessage (#238)
- Loading branch information
1 parent
f92c102
commit 5548745
Showing
22 changed files
with
880 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
annotate!(messages::AbstractVector{<:AbstractMessage}, content; kwargs...) | ||
annotate!(message::AbstractMessage, content; kwargs...) | ||
Add an annotation message to a vector of messages or wrap a single message in a vector with an annotation. | ||
The annotation is always inserted after any existing annotation messages. | ||
# Arguments | ||
- `messages`: Vector of messages or single message to annotate | ||
- `content`: Content of the annotation | ||
- `kwargs...`: Additional fields for the AnnotationMessage (extras, tags, comment) | ||
# Returns | ||
Vector{AbstractMessage} with the annotation message inserted | ||
# Example | ||
```julia | ||
messages = [SystemMessage("Assistant"), UserMessage("Hello")] | ||
annotate!(messages, "This is important"; tags=[:important], comment="For review") | ||
``` | ||
""" | ||
function annotate!(messages::AbstractVector{T}, content::AbstractString; | ||
kwargs...) where {T <: AbstractMessage} | ||
# Convert to Vector{AbstractMessage} if needed | ||
messages_abstract = T == AbstractMessage ? messages : | ||
convert(Vector{AbstractMessage}, messages) | ||
|
||
# Find last annotation message index | ||
last_anno_idx = findlast(isabstractannotationmessage, messages_abstract) | ||
insert_idx = isnothing(last_anno_idx) ? 1 : last_anno_idx + 1 | ||
|
||
# Create and insert annotation message | ||
anno = AnnotationMessage(; content = content, kwargs...) | ||
insert!(messages_abstract, insert_idx, anno) | ||
return messages_abstract | ||
end | ||
|
||
function annotate!(message::AbstractMessage, content::AbstractString; kwargs...) | ||
return annotate!(AbstractMessage[message], content; kwargs...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5548745
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release notes:
Breaking
MISTRALAI_API_KEY
toMISTRAL_API_KEY
to be compatible with the Mistral docs.Added
gemini-exp-1121
with aliasgemexp
).AnnotationMessage
type for keeping human-only information in the message changes. See?annotate!
on how to use it.ConversationMemory
type to enable long multi-turn conversations with a truncated memory of the conversation history. Truncation works in "batches" to not prevent caching. See?ConversationMemory
andget_last
for more information.Updated
MISTRALAI_API_KEY
toMISTRAL_API_KEY
to be compatible with the Mistral docs.Commits
5548745
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/120228
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: