Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ConversationMemory and enhance AnnotationMessage #238

Merged
merged 137 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
ac751a9
Revert "update deps"
svilupp Feb 26, 2024
423faef
remove GoogleGenAI (#83)
svilupp Feb 26, 2024
320b9b7
fix docs
svilupp Feb 27, 2024
18e1b71
Templating utilities (#84)
svilupp Feb 28, 2024
5200985
update docs + version (#85)
svilupp Feb 29, 2024
846aa37
Add image generation with DALL-E 3 (#86)
svilupp Mar 1, 2024
37fa1f4
update changelog (#87)
svilupp Mar 1, 2024
b8e888d
Update docs to Vitepress (#88)
svilupp Mar 1, 2024
4d26a4f
update docs/make.jl
svilupp Mar 1, 2024
a581d55
fix CI
svilupp Mar 1, 2024
83cefd9
Fix CI nr2
svilupp Mar 1, 2024
db91e60
Fix CI nr3
svilupp Mar 1, 2024
2d45b8e
Fix CI nr4
svilupp Mar 1, 2024
a84f230
Fix CI nr5
svilupp Mar 1, 2024
81198f5
Fix CI nr.6
svilupp Mar 1, 2024
0d6954e
Fix CI nr7
svilupp Mar 1, 2024
37603a4
Fix CI nr8
svilupp Mar 1, 2024
e97f571
Update README.md
svilupp Mar 2, 2024
cd681c8
Add support annotations (#90)
svilupp Mar 7, 2024
b3756b2
Update Documentation (#91)
svilupp Mar 9, 2024
94911cf
Add Prompt Templates to the Docs (#92)
svilupp Mar 9, 2024
846d069
fix typo on set_preferences! examples, fixes #93 (#94)
ceferisbarov Mar 17, 2024
3b30d66
RAG Interface Rewrite (#95)
svilupp Mar 20, 2024
2509e0b
Update Google AI tutorial (#103)
svilupp Mar 21, 2024
e347081
Allow HTMLStyler in node annotations (#105)
svilupp Mar 21, 2024
96357ce
update diagram in the docs (#108)
svilupp Mar 22, 2024
ce4a2ed
A little README.md correction (#107)
Muhammad-saad-2000 Mar 24, 2024
7cab975
Add support for Claude API (#109)
svilupp Mar 25, 2024
5146a95
Enable GoogleGenAI extension (#111)
svilupp Mar 26, 2024
4925b70
Update CHANGELOG.md (#104)
svilupp Mar 26, 2024
5d9d132
Add ShareGPT template (#113)
svilupp Mar 26, 2024
82d87db
Increase compat for GoogleGenAI v0.3
svilupp Mar 26, 2024
069b6f6
Update html printing (#115)
svilupp Mar 27, 2024
7eb32b1
Fix bug in `print_html` (#116)
svilupp Mar 27, 2024
ee3459d
Add Binary embeddings to RAGTools (#117)
svilupp Apr 3, 2024
024562d
Add data extraction for Anthropic models (#122)
svilupp Apr 5, 2024
fc0073e
Register mistral tiny (#123)
svilupp Apr 6, 2024
84f68cc
Add new GPT-4 Turbo (#124)
svilupp Apr 10, 2024
5054f4c
Update code fences in the hero cards in the docs
cpfiffer Apr 11, 2024
49f3f5b
Update Docs Hero page
svilupp Apr 11, 2024
eb94d1a
Add TraceMessage for observability (#133)
svilupp Apr 15, 2024
23e4f0b
Update binary RAG pipeline (#136)
svilupp Apr 17, 2024
a81bd76
Fix truncate_dimension (#137)
svilupp Apr 18, 2024
790b4e2
Add Llama 3 (#138)
svilupp Apr 19, 2024
02b7cf1
Add support for groq (#139)
svilupp Apr 20, 2024
3b18f02
Update Project.toml (#140)
svilupp Apr 20, 2024
ebaa2c5
Update new OpenAI pre-paid credit requirements (#135)
KronosTheLate Apr 20, 2024
4f28fb6
Add model providers and Supported functions (#134)
adarshpalaskar1 Apr 20, 2024
382638d
Add templates and minor improvements (#142)
svilupp Apr 27, 2024
4655422
Add DeepSeek models (#147)
svilupp May 7, 2024
36aa9cb
Update Changelog (#148)
svilupp May 7, 2024
64f51cb
Add GPT4-Omni
svilupp May 13, 2024
f29b99e
Improvements to aiclassify and aitemplates (#150)
svilupp May 18, 2024
2549722
Improve tracer schema / automated logging (#151)
svilupp May 19, 2024
d244680
Add BitPacked embeddings for RAG retrieval (#152)
svilupp May 19, 2024
39647b3
Add more tracer kwargs for logging
svilupp May 20, 2024
d8f3fca
Fix LCS utility
svilupp May 21, 2024
dee5263
Template file parsing fix
svilupp May 22, 2024
bf1eb85
Add BM25 Index (#157)
svilupp May 28, 2024
608bdf0
E2E Hybrid retrieval
svilupp May 28, 2024
6ec6456
Register Mistral Codestral
svilupp May 29, 2024
0f45fde
add FlashRank.jl package extension
svilupp Jun 11, 2024
f3e3994
Update deps
svilupp Jun 14, 2024
223107f
Update RAG performance
svilupp Jun 18, 2024
a4f191a
Improve unpack_bits (#165)
svilupp Jun 18, 2024
03029ee
Update FlashRank to use only unique documents (#166)
svilupp Jun 18, 2024
bbb1c38
fix formatting of changelog
svilupp Jun 18, 2024
f63935d
Add Anthropic Sonnet 3.5 (#167)
svilupp Jun 20, 2024
be91226
Rag Tools fix + relaxing `const` for API key loading
svilupp Jun 26, 2024
971e926
Update CHANGELOG.md
svilupp Jun 26, 2024
4f0cfd7
Add back API keys
svilupp Jun 26, 2024
af4f67f
Add RankGPT (#172)
svilupp Jul 1, 2024
44450c0
Reciprocal Rank Fusion
svilupp Jul 1, 2024
b5f089f
Update rankGPT
svilupp Jul 2, 2024
6e9f0ea
Compat-flashrank-v04
svilupp Jul 7, 2024
988f3d3
Fix CohereReranker bug
svilupp Jul 9, 2024
dd3fbbc
Drafter update
svilupp Jul 13, 2024
dfb88a1
Add AllTagFilter (#178)
svilupp Jul 16, 2024
53ac0b8
Add GPT-4o-mini + set as default (#180)
svilupp Jul 19, 2024
fcd7509
Add SubChunkIndex (view of index)
svilupp Jul 21, 2024
89d4c43
Add SubDocumentTermMatrix (#181)
svilupp Jul 22, 2024
0f1a334
Register Llama3.1 + minor retrieval improvements
svilupp Jul 23, 2024
c02bd43
Llama 3.1 Fireworks.ai
svilupp Jul 24, 2024
886bdd1
Add Mistral Large 2 and Nemo
svilupp Jul 24, 2024
f6cb37d
Fix wrap string
svilupp Jul 30, 2024
0916bd7
version fix
svilupp Jul 30, 2024
e2553b8
Updates embedding concatenation (#186)
svilupp Aug 4, 2024
1473799
Fix getindex
svilupp Aug 4, 2024
1f941f9
Update RAGTools docstrings
svilupp Aug 5, 2024
a53fbfe
Add GPT4o registry entry
svilupp Aug 7, 2024
7d6a8d8
Add DTM specialized method
svilupp Aug 8, 2024
8f697f6
Add OpenAI structured outputs
svilupp Aug 9, 2024
a2cde30
Add ChatGPT 4o (#195)
svilupp Aug 14, 2024
8e880f8
Add experimental prompt cache support for Anthropic
svilupp Aug 16, 2024
06aa438
Improved docs styling with DocumenterVitepress
lazarusA Aug 20, 2024
271ff08
Add assertion for empty docs in `get_embeddings` (#200)
iuliadmtru Aug 23, 2024
5fe770a
Fix documentation for building RAG (#201)
iuliadmtru Aug 23, 2024
1c8fb7d
Update Structured Extraction
svilupp Sep 3, 2024
e1a3d23
Add stream callbacks
svilupp Sep 7, 2024
1ef3ba3
Update Anthropic kwargs + docs
svilupp Sep 9, 2024
a125fcd
Updated DocumentTermMatrix implementation
svilupp Sep 10, 2024
7038175
OpenAI JSON mode extraction
svilupp Sep 15, 2024
9a75d2c
OpenRouter support, new OpenAI o1 models (#207)
svilupp Sep 15, 2024
fe23115
Update reserved keywords
svilupp Sep 15, 2024
51a46bc
Tidy up streaming
svilupp Sep 17, 2024
2a01bb5
Enable Streaming for OpenAI-compatible models
svilupp Sep 18, 2024
0745925
Fix logging
svilupp Sep 22, 2024
cd3f891
Support for Azure OpenAI API
pabvald Sep 24, 2024
ea8d51a
Version up
svilupp Sep 24, 2024
a66da99
Add Cerebras API + node validation for airetry!
svilupp Oct 9, 2024
f945ab9
Tool interface update
svilupp Oct 19, 2024
5280ee8
Add a new models, clean up tools (#219)
svilupp Oct 20, 2024
c57d209
Update VERSION
svilupp Oct 20, 2024
a8c1799
Multi-turn tool fix
svilupp Oct 20, 2024
e7b5f7f
Update anthropic models (#223)
svilupp Oct 22, 2024
80e232d
Add streaming for OllamaSchema (#224)
svilupp Oct 26, 2024
4c3516f
Fix call_cost (#225)
svilupp Nov 3, 2024
158f409
Anthropic computer use (#226)
svilupp Nov 3, 2024
8b6f951
Update Callbacks compat + ToolRef definition (#227)
svilupp Nov 3, 2024
b2bcb94
Update tool execution
svilupp Nov 3, 2024
bcc7c81
Add Haiku35 and Grok2Beta
svilupp Nov 5, 2024
31b1c27
Fix tool dict (#230)
svilupp Nov 6, 2024
3cd535e
Gwen 72B and open-router Google Flash added. (#232)
Sixzero Nov 11, 2024
faaf9ce
Add GoogleOpenAISchema with comprehensive test logging (#234)
devin-ai-integration[bot] Nov 12, 2024
8a2fd46
Add image support to aitools (#235)
svilupp Nov 17, 2024
42fafbb
[Breaking] Renamed MISTRALAI to MISTRAL everywhere (#231)
Sixzero Nov 18, 2024
3cf6e88
update Google Gemini model (#237)
svilupp Nov 23, 2024
efe8748
feat: Add ConversationMemory and enhance AnnotationMessage
devin-ai-integration[bot] Nov 25, 2024
d90bd07
Fix annotation message rendering tests for different schema structures
devin-ai-integration[bot] Nov 25, 2024
3f9f4dc
Fix AnnotationMessage tests and implementation
devin-ai-integration[bot] Nov 25, 2024
3b54eef
update tests
svilupp Nov 26, 2024
a64fca8
up
svilupp Nov 26, 2024
47354cd
cleanup
svilupp Nov 26, 2024
7b79d8b
Merge branch 'devin/1732559303-add-conversation-memory-and-annotation…
svilupp Nov 26, 2024
2599ce7
Merge branch 'main' into devin/1732559303-add-conversation-memory-and…
svilupp Nov 26, 2024
58ca841
update tests
svilupp Nov 26, 2024
a6fb649
update tests
svilupp Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
docs/package-lock.json

# Ignore Cursor rules
.cursorrules
.cursorrules

# Ignore any local preferences
**/LocalPreferences.toml
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added a new Gemini Experimental model from November 2024 (`gemini-exp-1121` with alias `gemexp`).
- Added a new `AnnotationMessage` type for keeping human-only information in the message changes. See `?annotate!` on how to use it.
- Added a new `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` and `get_last` for more information.


### Updated
- Changed the ENV variable for MistralAI API from `MISTRALAI_API_KEY` to `MISTRAL_API_KEY` to be compatible with the Mistral docs.
Expand Down
6 changes: 5 additions & 1 deletion src/PromptingTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ include("user_preferences.jl")

## Conversation history / Prompt elements
export AIMessage
# export UserMessage, UserMessageWithImages, SystemMessage, DataMessage # for debugging only
include("messages.jl")

# export ConversationMemory
include("memory.jl")
# export annotate!
include("annotation.jl")

export aitemplates, AITemplate
include("templates.jl")

Expand Down
40 changes: 40 additions & 0 deletions src/annotation.jl
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
7 changes: 6 additions & 1 deletion src/llm_anthropic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ function render(schema::AbstractAnthropicSchema,
no_system_message::Bool = false,
cache::Union{Nothing, Symbol} = nothing,
kwargs...)
##
##
@assert count(issystemmessage, messages)<=1 "AbstractAnthropicSchema only supports at most 1 System message"
@assert (isnothing(cache)||cache in [:system, :tools, :last, :all]) "Currently only `:system`, `:tools`, `:last`, `:all` are supported for Anthropic Prompt Caching"

# Filter out annotation messages before any processing
messages = filter(!isabstractannotationmessage, messages)

system = nothing

## First pass: keep the message types but make the replacements provided in `kwargs`
Expand All @@ -44,6 +47,8 @@ function render(schema::AbstractAnthropicSchema,
for msg in messages_replaced
if issystemmessage(msg)
system = msg.content
elseif isabstractannotationmessage(msg)
continue
elseif isusermessage(msg) || isaimessage(msg)
content = msg.content
push!(conversation,
Expand Down
6 changes: 6 additions & 0 deletions src/llm_google.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function render(schema::AbstractGoogleSchema,
no_system_message::Bool = false,
kwargs...)
##
# Filter out annotation messages before any processing
messages = filter(!isabstractannotationmessage, messages)

## First pass: keep the message types but make the replacements provided in `kwargs`
messages_replaced = render(
NoSchema(), messages; conversation, no_system_message, kwargs...)
Expand All @@ -34,6 +37,9 @@ function render(schema::AbstractGoogleSchema,

# replace any handlebar variables in the messages
for msg in messages_replaced
if isabstractannotationmessage(msg)
continue
end
push!(conversation,
Dict(
:role => role4render(schema, msg), :parts => [Dict("text" => msg.content)]))
Expand Down
13 changes: 10 additions & 3 deletions src/llm_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ struct OpenAISchema <: AbstractOpenAISchema end

"Echoes the user's input back to them. Used for testing the implementation"
@kwdef mutable struct TestEchoOpenAISchema <: AbstractOpenAISchema
response::AbstractDict
status::Integer
response::AbstractDict = Dict(
"choices" => [Dict("message" => Dict("content" => "Test response", "role" => "assistant"), "index" => 0, "finish_reason" => "stop")],
"usage" => Dict("prompt_tokens" => 10, "completion_tokens" => 20, "total_tokens" => 30),
"model" => "gpt-3.5-turbo",
"id" => "test-id",
"object" => "chat.completion",
"created" => 1234567890
)
status::Integer = 200
model_id::String = ""
inputs::Any = nothing
end

"""
CustomOpenAISchema
CustomOpenAISchema

CustomOpenAISchema() allows user to call any OpenAI-compatible API.

Expand Down
8 changes: 7 additions & 1 deletion src/llm_ollama.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function render(schema::AbstractOllamaSchema,
no_system_message::Bool = false,
kwargs...)
##
# Filter out annotation messages before any processing
messages = filter(!isabstractannotationmessage, messages)

## First pass: keep the message types but make the replacements provided in `kwargs`
messages_replaced = render(
NoSchema(), messages; conversation, no_system_message, kwargs...)
Expand All @@ -36,6 +39,9 @@ function render(schema::AbstractOllamaSchema,

# replace any handlebar variables in the messages
for msg in messages_replaced
if isabstractannotationmessage(msg)
continue
end
new_message = Dict{String, Any}(
"role" => role4render(schema, msg), "content" => msg.content)
## Special case for images
Expand Down Expand Up @@ -376,4 +382,4 @@ end
function aitools(prompt_schema::AbstractOllamaSchema, prompt::ALLOWED_PROMPT_TYPE;
kwargs...)
error("Managed schema does not support aitools. Please use OpenAISchema instead.")
end
end
2 changes: 2 additions & 0 deletions src/llm_ollama_managed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function render(schema::AbstractOllamaManagedSchema,
system = msg.content
elseif msg isa UserMessage
prompt = msg.content
elseif isabstractannotationmessage(msg)
continue
elseif msg isa UserMessageWithImages
error("Managed schema does not support UserMessageWithImages. Please use OpenAISchema instead.")
elseif msg isa AIMessage
Expand Down
8 changes: 7 additions & 1 deletion src/llm_openai.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function render(schema::AbstractOpenAISchema,
kwargs...)
##
@assert image_detail in ["auto", "high", "low"] "Image detail must be one of: auto, high, low"

# Filter out annotation messages before any processing
messages = filter(!isabstractannotationmessage, messages)

## First pass: keep the message types but make the replacements provided in `kwargs`
messages_replaced = render(
NoSchema(), messages; conversation, no_system_message, kwargs...)
Expand Down Expand Up @@ -71,6 +75,8 @@ function render(schema::AbstractOpenAISchema,
content = msg.content isa AbstractString ? msg.content : string(msg.content)
Dict("role" => role4render(schema, msg), "content" => content,
"tool_call_id" => msg.tool_call_id)
elseif isabstractannotationmessage(msg)
continue
else
## Vanilla assistant message
Dict("role" => role4render(schema, msg),
Expand Down Expand Up @@ -1733,4 +1739,4 @@ function aitools(prompt_schema::AbstractOpenAISchema, prompt::ALLOWED_PROMPT_TYP
kwargs...)

return output
end
end
7 changes: 7 additions & 0 deletions src/llm_shared.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ role4render(schema::AbstractPromptSchema, msg::UserMessageWithImages) = "user"
role4render(schema::AbstractPromptSchema, msg::AIMessage) = "assistant"
role4render(schema::AbstractPromptSchema, msg::AIToolRequest) = "assistant"
role4render(schema::AbstractPromptSchema, msg::ToolMessage) = "tool"
role4render(schema::AbstractPromptSchema, msg::AbstractAnnotationMessage) = "annotation"
"""
render(schema::NoSchema,
messages::Vector{<:AbstractMessage};
Expand Down Expand Up @@ -39,6 +40,9 @@ function render(schema::NoSchema,
count_system_msg = count(issystemmessage, conversation)
# TODO: concat multiple system messages together (2nd pass)

# Filter out annotation messages from input messages
messages = filter(!isabstractannotationmessage, messages)

# replace any handlebar variables in the messages
for msg in messages
if issystemmessage(msg) || isusermessage(msg) || isusermessagewithimages(msg)
Expand Down Expand Up @@ -73,6 +77,9 @@ function render(schema::NoSchema,
count_system_msg += 1
# move to the front
pushfirst!(conversation, msg)
elseif isabstractannotationmessage(msg)
# Ignore annotation messages
continue
else
# Note: Ignores any DataMessage or other types for the prompt/conversation history
@warn "Unexpected message type: $(typeof(msg)). Skipping."
Expand Down
2 changes: 1 addition & 1 deletion src/llm_sharegpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
function render(schema::AbstractShareGPTSchema, conv::AbstractVector{<:AbstractMessage})
Dict("conversations" => [Dict("from" => role4render(schema, msg),
"value" => msg.content)
for msg in conv])
for msg in conv if !isabstractannotationmessage(msg)])
end

### AI Functions
Expand Down
3 changes: 3 additions & 0 deletions src/llm_tracer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ end
function role4render(schema::AbstractTracerSchema, msg::AIMessage)
role4render(schema.schema, msg)
end
function role4render(schema::AbstractTracerSchema, msg::AbstractAnnotationMessage)
role4render(schema.schema, msg)
end
"""
render(tracer_schema::AbstractTracerSchema,
conv::AbstractVector{<:AbstractMessage}; kwargs...)
Expand Down
Loading
Loading