-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
160 additions
and
4 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,38 @@ | ||
### RENDERING | ||
function sharegpt_role(::AbstractMessage) | ||
throw(ArgumentError("Unsupported message type $(typeof(msg))")) | ||
end | ||
sharegpt_role(::AIMessage) = "gpt" | ||
sharegpt_role(::UserMessage) = "human" | ||
sharegpt_role(::SystemMessage) = "system" | ||
|
||
function render(::AbstractShareGPTSchema, conv::AbstractVector{<:AbstractMessage}) | ||
Dict("conversations" => [Dict("from" => sharegpt_role(msg), "value" => msg.content) | ||
for msg in conv]) | ||
end | ||
|
||
### AI Functions | ||
function aigenerate(prompt_schema::AbstractShareGPTSchema, prompt::ALLOWED_PROMPT_TYPE; | ||
kwargs...) | ||
error("ShareGPT schema does not support aigenerate. Please use OpenAISchema instead.") | ||
end | ||
function aiembed(prompt_schema::AbstractShareGPTSchema, prompt::ALLOWED_PROMPT_TYPE; | ||
kwargs...) | ||
error("ShareGPT schema does not support aiembed. Please use OpenAISchema instead.") | ||
end | ||
function aiclassify(prompt_schema::AbstractShareGPTSchema, prompt::ALLOWED_PROMPT_TYPE; | ||
kwargs...) | ||
error("ShareGPT schema does not support aiclassify. Please use OpenAISchema instead.") | ||
end | ||
function aiextract(prompt_schema::AbstractShareGPTSchema, prompt::ALLOWED_PROMPT_TYPE; | ||
kwargs...) | ||
error("ShareGPT schema does not support aiextract. Please use OpenAISchema instead.") | ||
end | ||
function aiscan(prompt_schema::AbstractShareGPTSchema, prompt::ALLOWED_PROMPT_TYPE; | ||
kwargs...) | ||
error("ShareGPT schema does not support aiscan. Please use OpenAISchema instead.") | ||
end | ||
function aiimage(prompt_schema::AbstractShareGPTSchema, prompt::ALLOWED_PROMPT_TYPE; | ||
kwargs...) | ||
error("ShareGPT schema does not support aiimage. Please use OpenAISchema instead.") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using PromptingTools: render, ShareGPTSchema | ||
using PromptingTools: AIMessage, SystemMessage, AbstractMessage | ||
using PromptingTools: UserMessage, UserMessageWithImages, DataMessage | ||
|
||
@testset "render-ShareGPT" begin | ||
schema = ShareGPTSchema() | ||
# Ignores any handlebar replacement, takes conversations as is | ||
messages = [ | ||
SystemMessage("Act as a helpful AI assistant"), | ||
UserMessage("Hello, my name is {{name}}"), | ||
AIMessage("Hello, my name is {{name}}") | ||
] | ||
expected_output = Dict("conversations" => [ | ||
Dict("value" => "Act as a helpful AI assistant", "from" => "system"), | ||
Dict("value" => "Hello, my name is {{name}}", "from" => "human"), | ||
Dict("value" => "Hello, my name is {{name}}", "from" => "gpt")]) | ||
conversation = render(schema, messages) | ||
@test conversation == expected_output | ||
|
||
# IT DOES NOT support any advanced message types (UserMessageWithImages, DataMessage) | ||
messages = [ | ||
UserMessage("Hello"), | ||
DataMessage(; content = ones(3, 3)) | ||
] | ||
|
||
@test_throws ArgumentError render(schema, messages) | ||
|
||
messages = [ | ||
SystemMessage("System message 1"), | ||
UserMessageWithImages("User message"; image_url = "https://example.com/image.png") | ||
] | ||
@test_throws ArgumentError render(schema, messages) | ||
end | ||
|
||
@testset "not implemented ai* functions" begin | ||
@test_throws ErrorException aigenerate(ShareGPTSchema(), "prompt") | ||
@test_throws ErrorException aiembed(ShareGPTSchema(), "prompt") | ||
@test_throws ErrorException aiextract(ShareGPTSchema(), "prompt") | ||
@test_throws ErrorException aiclassify(ShareGPTSchema(), "prompt") | ||
@test_throws ErrorException aiscan(ShareGPTSchema(), "prompt") | ||
@test_throws ErrorException aiimage(ShareGPTSchema(), "prompt") | ||
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