Functions/GenXdev.AI.Queries/Get-SimularMovieTitles.ps1
################################################################################ <# .SYNOPSIS Finds similar movie titles based on common properties. .DESCRIPTION Analyzes the provided movies to find common properties and returns a list of 10 similar movie titles. Uses AI to identify patterns and themes across the input movies to suggest relevant recommendations. .PARAMETER Movies Array of movie titles to analyze for similarities. .PARAMETER LLMQueryType The type of LLM query. .PARAMETER Model The model identifier or pattern to use for AI operations. .PARAMETER HuggingFaceIdentifier The LM Studio specific model identifier. .PARAMETER MaxToken The maximum number of tokens to use in AI operations. .PARAMETER Cpu The number of CPU cores to dedicate to AI operations. .PARAMETER Gpu How much to offload to the GPU. If 'off', GPU offloading is disabled. If 'max', all layers are offloaded to GPU. If a number between 0 and 1, that fraction of layers will be offloaded to the GPU. -1 = LM Studio will decide how much to offload to the GPU. -2 = Auto. .PARAMETER ApiEndpoint The API endpoint URL for AI operations. .PARAMETER ApiKey The API key for authenticated AI operations. .PARAMETER TimeoutSeconds The timeout in seconds for AI operations. .PARAMETER PreferencesDatabasePath Database path for preference data files. .PARAMETER Temperature Temperature for response randomness (0.0-1.0). .PARAMETER OpenInImdb Opens IMDB searches for each result in default browser. .PARAMETER ShowWindow Show the LM Studio window during processing. .PARAMETER Force Force stop LM Studio before initialization. .PARAMETER SessionOnly Use alternative settings stored in session for AI preferences. .PARAMETER ClearSession Clear alternative settings stored in session for AI preferences. .PARAMETER SkipSession Store settings only in persistent preferences without affecting session. .EXAMPLE Get-SimularMovieTitles -Movies "The Matrix","Inception" -OpenInImdb .EXAMPLE moremovietitles "The Matrix","Inception" -imdb #> function Get-SimularMovieTitles { [CmdletBinding()] param ( # [Parameter( Position = 0, Mandatory = $true, HelpMessage = 'Array of movie titles to analyze for similarities' )] [string[]]$Movies, # [Parameter( Position = 1, Mandatory = $false, HelpMessage = 'The type of LLM query' )] [ValidateSet( 'SimpleIntelligence', 'Knowledge', 'Pictures', 'TextTranslation', 'Coding', 'ToolUse' )] [string] $LLMQueryType = 'Knowledge', # [Parameter( Mandatory = $false, HelpMessage = 'The model identifier or pattern to use for AI operations' )] [string] $Model, # [Parameter( Mandatory = $false, HelpMessage = 'The LM Studio specific model identifier' )] [Alias('ModelLMSGetIdentifier')] [string] $HuggingFaceIdentifier, # [Parameter( Mandatory = $false, HelpMessage = 'The maximum number of tokens to use in AI operations' )] [int] $MaxToken, # [Parameter( Mandatory = $false, HelpMessage = 'The number of CPU cores to dedicate to AI operations' )] [int] $Cpu, # [Parameter( Mandatory = $false, HelpMessage = ("How much to offload to the GPU. If 'off', GPU " + "offloading is disabled. If 'max', all layers are " + 'offloaded to GPU. If a number between 0 and 1, ' + 'that fraction of layers will be offloaded to the ' + 'GPU. -1 = LM Studio will decide how much to ' + 'offload to the GPU. -2 = Auto') )] [ValidateRange(-2, 1)] [int]$Gpu = -1, # [Parameter( Mandatory = $false, HelpMessage = 'The API endpoint URL for AI operations' )] [string] $ApiEndpoint, # [Parameter( Mandatory = $false, HelpMessage = 'The API key for authenticated AI operations' )] [string] $ApiKey, # [Parameter( Mandatory = $false, HelpMessage = 'The timeout in seconds for AI operations' )] [int] $TimeoutSeconds, # [Parameter( Mandatory = $false, HelpMessage = 'Database path for preference data files' )] [Alias('DatabasePath')] [string] $PreferencesDatabasePath, # [Parameter( Mandatory = $false, HelpMessage = 'Temperature for response randomness (0.0-1.0)' )] [ValidateRange(0.0, 1.0)] [double] $Temperature = 0.2, # [Parameter( Mandatory = $false, HelpMessage = 'Opens IMDB searches for each result' )] [Alias('imdb')] [switch]$OpenInImdb, # [Parameter( Mandatory = $false, HelpMessage = 'Show the LM Studio window' )] [switch] $ShowWindow, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Language for IMDB search or browser session' )] [string] $Language, ############################################################################### [Alias('m','mon')] [Parameter( Mandatory = $false, HelpMessage = 'Monitor index or name for browser window placement' )] [string] $Monitor, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Width of the browser window in pixels' )] [int] $Width, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Height of the browser window in pixels' )] [int] $Height, ############################################################################### [Alias('lang','locale')] [Parameter( Mandatory = $false, HelpMessage = 'Accept-Language HTTP header for browser session' )] [string] $AcceptLang, ############################################################################### [Alias('incognito','inprivate')] [Parameter( Mandatory = $false, HelpMessage = 'Open browser in private/incognito mode' )] [switch] $Private, ############################################################################### [Alias('ch')] [Parameter( Mandatory = $false, HelpMessage = 'Use Google Chrome for browser session' )] [switch] $Chrome, ############################################################################### [Alias('c')] [Parameter( Mandatory = $false, HelpMessage = 'Use Chromium for browser session' )] [switch] $Chromium, ############################################################################### [Alias('ff')] [Parameter( Mandatory = $false, HelpMessage = 'Use Mozilla Firefox for browser session' )] [switch] $Firefox, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Left position of the browser window in pixels' )] [int] $Left, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Right position of the browser window in pixels' )] [int] $Right, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Bottom position of the browser window in pixels' )] [int] $Bottom, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Open browser window centered on screen' )] [switch] $Centered, ############################################################################### [Alias('fs','f')] [Parameter( Mandatory = $false, HelpMessage = 'Open browser in full screen mode' )] [switch] $FullScreen, ############################################################################### [Alias('a','app','appmode')] [Parameter( Mandatory = $false, HelpMessage = 'Open browser in application mode (minimal UI)' )] [switch] $ApplicationMode, ############################################################################### [Alias('de','ne','NoExtensions')] [Parameter( Mandatory = $false, HelpMessage = 'Disable browser extensions for session' )] [switch] $NoBrowserExtensions, ############################################################################### [Alias('allowpopups')] [Parameter( Mandatory = $false, HelpMessage = 'Disable popup blocker in browser session' )] [switch] $DisablePopupBlocker, ############################################################################### [Alias('fw','focus')] [Parameter( Mandatory = $false, HelpMessage = 'Focus the browser window after opening' )] [switch] $FocusWindow, ############################################################################### [Alias('fg')] [Parameter( Mandatory = $false, HelpMessage = 'Set browser window to foreground after opening' )] [switch] $SetForeground, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Maximize the browser window after opening' )] [switch] $Maximize, ############################################################################### [Alias('rf','bg')] [Parameter( Mandatory = $false, HelpMessage = 'Restore focus to previous window after closing browser' )] [switch] $RestoreFocus, ############################################################################### [Alias('nw','new')] [Parameter( Mandatory = $false, HelpMessage = 'Open each IMDB result in a new browser window' )] [switch] $NewWindow, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Return the URL after opening IMDB search' )] [switch] $ReturnURL, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Return only the URL without opening browser' )] [switch] $ReturnOnlyURL, ############################################################################### [Alias('Escape')] [Parameter( Mandatory = $false, HelpMessage = 'Send Escape key to browser after opening' )] [switch] $SendKeyEscape, ############################################################################### [Alias('HoldKeyboardFocus')] [Parameter( Mandatory = $false, HelpMessage = 'Hold keyboard focus in browser after sending keys' )] [switch] $SendKeyHoldKeyboardFocus, ############################################################################### [Alias('UseShiftEnter')] [Parameter( Mandatory = $false, HelpMessage = 'Use Shift+Enter when sending keys to browser' )] [switch] $SendKeyUseShiftEnter, ############################################################################### [Alias('DelayMilliSeconds')] [Parameter( Mandatory = $false, HelpMessage = 'Delay in milliseconds between sending keys to browser' )] [int] $SendKeyDelayMilliSeconds, ############################################################################### [Alias('nb')] [Parameter( Mandatory = $false, HelpMessage = 'Open browser window without borders' )] [switch] $NoBorders, ############################################################################### [Alias('sbs')] [Parameter( Mandatory = $false, HelpMessage = 'Open browser windows side by side for each result' )] [switch] $SideBySide, # [Parameter( Mandatory = $false, HelpMessage = 'Force stop LM Studio before initialization' )] [switch]$Force, # [Parameter( Mandatory = $false, HelpMessage = ('Use alternative settings stored in session for AI ' + 'preferences') )] [switch] $SessionOnly, # [Parameter( Mandatory = $false, HelpMessage = ('Clear alternative settings stored in session for AI ' + 'preferences') )] [switch] $ClearSession, # [Parameter( Mandatory = $false, HelpMessage = ('Store settings only in persistent preferences without ' + 'affecting session') )] [Alias('FromPreferences')] [switch] $SkipSession, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Instructions for the AI model on how to generate the string list' )] [string] $Instructions, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Array of file paths to attach' )] [string[]] $Attachments, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Image detail level for image processing.' )] [ValidateSet('low', 'medium', 'high')] [string] $ImageDetail, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Array of function definitions that can be called by the AI model during processing.' )] [hashtable[]] $Functions, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Array of PowerShell command definitions to use as tools that the AI can invoke.' )] [GenXdev.Helpers.ExposedCmdletDefinition[]] $ExposedCmdLets, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = "Array of command names that don't require confirmation before execution." )] [Alias('NoConfirmationFor')] [string[]] $NoConfirmationToolFunctionNames, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Temperature for audio generation.' )] [double] $AudioTemperature, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Temperature for response generation.' )] [double] $TemperatureResponse, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Number of CPU threads to use.' )] [int] $CpuThreads, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Regular expression to suppress certain outputs.' )] [string] $SuppressRegex, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Audio context size for processing.' )] [int] $AudioContextSize, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Silence threshold for audio processing.' )] [double] $SilenceThreshold, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Length penalty for sequence generation.' )] [double] $LengthPenalty, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Entropy threshold for output filtering.' )] [double] $EntropyThreshold, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Log probability threshold for output filtering.' )] [double] $LogProbThreshold, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'No speech threshold for audio detection.' )] [double] $NoSpeechThreshold, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Disable speech output.' )] [switch] $DontSpeak, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Disable thought speech output.' )] [switch] $DontSpeakThoughts, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Disable VOX (voice activation).' )] [switch] $NoVOX, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Use desktop audio capture.' )] [switch] $UseDesktopAudioCapture, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Disable context usage.' )] [switch] $NoContext, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Use beam search sampling strategy.' )] [switch] $WithBeamSearchSamplingStrategy, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Return only responses.' )] [switch] $OnlyResponses, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'When specified, copies the resulting string list back to the system clipboard after processing.' )] [switch] $SetClipboard, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = "Include model's thoughts in output" )] [switch] $IncludeThoughts, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = "Don't add model's thoughts to conversation history" )] [switch] $DontAddThoughtsToHistory, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Continue from last conversation' )] [switch] $ContinueLast, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Enable text-to-speech for AI responses' )] [switch] $Speak, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Enable text-to-speech for AI thought responses' )] [switch] $SpeakThoughts, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = "Don't store session in session cache" )] [switch] $NoSessionCaching, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Enable default tools for the AI model.' )] [switch] $AllowDefaultTools, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'The time-to-live in seconds for the AI operation.' )] [int] $TTLSeconds, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Return only markup blocks in the output.' )] [switch] $OutputMarkdownBlocksOnly, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Filter for specific types of markup blocks.' )] [string[]] $MarkupBlocksTypeFilter, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Do not initialize LM Studio.' )] [switch] $NoLMStudioInitialize, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Unload the model or session after completion.' )] [switch] $Unload, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Maximum callback length for tool calls.' )] [int] $MaxToolcallBackLength # ) ################################################################################ begin { # output verbose message about starting movie analysis Microsoft.PowerShell.Utility\Write-Verbose ( "Starting movie analysis for: $($Movies -join ', ')") # validate minimum number of movies required for comparison if ($Movies.Count -lt 2) { throw 'Please provide at least 2 movies for comparison' } # initialize empty array to store AI generated movie recommendations [string[]] $results = @() } ################################################################################ process { # construct the AI prompt for movie analysis with input movies listed $prompt = @" Analyze with high precision what the following movies have in common, and provide me a list of 10 more movie titles that have closest match based on the properties you found in your analyses. $(($Movies | Microsoft.PowerShell.Core\ForEach-Object { "- $_`r`n" })) "@ # output verbose message about parameter preparation Microsoft.PowerShell.Utility\Write-Verbose ( 'Preparing LLM invocation parameters') # copy matching parameters from current function to target function $invocationParams = GenXdev.Helpers\Copy-IdenticalParamValues ` -BoundParameters $PSBoundParameters ` -FunctionName 'GenXdev.AI\Invoke-LLMStringListEvaluation' # set the constructed prompt as the text parameter for AI evaluation $invocationParams.Text = $prompt # output verbose message about AI invocation Microsoft.PowerShell.Utility\Write-Verbose 'Invoking AI analysis' # invoke AI to get movie recommendations based on input analysis $results = GenXdev.AI\Invoke-LLMStringListEvaluation @invocationParams # open IMDB searches for results if requested by user if ($OpenInImdb) { # output verbose message about opening IMDB Microsoft.PowerShell.Utility\Write-Verbose 'Opening results in IMDB' # open IMDB query for each recommended movie title Open-IMDBQuery -Query $results } } ################################################################################ end { # output the final array of recommended movie titles Microsoft.PowerShell.Utility\Write-Output $results } } ################################################################################ |