Skip to content

Commit 0121420

Browse files
committed
Feature: Report GPT token 'risk'.
It gets redder the closer to the typical GPT token limit (128,000).
1 parent 524d271 commit 0121420

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

CodeIngest.Desktop/MainViewModel.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,15 @@ public long? PreviewFileSize
153153
get => m_previewFileSize;
154154
set
155155
{
156-
if (SetField(ref m_previewFileSize, value))
157-
OnPropertyChanged(nameof(PreviewTokenCount));
156+
if (!SetField(ref m_previewFileSize, value))
157+
return;
158+
OnPropertyChanged(nameof(PreviewTokenCount));
159+
OnPropertyChanged(nameof(PreviewTokenRisk));
158160
}
159161
}
160162

161163
public int PreviewTokenCount => (int)((PreviewFileSize ?? 0) / 3.8);
164+
public double PreviewTokenRisk => (double)PreviewTokenCount / 128_000;
162165

163166
public bool IsGeneratingPreview
164167
{
@@ -179,7 +182,7 @@ public MainViewModel(IDialogService dialogService = null)
179182
{
180183
m_dialogService = dialogService ?? DialogService.Instance;
181184

182-
m_folderSelectionConsolidator = new ActionConsolidator(RefreshPredictedSize, 2.0);
185+
m_folderSelectionConsolidator = new ActionConsolidator(() => _ = RefreshPredictedSizeAsync(), 2.0);
183186
Root = new FolderTreeRoot(Settings.Instance.RootFolder);
184187
}
185188

@@ -257,7 +260,7 @@ private void InvalidatePreviewStats()
257260
m_folderSelectionConsolidator.Invoke();
258261
}
259262

260-
private void RefreshPredictedSize()
263+
private async Task RefreshPredictedSizeAsync()
261264
{
262265
try
263266
{
@@ -282,7 +285,7 @@ private void RefreshPredictedSize()
282285
var ingester = new Ingester(options);
283286
m_backgroundRefreshProgress = new ProgressToken(isCancelSupported: true);
284287

285-
Task.Run(() =>
288+
await Task.Run(() =>
286289
{
287290
var result = ingester.Run(selectedFolders, progress: m_backgroundRefreshProgress);
288291
if (!result.HasValue || m_backgroundRefreshProgress.CancelRequested)

CodeIngest.Desktop/Views/App.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<Application.Resources>
3131
<converters:BytesToUiStringConverter x:Key="BytesToUiStringConverter" />
32+
<converters:RiskToBrushConverter x:Key="RiskToBrushConverter" />
3233
</Application.Resources>
3334

3435
<NativeMenu.Menu>

CodeIngest.Desktop/Views/MainWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
IsVisible="{Binding PreviewFileSize, Converter={x:Static ObjectConverters.IsNull}}" />
7171
<StackPanel Grid.Column="4" Grid.Row="0" Orientation="Horizontal"
7272
IsVisible="{Binding PreviewFileSize, Converter={x:Static ObjectConverters.IsNotNull}}">
73-
<TextBlock Text="{Binding PreviewTokenCount, StringFormat=N0}"/>
73+
<TextBlock Text="{Binding PreviewTokenCount, StringFormat=N0}" Foreground="{Binding PreviewTokenRisk, Converter={StaticResource RiskToBrushConverter}}"/>
7474
<TextBlock Text="tokens"/>
7575
</StackPanel>
7676

CodeIngestLib/Ingester.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Linq;
1515
using System.Text;
1616
using CSharp.Core;
17+
using CSharp.Core.Extensions;
1718

1819
namespace CodeIngestLib;
1920

@@ -35,13 +36,13 @@ public Ingester(IngestOptions options)
3536
{
3637
var didError = false;
3738
var sourceFiles = directories
38-
.Where(d => d.Exists)
39+
.Where(d => d.Exists() && d.IsAccessible())
3940
.AsParallel()
4041
.SelectMany(d => m_options.FilePatterns.SelectMany(p =>
4142
{
4243
try
4344
{
44-
return d.GetFiles(p, SearchOption.AllDirectories);
45+
return d.TryGetFiles(p, SearchOption.AllDirectories);
4546
}
4647
catch (Exception ex)
4748
{

DTC.Core

0 commit comments

Comments
 (0)