Skip to content

Commit

Permalink
Enhanced token usage tracking and UI updates
Browse files Browse the repository at this point in the history
- Enhanced `TokenUsageData` to include direct tracking of the last request model name, improving performance and reliability. This includes adding a new private string `_lastRequestModelName`, modifying the `LastRequestModelName` property, and updating the `AddTokenUsage` method for direct assignment and UI notification.
- Updated the default model in `IntelliChatModuleSettings` to `gpt4_turbo` for text completion, reflecting a shift towards more advanced AI capabilities.
- Made several UI text adjustments for clarity and conciseness, including updates to system messages and prompt messages for features like text completion and next word prediction.
- Introduced UI enhancements such as a new dropdown for selecting the "Next word prediction OpenAI Model" in `MainWindow.xaml`, and adjusted the visibility of certain UI elements to streamline the interface.
- Adjusted functionality in `MainWindow.xaml.cs` by modifying the `NextwordPredict_Click` event handler to alter feature behavior, likely affecting completion and prediction modes.
  • Loading branch information
BoiHanny committed Apr 30, 2024
1 parent dcd2899 commit 0272cc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 7 additions & 4 deletions vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public DailyTokenUsage()
public class TokenUsageData : ObservableObject
{
private int _lastRequestTotalTokens;
private string _lastRequestModelName;

public TokenUsageData()
{
Expand All @@ -111,7 +112,7 @@ public TokenUsageData()
public int LastRequestTotalTokens => _lastRequestTotalTokens;

// Expose the last request's model name
public string LastRequestModelName => DailyUsages.LastOrDefault()?.ModelUsages.LastOrDefault()?.ModelName;
public string LastRequestModelName => _lastRequestModelName;

public void AddTokenUsage(string modelName, int promptTokens, int completionTokens)
{
Expand All @@ -136,11 +137,13 @@ public void AddTokenUsage(string modelName, int promptTokens, int completionToke

// Update the last request total tokens
_lastRequestTotalTokens = promptTokens + completionTokens;
_lastRequestModelName = modelName;

// Notify UI about changes
OnPropertyChanged(nameof(TotalDailyTokens));
OnPropertyChanged(nameof(TotalDailyRequests));
OnPropertyChanged(nameof(LastRequestTotalTokens));
OnPropertyChanged(nameof(LastRequestModelName));
}
}

Expand All @@ -162,7 +165,7 @@ public partial class IntelliChatModuleSettings : ObservableObject
private IntelliGPTModel performBeautifySentenceModel = IntelliGPTModel.gpt4_turbo;

[ObservableProperty]
private IntelliGPTModel performTextCompletionModel = IntelliGPTModel.gpt3_5_turbo_16k;
private IntelliGPTModel performTextCompletionModel = IntelliGPTModel.gpt4_turbo;

[ObservableProperty]
private IntelliGPTModel performModerationCheckModel = IntelliGPTModel.Moderation_Latest;
Expand Down Expand Up @@ -875,7 +878,7 @@ public async Task PerformSpellingAndGrammarCheckAsync(string text)
{
new Message(
Role.System,
"Please correct any spelling and grammar errors in the following text (return also if correct):")
"Please correct any spelling and grammar errors in the following text, always return correct version:")
};

if (!Settings.AutolanguageSelection && Settings.SelectedSupportedLanguages.Count > 0)
Expand Down Expand Up @@ -1043,7 +1046,7 @@ public async Task GenerateCompletionOrPredictionAsync(string inputText, bool isN

// Apply the selected writing style
var writingStyle = Settings.SelectedWritingStyle;
var promptMessage = isNextWordPrediction ? "Predict the next word in a natural, contextually relevant way for VRChat." : "Complete the following text in a cool, engaging manner for VRChat.";
var promptMessage = isNextWordPrediction ? "Predict the next chat message word." : "Complete the following chat message, max 144 characters";
var messages = new List<Message>
{
new Message(Role.System, promptMessage + $"Use a {writingStyle.StyleName} writing style."),
Expand Down
24 changes: 24 additions & 0 deletions vrcosc-magicchatbox/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,29 @@
</ComboBox.ItemTemplate>
</ComboBox>

<TextBlock
Width="auto"
Padding="2,7,0,0"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="13"
Foreground="#FF9983AD"
Text="Next word prediction OpenAI Model" />
<ComboBox
Width="200"
Height="25"
Margin="2,4"
HorizontalAlignment="Left"
ItemsSource="{Binding IntelliChatModule.AvailableChatModels}"
Opacity="0.3"
SelectedValue="{Binding IntelliChatModule.Settings.PerformTextCompletionModel, Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>



</StackPanel>
Expand Down Expand Up @@ -6025,6 +6048,7 @@
Click="NextwordPredict_Click"
Style="{DynamicResource LINK_Button_style}"
ToolTip="Predict next word by AI"
Visibility="Collapsed"
WindowChrome.IsHitTestVisibleInChrome="True">
<StackPanel Orientation="Horizontal" RenderOptions.BitmapScalingMode="HighQuality">
<Image
Expand Down
2 changes: 1 addition & 1 deletion vrcosc-magicchatbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ private void MyUsageBtn_MouseUp(object sender, MouseButtonEventArgs e)

private void NextwordPredict_Click(object sender, RoutedEventArgs e)
{
ViewModel.Instance.IntelliChatModule.GenerateCompletionOrPredictionAsync(ViewModel.Instance.NewChattingTxt, false);
ViewModel.Instance.IntelliChatModule.GenerateCompletionOrPredictionAsync(ViewModel.Instance.NewChattingTxt, true);
}

private void Record_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 0272cc9

Please sign in to comment.