Skip to content

Commit aab8fa2

Browse files
author
Jefferson Pires
committed
Added the "Cancel" commands to stop receiving/waiting the requests.
1 parent 025cdc9 commit aab8fa2

22 files changed

+229
-62
lines changed

README.md

+5-14
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ English | [Chinese](https://github.com/jeffdapaz/VisualChatGPTStudio/blob/master
55
- For Visual Studio 2022: [here](https://marketplace.visualstudio.com/items?itemName=jefferson-pires.VisualChatGPTStudio)
66
- For Visual Studio 2019: [here](https://marketplace.visualstudio.com/items?itemName=jefferson-pires.VisualChatGPTStudio2019)
77

8-
## ⚠ ATTENTION!!! Since version 2.0.0 we have a breaking change.
9-
10-
Due to the discontinuation of Completion Models by OpenAI (more information [here](https://openai.com/blog/gpt-4-api-general-availability)), this extension no longer provide support for these models.
11-
12-
From now on, all requests to OpenAI will be made using Chat Models, which are at the moment GPT-3.5-TURBO, GPT-3.5-TURBO-16K E GPT-4.
13-
14-
### How can this maybe affect you?
15-
16-
- As the models are different, the behavior of the responses may be different, especially if you have customized the commands. If the responses start to not be as expected, it will be necessary to adjust the commands or the request parameters through the Options.
17-
18-
- For Azure users: Before the 2.0.0 version, you had to create two resources to could use properly this extension, one resource for Completion Models and another one for Chat Models. Now this is not more necessary, you only need to have one resource that use Chat Model. Because of that Azure users need adjust the Azure parameters through Options.
19-
20-
- And if after the steps above you still have issues, please, leave me a comment for I can adjust or fix.
21-
228
## Description
239

2410
This is an extension that adds chatGPT functionality directly within Visual Studio.
@@ -47,6 +33,7 @@ Select a method and right click on text editor and you see these new chatGPT com
4733
- **Custom Before:** Create a custom command through the options that inserts the response before the selected code.
4834
- **Custom After:** Create a custom command through the options that inserts the response after the selected code.
4935
- **Custom Replace:** Create a custom command through the options that replace the selected text with the response.
36+
- **Cancel:** Cancel receiving/waiting any command requests.
5037

5138
And if you desire that the responses be written on tool window instead on the code editor, press and hold the SHIFT key and select the command (not work with the shortcuts).
5239

@@ -120,6 +107,10 @@ You can check your quota here: [https://platform.openai.com/account/usage](https
120107

121108
## Release Notes
122109

110+
### 2.1.0
111+
112+
- Added the "Cancel" commands to stop receiving/waiting the requests.
113+
123114
### 2.0.0
124115

125116
- Completion models removed. Now all requests will be made through Chat Models.

Resources/cancel.png

750 Bytes
Loading

Resources/cancelCommand.png

198 Bytes
Loading

VSCommandTable.cs

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ internal sealed partial class PackageIds
3535
public const int CustomBefore = 0x0800;
3636
public const int CustomAfter = 0x0900;
3737
public const int CustomReplace = 0x0901;
38+
public const int Cancel = 0x0999;
3839
}
3940
}

VSCommandTable.vsct

+17
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@
116116
<LocCanonicalName>.VisuallChatGPTStudio.CustomReplace</LocCanonicalName>
117117
</Strings>
118118
</Button>
119+
<Button guid="VisuallChatGPTStudio" id="Cancel" priority="0x0999" type="Button">
120+
<Icon guid="VisuallChatGPTStudioCancelIcon" id="cancelIcon" />
121+
<Strings>
122+
<ButtonText>Cancel</ButtonText>
123+
<LocCanonicalName>.VisuallChatGPTStudio.Cancel</LocCanonicalName>
124+
</Strings>
125+
</Button>
119126
<Button guid="guidVisuallChatGPTStudioPackageCmdSet" id="cmdidTerminalWindowCommand" priority="0x0100" type="Button">
120127
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1" />
121128
<Icon guid="VisuallChatGPTStudioChatGPTIcon" id="chatGPTIcon" />
@@ -147,6 +154,7 @@
147154
<Bitmap guid="VisuallChatGPTStudioCustomBeforeIcon" href="Resources\customBefore.png" usedList="customBeforeIcon"/>
148155
<Bitmap guid="VisuallChatGPTStudioCustomAfterIcon" href="Resources\customAfter.png" usedList="customAfterIcon"/>
149156
<Bitmap guid="VisuallChatGPTStudioCustomReplaceIcon" href="Resources\customReplace.png" usedList="customReplaceIcon"/>
157+
<Bitmap guid="VisuallChatGPTStudioCancelIcon" href="Resources\cancelCommand.png" usedList="cancelIcon"/>
150158
<Bitmap guid="VisuallChatGPTStudioChatGPTIcon" href="Resources\bot.png" usedList="chatGPTIcon"/>
151159
<Bitmap guid="VisuallChatGPTStudioTurboIcon" href="Resources\turbo.png" usedList="turboIcon"/>
152160
</Bitmaps>
@@ -167,6 +175,7 @@
167175
<KeyBinding guid="VisuallChatGPTStudio" id="CustomBefore" mod1="ALT" key1="0" editor="guidVSStd97" />
168176
<KeyBinding guid="VisuallChatGPTStudio" id="CustomAfter" mod1="ALT" key1="A" editor="guidVSStd97" />
169177
<KeyBinding guid="VisuallChatGPTStudio" id="CustomReplace" mod1="ALT" key1="R" editor="guidVSStd97" />
178+
<KeyBinding guid="VisuallChatGPTStudio" id="Cancel" mod1="ALT" key1="Z" editor="guidVSStd97" />
170179
</KeyBindings>
171180

172181
<CommandPlacements>
@@ -238,6 +247,10 @@
238247
<Parent guid="VisuallChatGPTStudio" id="MyGroupForCommands"/>
239248
</CommandPlacement>
240249

250+
<CommandPlacement guid="VisuallChatGPTStudio" id="Cancel" priority="0x0999" >
251+
<Parent guid="VisuallChatGPTStudio" id="MyGroupForCommands"/>
252+
</CommandPlacement>
253+
241254
</CommandPlacements>
242255

243256
<Symbols>
@@ -260,6 +273,7 @@
260273
<IDSymbol name="CustomBefore" value="0x0800" />
261274
<IDSymbol name="CustomAfter" value="0x0900" />
262275
<IDSymbol name="CustomReplace" value="0x0901" />
276+
<IDSymbol name="Cancel" value="0x0999" />
263277
</GuidSymbol>
264278

265279
<GuidSymbol value="{8b0b1a54-4655-4dae-8984-022f82a739f2}" name="guidVisuallChatGPTStudioPackageCmdSet">
@@ -309,6 +323,9 @@
309323
<GuidSymbol name="VisuallChatGPTStudioCustomReplaceIcon" value="{38A870F1-BED8-4322-B98B-11A53E51821C}">
310324
<IDSymbol name="customReplaceIcon" value="1" />
311325
</GuidSymbol>
326+
<GuidSymbol name="VisuallChatGPTStudioCancelIcon" value="{D346ADF7-8DF0-48DE-B268-7149699B3CF8}">
327+
<IDSymbol name="cancelIcon" value="1" />
328+
</GuidSymbol>
312329
<GuidSymbol name="VisuallChatGPTStudioChatGPTIcon" value="{4C9AF432-30B5-44CB-9A6E-3121C6DC7A49}">
313330
<IDSymbol name="chatGPTIcon" value="1" />
314331
</GuidSymbol>

VisualChatGPTStudio.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
<Resource Include="Resources\explain.png" />
139139
<Resource Include="Resources\findBugs.png" />
140140
<Resource Include="Resources\garbage.png" />
141+
<Resource Include="Resources\cancel.png" />
142+
<Resource Include="Resources\cancelCommand.png" />
141143
<Content Include="Resources\Icon.png">
142144
<IncludeInVSIX>true</IncludeInVSIX>
143145
</Content>
Binary file not shown.

VisualChatGPTStudio2019/VisualChatGPTStudio2019.csproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,21 @@
117117
</PackageReference>
118118
</ItemGroup>
119119
<ItemGroup>
120-
<Resource Include="Resources\addSummaryForAll.png" />
121120
<Resource Include="..\Resources\translate.png">
122121
<Link>Resources\translate.png</Link>
123122
</Resource>
124123
<Resource Include="..\Resources\optimizeDiffView.png">
125124
<Link>Resources\optimizeDiffView.png</Link>
126125
</Resource>
126+
<Resource Include="..\Resources\cancel.png">
127+
<Link>Resources\cancel.png</Link>
128+
</Resource>
129+
<Resource Include="..\Resources\addSummaryForAll.png">
130+
<Link>Resources\addSummaryForAll.png</Link>
131+
</Resource>
132+
<Content Include="..\Resources\cancelCommand.png">
133+
<Link>Resources\cancelCommand.png</Link>
134+
</Content>
127135
<Content Include="Icon2019.png">
128136
<IncludeInVSIX>true</IncludeInVSIX>
129137
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

VisualChatGPTStudio2019/source.extension.vsixmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="VisualChatGPTStudio2019.4854bc98-735d-4622-a0cf-30454b50aa0f" Version="2.0.1" Language="en-US" Publisher="Jefferson Pires" />
4+
<Identity Id="VisualChatGPTStudio2019.4854bc98-735d-4622-a0cf-30454b50aa0f" Version="2.1.0" Language="en-US" Publisher="Jefferson Pires" />
55
<DisplayName>Visual chatGPT Studio 2019</DisplayName>
66
<Description xml:space="preserve">Add chatGPT functionalities directly on Visual Studio.</Description>
77
<Icon>Icon2019.png</Icon>

VisualChatGPTStudioShared/Commands/AddSummaryForAll.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Linq;
1212
using System.Text;
1313
using System.Text.RegularExpressions;
14+
using System.Threading;
1415
using System.Threading.Tasks;
1516
using Constants = JeffPires.VisualChatGPTStudio.Utils.Constants;
1617

@@ -88,6 +89,8 @@ protected override async System.Threading.Tasks.Task ExecuteAsync(OleMenuCmdEven
8889

8990
int memberIndex = 1;
9091

92+
CancellationTokenSource = new CancellationTokenSource();
93+
9194
await VS.StatusBar.ShowProgressAsync(PROGRESS_MESSAGE, memberIndex, totalDeclarations);
9295

9396
foreach (SyntaxNode member in root.DescendantNodes().Where(d => CheckIfMemberTypeIsValid(d)))
@@ -107,14 +110,17 @@ protected override async System.Threading.Tasks.Task ExecuteAsync(OleMenuCmdEven
107110
}
108111
catch (Exception ex)
109112
{
113+
await VS.StatusBar.ShowProgressAsync(ex.Message, totalDeclarations, totalDeclarations);
114+
110115
if (!string.IsNullOrWhiteSpace(originalCode))
111116
{
112117
docView.TextView.TextBuffer.Replace(new Span(0, originalCode.Length), originalCode);
113118
}
114119

115-
await VS.StatusBar.ShowProgressAsync(ex.Message, totalDeclarations, totalDeclarations);
116-
117-
await VS.MessageBox.ShowAsync(Constants.EXTENSION_NAME, ex.Message, Microsoft.VisualStudio.Shell.Interop.OLEMSGICON.OLEMSGICON_WARNING, Microsoft.VisualStudio.Shell.Interop.OLEMSGBUTTON.OLEMSGBUTTON_OK);
120+
if (ex is not OperationCanceledException)
121+
{
122+
await VS.MessageBox.ShowAsync(Constants.EXTENSION_NAME, ex.Message, Microsoft.VisualStudio.Shell.Interop.OLEMSGICON.OLEMSGICON_WARNING, Microsoft.VisualStudio.Shell.Interop.OLEMSGBUTTON.OLEMSGBUTTON_OK);
123+
}
118124
}
119125
}
120126

@@ -201,7 +207,7 @@ private async Task<string> RequestAsync(string code)
201207
{
202208
string command = TextFormat.FormatCommandForSummary($"{OptionsCommands.AddSummary}\r\n\r\n{{0}}\r\n\r\n", code);
203209

204-
string result = await ChatGPT.GetResponseAsync(OptionsGeneral, command, code, new string[] { "public", "private", "internal" });
210+
string result = await ChatGPT.GetResponseAsync(OptionsGeneral, command, code, new string[] { "public", "private", "internal" }, CancellationTokenSource.Token);
205211

206212
result = RemoveBlankLinesFromResult(result);
207213

VisualChatGPTStudioShared/Commands/BaseCommand.cs

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using JeffPires.VisualChatGPTStudio.Options;
44
using Microsoft.VisualStudio.Shell;
55
using System;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using Constants = JeffPires.VisualChatGPTStudio.Utils.Constants;
89

@@ -14,6 +15,21 @@ namespace JeffPires.VisualChatGPTStudio.Commands
1415
/// <typeparam name="TCommand">The type of the command.</typeparam>
1516
internal abstract class BaseCommand<TCommand> : Community.VisualStudio.Toolkit.BaseCommand<TCommand> where TCommand : class, new()
1617
{
18+
/// <summary>
19+
/// Gets or sets the cancellation token source.
20+
/// </summary>
21+
protected CancellationTokenSource CancellationTokenSource
22+
{
23+
get
24+
{
25+
return ((VisuallChatGPTStudioPackage)this.Package).CancellationTokenSource;
26+
}
27+
set
28+
{
29+
((VisuallChatGPTStudioPackage)this.Package).CancellationTokenSource = value;
30+
}
31+
}
32+
1733
/// <summary>
1834
/// Gets the OptionsGeneral property of the VisualChatGPTStudioPackage.
1935
/// </summary>

0 commit comments

Comments
 (0)