@@ -130,8 +130,7 @@ function Get-LMStudioTextEmbedding {
130130 HelpMessage = ' Text to get embeddings for' ,
131131 ValueFromPipeline = $true
132132 )]
133- [ValidateNotNullOrEmpty ()]
134- [string []]$Text ,
133+ [object ] $InputObject ,
135134 # #######################################################################
136135 [Parameter (
137136 Mandatory = $false ,
@@ -434,40 +433,45 @@ function Get-LMStudioTextEmbedding {
434433
435434 process {
436435
437- # write verbose message about processing text items
438- Microsoft.PowerShell. Utility\Write-Verbose ( ' Processing embeddings ' +
439- " request for $ ( $Text .Length ) text items " )
436+ $InputObject | ForEach-Object - ErrorAction SilentlyContinue {
437+ $text = " $PSItem " ;
438+ if ([ string ]::IsNullOrWhiteSpace( $text )) { return }
440439
441- # create api request payload with model and input text
442- $payload = @ {
443- model = $Model
444- input = $Text
445- }
440+ # write verbose message about processing text items
441+ Microsoft.PowerShell.Utility\Write-Verbose (' Processing embeddings ' +
442+ " request for $ ( $Text.Length ) text items" )
443+
444+ # create api request payload with model and input text
445+ $payload = @ {
446+ model = $Model
447+ input = $Text
448+ }
446449
447- # convert payload to compressed json with deep nesting support
448- $json = $payload |
449- Microsoft.PowerShell.Utility\ConvertTo-Json - Depth 60 - Compress
450-
451- # encode json string to utf8 bytes for api transmission
452- $bytes = [System.Text.Encoding ]::UTF8.GetBytes($json )
453-
454- # invoke embeddings api with extended timeout for large requests
455- $response = Microsoft.PowerShell.Utility\Invoke-RestMethod `
456- - Uri $apiUrl `
457- - Method Post `
458- - Body $bytes `
459- - Headers $headers `
460- - OperationTimeoutSeconds (3600 * 24 ) `
461- - ConnectionTimeoutSeconds (3600 * 24 )
462-
463- # process each embedding result and create output objects
464- foreach ($embedding in $response.data ) {
465-
466- # create custom object with embedding data and context
467- [PSCustomObject ]@ {
468- embedding = $embedding.embedding
469- index = $embedding.index
470- text = $Text [$embedding.index ]
450+ # convert payload to compressed json with deep nesting support
451+ $json = $payload |
452+ Microsoft.PowerShell.Utility\ConvertTo-Json - Depth 60 - Compress
453+
454+ # encode json string to utf8 bytes for api transmission
455+ $bytes = [System.Text.Encoding ]::UTF8.GetBytes($json )
456+
457+ # invoke embeddings api with extended timeout for large requests
458+ $response = Microsoft.PowerShell.Utility\Invoke-RestMethod `
459+ - Uri $apiUrl `
460+ - Method Post `
461+ - Body $bytes `
462+ - Headers $headers `
463+ - OperationTimeoutSeconds (3600 * 24 ) `
464+ - ConnectionTimeoutSeconds (3600 * 24 )
465+
466+ # process each embedding result and create output objects
467+ foreach ($embedding in $response.data ) {
468+
469+ # create custom object with embedding data and context
470+ [PSCustomObject ]@ {
471+ embedding = $embedding.embedding
472+ index = $embedding.index
473+ text = $Text [$embedding.index ]
474+ }
471475 }
472476 }
473477 }
0 commit comments