Skip to content

Commit

Permalink
Template file parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
svilupp committed May 22, 2024
1 parent 119fa52 commit af8b238
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [0.26.2]

### Fixed
- Fixed a rare bug where prompt templates created on MacOS will come with metadata that breaks the prompt loader. From now on, it ignores any dotfiles (hidden files starting with ".").

## [0.26.1]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PromptingTools"
uuid = "670122d1-24a8-4d70-bfce-740807c42192"
authors = ["J S @svilupp and contributors"]
version = "0.26.1"
version = "0.26.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
2 changes: 1 addition & 1 deletion src/templates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function load_templates!(dir_templates::Union{String, Nothing} = nothing;
for template_path in load_paths
for (root, dirs, files) in walkdir(template_path)
for file in files
if endswith(file, ".json")
if endswith(file, ".json") && !startswith(file, ".")
template_name = Symbol(split(basename(file), ".")[begin])
template, metadata_msgs = load_template(joinpath(root, file))
# add to store
Expand Down
23 changes: 22 additions & 1 deletion test/templates.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using PromptingTools: AbstractChatMessage, SystemMessage, UserMessage, MetadataMessage
using PromptingTools: render
using PromptingTools: load_templates!, aitemplates, create_template
using PromptingTools: load_templates!, aitemplates, create_template, AITemplateMetadata,
save_conversation
using PromptingTools: TestEchoOpenAISchema

@testset "Template rendering" begin
Expand Down Expand Up @@ -76,6 +77,26 @@ end
filter!(x -> x.name != :PirateGreetingX, PT.TEMPLATE_METADATA)
end

@testset "load_templates!-filtering" begin
tpl = create_template(; system = "a", user = "b")
mktempdir() do dir
## File to be visible
fn = joinpath(dir, "x1.json")
save_conversation(fn, tpl)

## File to be invisible
fn = joinpath(dir, "._x2.json")
save_conversation(fn, tpl)

store = Dict{Symbol, Any}()
PT.load_templates!(dir;
remember_path = false, store,
metadata_store = Vector{AITemplateMetadata}())
@test length(store) == 1
@test haskey(store, :x1)
end
end

@testset "Templates - Echo aigenerate call" begin
# E2E test for aigenerate with rendering template and filling the placeholders
template_name = :JudgeIsItTrue
Expand Down

2 comments on commit af8b238

@svilupp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Fixed

  • Fixed a rare bug where prompt templates created on MacOS will come with metadata that breaks the prompt loader. From now on, it ignores any dotfiles (hidden files starting with ".").

Commits

@JuliaRegistrator
Copy link

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/107382

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:

git tag -a v0.26.2 -m "<description of version>" af8b238ac7736de391e5f9d398cabd79cdd37929
git push origin v0.26.2

Please sign in to comment.