Skip to content

Commit

Permalink
Enhacements of JSON support. Related to issue #20
Browse files Browse the repository at this point in the history
  • Loading branch information
rrg92 committed Oct 1, 2024
1 parent 30a23e5 commit 6c0af1d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions powershai/powershai.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ function Get-AiChat {
,#Formato da resposta
#Os formatos aceitáveis, e comportamento, devem seguir o mesmo da OpenAI: https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format
#Atalhos:
# "json", equivale a {"type": "json_object"}
# "json"|"json_object", equivale a {"type": "json_object"}
$ResponseFormat = $null

,#Lista de tools que devem ser invocadas!
Expand Down Expand Up @@ -888,8 +888,8 @@ function Get-AiChat {
$Provider = Get-AiCurrentProvider
$FuncParams = $PsBoundParameters;

if($ResponseFormat -eq "json"){
$ResponseFormat = @{type = "json_object"}
if($ResponseFormat -in "json","json_object"){
$FuncParams.ResponseFormat = @{type = "json_object"}
}

if(!$model){
Expand Down
8 changes: 8 additions & 0 deletions powershai/providers/google.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ function Invoke-GoogleGenerateContent {
#Note que reaproveitamos o convert to openai message do provider!
$GoogleContent = @(ConvertTo-GoogleContentMessage $messages)

$Config = @{}

if($ResponseFormat.type -eq "json_object"){
$Config.responseMimeType = "application/json"
}

$Data = @{
contents = $GoogleContent.content
#tools = @()
Expand All @@ -170,6 +176,8 @@ function Invoke-GoogleGenerateContent {
@{text = $GoogleContent.SystemMessage }
)
}

generationConfig = $Config
}

$ReqParams = @{
Expand Down
11 changes: 11 additions & 0 deletions util/TestPowershai.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ try {
}

write-host " TEMPORARY TEST PASSED";


# Json test!
$ExpectedA = Get-Random -Min 1 -Max 100;
$ExpectedB = [Guid]::NewGuid().Guid;
$prompt = @(
"Return an array with 5 objects"
"Each object must contains two props: a and b. a must contain value $ExpectedA, b must contains value $ExpectedB"
)
$JsonResult = @(iat -Json -Lines $prompt);
write-host "JsonOutput:`n$JsonResult";
}

} catch {
Expand Down

0 comments on commit 6c0af1d

Please sign in to comment.