Skip to content

Commit

Permalink
Merge pull request #5 from kurokobo/chat
Browse files Browse the repository at this point in the history
fix: allow multibyte characters in all cmdlets
  • Loading branch information
kurokobo authored Jan 10, 2025
2 parents de69f38 + 6cc70b6 commit b8a6006
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion PSDify.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'PSDify.psm1'
ModuleVersion = '0.3.0'
ModuleVersion = '0.3.1'
CompatiblePSEditions = @('Core', 'Desktop')
GUID = 'b791c4c0-ed46-4561-8713-5d4242e6bac7'
Author = 'kurokobo'
Expand Down
14 changes: 7 additions & 7 deletions Public/Import-DifyApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function Import-DifyApp {
if ([System.Version]$SimplifiedVersion -lt [System.Version]"0.12.0") {
$Endpoint = Join-Url -Segments @($env:PSDIFY_URL, "/console/api/apps/import")
$Method = "POST"
$Body = $UTF8NoBOM.GetBytes((@{
"data" = $RawContent
} | ConvertTo-Json))
$Body = @{
"data" = $RawContent
} | ConvertTo-Json
try {
$Response = Invoke-DifyRestMethod -Uri $Endpoint -Method $Method -Body $Body -Token $env:PSDIFY_CONSOLE_TOKEN
}
Expand Down Expand Up @@ -85,10 +85,10 @@ function Import-DifyApp {
else {
$Endpoint = Join-Url -Segments @($env:PSDIFY_URL, "/console/api/apps/imports")
$Method = "POST"
$Body = $UTF8NoBOM.GetBytes((@{
"mode" = "yaml-content"
"yaml_content" = $RawContent
} | ConvertTo-Json))
$Body = @{
"mode" = "yaml-content"
"yaml_content" = $RawContent
} | ConvertTo-Json
try {
$Response = Invoke-DifyRestMethod -Uri $Endpoint -Method $Method -Body $Body -Token $env:PSDIFY_CONSOLE_TOKEN
}
Expand Down
5 changes: 3 additions & 2 deletions Public/Invoke-DifyRestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function Invoke-DifyRestMethod {
[String] $Uri,
[String] $Method = "GET",
[String] $ContentType = "application/json",
[Object] $Body = $null,
[String] $Body = $null,
[Hashtable] $Query = $null,
[String] $Token = $null,
[Microsoft.PowerShell.Commands.WebRequestSession] $Session = $null,
Expand Down Expand Up @@ -37,7 +37,8 @@ function Invoke-DifyRestMethod {
}
if (@("POST", "PUT", "PATCH", "DELETE") -contains $Method) {
if ($Body) {
$RestMethodParams.Body = $Body
$UTF8NoBOM = New-Object "System.Text.UTF8Encoding" -ArgumentList @($false)
$RestMethodParams.Body = $UTF8NoBOM.GetBytes($Body)
}
if ($InFile) {
$RestMethodParams.InFile = $InFile
Expand Down
8 changes: 7 additions & 1 deletion Tests/Integration/52_Send-DifyChatMessage.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.6" }
#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.6" }

BeforeDiscovery {
$PesterPhase = "BeforeDiscovery"
Expand Down Expand Up @@ -61,6 +61,12 @@ Describe "Send-DifyChatMessage" -Tag "chat" {

Assert-MockCalled -ModuleName PSDify -CommandName Write-Host -ParameterFilter { $Object -like "*Pong*" }
}
It "should send messages without knowledge with multibyte characters" {
$env:PSDIFY_APP_TOKEN = $TestAppWithoutKnowledgeAPIKey.Token
Send-DifyChatMessage -NewSession -Message "日本語で朝の挨拶は? ひらがなで。"

Assert-MockCalled -ModuleName PSDify -CommandName Write-Host -ParameterFilter { $Object -like "*おはよ*" }
}
It "should send messages with knowledge" {
$env:PSDIFY_APP_TOKEN = $TestAppWithKnowledgeAPIKey.Token
Send-DifyChatMessage -NewSession -Message "What is the vegetable that is deep ruby red in color ?"
Expand Down

0 comments on commit b8a6006

Please sign in to comment.