Skip to content

Commit

Permalink
Minor fixes and enhacements to match docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rrg92 committed Sep 13, 2024
1 parent 3da06a2 commit 3f71837
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 47 deletions.
71 changes: 43 additions & 28 deletions doc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ $LangDirs = $SupportedLangs | %{
New-Item -ItemType Directory -Path $DirPath
}

$Utf8Bom = New-Object System.Text.UTF8Encoding $true

Function ParseFile($Source,$Target,$Vars){


Expand Down Expand Up @@ -263,13 +265,16 @@ Function ParseFile($Source,$Target,$Vars){
throw $Ex;
}

$NewLines | Set-Content -Path $Target -Encoding UTF8
[System.IO.File]::WriteAllLines($Target,$NewLines,$Utf8Bom)
#$NewLines, | Set-Content -Path $Target -Encoding
}



write-host "Loading file list";
$AllMarkDowns = gci -rec (JoinPath $DocsDir *.md);
write-host "Loading file list: $DocsDir";
$SrcLangDirs = $SupportedLangs | %{JoinPath $DocsDir $_ *.md}
write-host " Dirs: $SrcLangDirs"
$AllMarkDowns = gci -rec $SrcLangDirs;
foreach($MdFile in $AllMarkDowns){

$Vars = @{}
Expand Down Expand Up @@ -298,14 +303,9 @@ foreach($MdFile in $AllMarkDowns){
$LangDir = JoinPath $TempDir $Lang;

# Is cmdlet help file!
if($FileName -match '([\w-]+)\.cmdlet\.md$'){
if($FileName -match '([\w-]+)\.cmdlet\.md$' -or $FileName -match 'cmdlets/([\w-]+).md'){
$CmdLetName = $matches[1];

if($CmdLetName -NotLike '*-*'){
write-host " NotSupported: Must be in format Verb-Noun.cmdlet.md"
continue;
}


$NewFileName = $matches[1] + '.md';

$Vars.FileName = $MdFile.name;
Expand All @@ -318,21 +318,15 @@ foreach($MdFile in $AllMarkDowns){
continue;
}

if($FileName -match '^providers/(.*?)/(.*)'){
$ProviderName = $matches[1];
$Topic += "_" + $ProviderName;
$FileName = $matches[2];
}

if($FileName -match '((.*?)/)?(.*?)\.md'){
if($matches[1]){
$Topic += "_" + $Matches[2].replace("/","_")
}

$BaseName = $matches[3];

if($BaseName -like '*.about'){
$Topic += "_" + ($BaseName -replace 'about$','')
if($BaseName -like '*.about' -or $BaseName -eq "README"){
$Topic += "_" + ($BaseName -replace '\.about$','')
} elseif($BaseName -ne 'README') {
write-host " MdFileNotSupported: leftname=$fileName"
continue;
Expand All @@ -356,18 +350,39 @@ write-host "== Start compilation... =="

write-host " Out: $OutDir";

$Progress = @()

foreach($Lang in $LangDirs){
write-host "Compiling:" $Lang.FullName;

$OutPath = JoinPath $OutDir $Lang.name;

write-host " Generating help files to $OutPath";
$null = New-ExternalHelp -Path $Lang.FullName -OutputPath $OutPath;

$LangName = $Lang.name
write-host "Compiling:" $LangName


$ModuleLangDir = JoinPath "$PsScriptRoot" "powershai" $Lang.name
write-host " Copying back to docs: $ModuleLangDir"
gci $OutPath | copy-item -Recurse -Destination $ModuleLangDir;
try {
$OutPath = JoinPath $OutDir $LangName;
$ErrorFile = JoinPath $OutDir "$LangName-Errors.json";

write-host " Generating help files to $OutPath";
#$FileList = gci -rec (JoinPath $Lang.FullName *.md)
$null = New-ExternalHelp -force -Path $Lang.FullName-OutputPath $OutPath -Encoding $Utf8Bom -ErrorLogFile $ErrorFile -EA Continue;



$ModuleLangDir = JoinPath "$PsScriptRoot" "powershai" $LangName

if(Test-Path $ModuleLangDir){
write-host " Cleaning target dir: $ModuleLangDir";
gci (JoinPath $ModuleLangDir *) | remove-item -force -recurse;
}

write-host " Copying back to docs: $ModuleLangDir"
gci $OutPath | copy-item -Recurse -Destination $ModuleLangDir;
} catch {
write-warning "LANG ERROR: $LangName, Summary = $_";
$ErrorActionPreference = "Continue";
write-error -Exception $_.Exception
write-host $_.ScriptStackTrace
$ErrorActionPreference = "Stop";
}
}


Expand Down
12 changes: 12 additions & 0 deletions powershai/lib/PowershaiHelp.tools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Function GetHelpAbout {
<#
.DESCRIPTION
Obtém help sobre um comando ou tópico específico!s
#>
param(
#TOpico ou comando
$Assunto
)

Get-help -Full $assunto;
}
4 changes: 2 additions & 2 deletions powershai/providers/claude.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ function claude_Chat {
#
#}

if($ResponseFormat -eq "json_object"){
throw "POWERSHAI_CLAUDE_JSON_NOTSUPPORTED: Json mode not supported yet!"
if($ResponseFormat){
throw "POWERSHAI_CLAUDE_FORMAT_NOTSUPPORTED: ResponseFormat not suppoted yet!"
}


Expand Down
4 changes: 2 additions & 2 deletions powershai/providers/maritalk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function Get-MaritalkChat {
}

if($ResponseFormat){
$Body.response_format = @{type = $ResponseFormat}
$Body.response_format = $ResponseFormat
}

#if($Functions){
Expand Down Expand Up @@ -369,7 +369,7 @@ function maritalk_Chat {


$ResultText = $result.answer;
if($ResponseFormat -eq "json_object"){
if($ResponseFormat.type -eq "json_object"){
if($ResultText -match '(?s)```json(.*?)```'){
$ResultText = $matches[1];
} else {
Expand Down
37 changes: 22 additions & 15 deletions powershai/providers/openai.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function Get-OpenaiChat {
}

if($ResponseFormat){
$Body.response_format = @{type = $ResponseFormat}
$Body.response_format = $ResponseFormat
}

if($Functions){
Expand Down Expand Up @@ -668,6 +668,7 @@ function Get-OpenaiToolFromCommand {

foreach($function in $functions){


$Command = Get-Command -EA SilentlyContinue $function;


Expand Down Expand Up @@ -947,12 +948,12 @@ function NewAiInteraction {



# Obtéms os embegginds de um texto
function OpenaiEmbeddings {
# Invoca a api para ober os mebddings
function Get-OpenaiEmbeddings {
param($inputText,$model)

if(!$model){
$model = 'text-embedding-ada-002'
$model = 'text-embedding-3-small'
}

$body = @{
Expand All @@ -966,24 +967,30 @@ function OpenaiEmbeddings {
<#
Gera o embedding de um texto!
#>
function Invoke-OpenaiEmbedding {
function Get-OpenaiEmbeddings {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
$text
,$model
)

$ans = OpenaiEmbeddings -input $text -model $model
$costs = Get-OpenAiAnswerCost $ans

[object[]]$AllEmbeddings = @($null) * $ans.data.length;

$ans.data | %{ $AllEmbeddings[$_.index] = $_.embedding }
process {

return @{
rawAnswer = $ans
costs = $costs
embeddings = $AllEmbeddings
$ans = Invoke-OpenaiEmbeddings -input $text -model $model
$costs = Get-OpenAiAnswerCost $ans

[object[]]$AllEmbeddings = @($null) * $ans.data.length;

$ans.data | %{ $AllEmbeddings[$_.index] = $_.embedding }

return [PsCustomObject]@{
rawAnswer = $ans
costs = $costs
embeddings = $AllEmbeddings
text = $text
}

}
}

Expand Down

0 comments on commit 3f71837

Please sign in to comment.