@@ -34,19 +34,16 @@ $catalogues["catalog"]["tags"] = Get-CatalogHashtable -Classification "tags"
34
34
$catalogues [" catalog_full" ] = $catalogues [" catalog" ][" categories" ] + $catalogues [" catalog" ][" tags" ]
35
35
$catalogues [" marketing" ] = Get-CatalogHashtable - Classification " marketing"
36
36
37
- function Get-CategoryConfidenceWithChecksum {
37
+ function Get-ClassificationsForType {
38
38
param (
39
- [string ]$ResourceContent ,
40
- [string ]$ResourceTitle ,
41
- [string ]$CacheFolder ,
39
+ [Parameter (Mandatory = $true )]
40
+ [HugoMarkdown ]$hugoMarkdown ,
42
41
[string ]$ClassificationType = " classification" ,
43
42
[switch ]$batch ,
44
43
[switch ]$updateMissing
45
44
)
46
45
47
- if (! (Test-Path $CacheFolder )) {
48
- New-Item - ItemType Directory - Path $CacheFolder - Force | Out-Null
49
- }
46
+ $CacheFolder = $hugoMarkdown.FolderPath
50
47
51
48
$batchFile = Join-Path $CacheFolder " data.index.classifications.$ClassificationType .batch"
52
49
$batchJsonlOutout = Join-Path $CacheFolder " data.index.classifications.$ClassificationType -output.jsonl"
@@ -156,7 +153,7 @@ function Get-CategoryConfidenceWithChecksum {
156
153
Write-ErrorLog " Error parsing AI response for $CacheFolder . Skipping."
157
154
continue
158
155
}
159
- $newEntry = Get-ConfidenceFromAIResponse - AIResponseJson $aiResponseJson - ResourceTitle $ResourceTitle - ResourceContent $ResourceContent
156
+ $newEntry = Get-ConfidenceFromAIResponse - AIResponseJson $aiResponseJson - ResourceTitle $hugoMarkdown .FrontMatter.title - ResourceContent $hugoMarkdown .BodyContent
160
157
if ($cachedData.ContainsKey ($newEntry.category )) {
161
158
$oldEntry = $cachedData .($newEntry.category )
162
159
if ([System.DateTimeOffset ]$oldEntry.calculated_at -gt $newEntry.calculated_at ) {
@@ -267,8 +264,8 @@ function Get-CategoryConfidenceWithChecksum {
267
264
268
265
do not wrap the json in anything else, just return the json object.
269
266
270
- **Content Title:** "$ResourceTitle "
271
- **Content:** "$ResourceContent "
267
+ **Content Title:** "$ ( $hugoMarkdown .FrontMatter.Title ) "
268
+ **Content:** "$ ( $hugoMarkdown .BodyContent ) "
272
269
"@
273
270
$prompts += $prompt
274
271
}
@@ -299,17 +296,12 @@ function Get-CategoryConfidenceWithChecksum {
299
296
# Write-Progress -Id 2 -Activity "Classification of $ClassificationType" -Status "Processing prompt [$count/$($prompts.count)]" -PercentComplete (($count / $prompts.count) * 100)
300
297
# Calls processing
301
298
$aiResponseJson = Get-OpenAIResponse - Prompt $prompt
302
- $result = Get-ConfidenceFromAIResponse - AIResponseJson $aiResponseJson - ResourceTitle $ResourceTitle - ResourceContent $ResourceContent
299
+ $result = Get-ConfidenceFromAIResponse - AIResponseJson $aiResponseJson - hugoMarkdown $hugoMarkdown
303
300
if ($result.reasoning -ne $null -and $result.category -ne " unknown" ) {
304
301
$oldConfidence = $cachedData [$result.category ]? .ai_confidence ?? 0
305
- $DaysAgo = if ($cachedData [$result.category ]? .calculated_at -is [DateTime ]) {
306
- [math ]::Round(([DateTimeOffset ]::Now - [DateTimeOffset ]$cachedData [$result.category ].calculated_at).TotalDays)
307
- }
308
- else {
309
- 0
310
- }
311
-
312
- Write-InformationLog " Updating {category} with confidence of {old} calculated {daysago} to new confidence of {confidence} " - PropertyValues $result.category , $oldConfidence , $DaysAgo , $result.ai_confidence
302
+ $DaysAgo = [math ]::Round(([DateTimeOffset ]::Now - [DateTimeOffset ]$cachedData [$result.category ].calculated_at).TotalDays)
303
+ $confidenceDiff = " {0}{1}" -f ($ (if (($result.ai_confidence - $oldConfidence ) -ge 0 ) { ' +' } else { ' -' }), [math ]::Abs($result.ai_confidence - $oldConfidence ))
304
+ Write-InformationLog " Updating {category} confidence {diff}! The old confidence of {old} was calculated {daysago} days ago. The new confidence is {confidence}!" - PropertyValues $result.category , $confidenceDiff , $oldConfidence , $DaysAgo , $result.ai_confidence
313
305
$CatalogFromCache [$result.category ] = $result
314
306
$cachedData [$result.category ] = $result
315
307
# Save cache after each API call
@@ -328,17 +320,13 @@ function Get-CategoryConfidenceWithChecksum {
328
320
# ==========================================
329
321
# =================return===================
330
322
# ==========================================
331
- $finalSelection = Get-FinalSelection - categoryScores $CatalogFromCache
332
- return $finalSelection | Sort-Object final_score - Descending | ConvertTo-Json - Depth 2
323
+ return $CatalogFromCache.Values | Sort-Object final_score - Descending
333
324
# ==========================================
334
325
# ================/return===================
335
326
# ==========================================
336
-
337
-
338
-
339
327
}
340
328
341
- function Get-ClassificationFromCache {
329
+ function Get-Classification {
342
330
param (
343
331
[string ]$CacheFolder ,
344
332
[string ]$ClassificationName
@@ -357,27 +345,31 @@ function Get-ClassificationFromCache {
357
345
Return $cachedData .$ClassificationName
358
346
}
359
347
360
- function Get-FinalSelection {
348
+ function Get-ClassificationOrderedList {
361
349
param (
362
- [hashtable ]$categoryScores ,
363
- [string []]$levels = @ (" Primary" , " Secondary" , " Tertiary" , " Quaternary" , " Quinary" )
350
+ [array ]$Classifications ,
351
+ [int ] $minScore = 30 ,
352
+ [string []]$levels = @ (" Primary" , " Secondary" , " Tertiary" , " Quaternary" , " Quinary" ),
353
+ [switch ]$byLevel
364
354
)
365
-
366
- $finalSelection = @ ()
367
355
368
- foreach ($level in $levels ) {
369
- $currentSelection = $categoryScores.Values | Where-Object { $_.final_score -gt 30 -and $_.level -eq $level } | Sort-Object final_score - Descending
370
- if ($currentSelection.Count -gt 0 ) {
371
- $finalSelection += $currentSelection
372
- break
373
- }
356
+ $filtered = $Classifications | Where-Object { $_.final_score -gt $minScore }
357
+ $selected = @ ()
358
+ if ($byLevel ) {
359
+ foreach ($level in $levels ) {
360
+ $currentSelection = $filtered | Where-Object { $_.level -eq $level } | Sort-Object final_score - Descending
361
+ if ($currentSelection.Count -gt 0 ) {
362
+ $selected += $currentSelection
363
+ break
364
+ }
365
+ }
374
366
}
375
-
376
- return $finalSelection | Sort-Object final_score - Descending
367
+ else {
368
+ $selected = $filtered | Sort-Object final_score - Descending
369
+ }
370
+ return $selected | Sort-Object - Property @ {Expression = " final_score" ; Descending = $true }, @ {Expression = " ai_alignment" ; Descending = $true }, @ {Expression = " ai_depth" ; Descending = $true }, @ {Expression = " category" ; Descending = $false }
377
371
}
378
372
379
-
380
-
381
373
function Get-ComputedConfidence {
382
374
param (
383
375
[int ]$aiConfidence ,
@@ -402,9 +394,9 @@ function Get-ComputedLevel {
402
394
403
395
function Get-ConfidenceFromAIResponse {
404
396
param (
405
- [string ] $AIResponseJson ,
406
- [string ] $ResourceTitle ,
407
- [string ]$ResourceContent
397
+ [Parameter ( Mandatory = $true )]
398
+ [HugoMarkdown ] $hugoMarkdown ,
399
+ [string ]$AIResponseJson
408
400
)
409
401
$responceOK = $true
410
402
try {
@@ -448,7 +440,7 @@ function Get-ConfidenceFromAIResponse {
448
440
# Non-AI Confidence Calculation
449
441
$nonAiConfidence = 0
450
442
$categoryWords = $category -split ' \s+'
451
- $contentWords = ($ResourceTitle + " " + $ResourceContent ) -split ' \s+'
443
+ $contentWords = ($hugoMarkdown .FrontMatter.title + " " + $hugoMarkdown .BodyContent ) -split ' \s+'
452
444
$escapedCategory = [Regex ]::Escape($category )
453
445
454
446
if ($category -in $contentWords ) {
0 commit comments