├── .gitignore
├── Copilot
├── CommandFilter.cs
├── InlinePredictionManager.cs
├── Suggestions.cs
└── TextViewCreationListener.cs
├── LICENSE
├── OpenAI_API
├── APIAuthentication.cs
├── ApiResultBase.cs
├── Chat
│ ├── ChatContent.cs
│ ├── ChatEndpoint.cs
│ ├── ChatMessage.cs
│ ├── ChatMessageRole.cs
│ ├── ChatRequest.cs
│ ├── ChatResult.cs
│ ├── Conversation.cs
│ └── IChatEndpoint.cs
├── Completions
│ ├── CompletionEndpoint.cs
│ ├── CompletionRequest.cs
│ ├── CompletionResult.cs
│ └── ICompletionEndpoint.cs
├── Embedding
│ ├── EmbeddingEndpoint.cs
│ ├── EmbeddingRequest.cs
│ ├── EmbeddingResult.cs
│ └── IEmbeddingEndpoint.cs
├── EndpointBase.cs
├── Files
│ ├── File.cs
│ ├── FilesEndpoint.cs
│ └── IFilesEndpoint.cs
├── Functions
│ ├── FunctionRequest.cs
│ └── FunctionResult.cs
├── IOpenAIAPI.cs
├── Images
│ ├── IImageGenerationEndpoint.cs
│ ├── ImageGenerationEndpoint.cs
│ ├── ImageGenerationRequest.cs
│ ├── ImageResponseFormat.cs
│ ├── ImageResult.cs
│ └── ImageSize.cs
├── Model
│ ├── IModelsEndpoint.cs
│ ├── Model.cs
│ └── ModelsEndpoint.cs
├── Moderation
│ ├── IModerationEndpoint.cs
│ ├── ModerationEndpoint.cs
│ ├── ModerationRequest.cs
│ └── ModerationResult.cs
├── OpenAIAPI.cs
├── OpenAI_API.csproj
└── Usage.cs
├── Properties
└── AssemblyInfo.cs
├── README-zh.md
├── README.md
├── ReleaseNotes.md
├── Resources
├── DB.png
├── FileTypes
│ ├── config.png
│ ├── cs.png
│ ├── css.png
│ ├── folder.png
│ ├── html.png
│ ├── js.png
│ ├── json.png
│ ├── md.png
│ ├── sln.png
│ ├── sql.png
│ ├── ts.png
│ ├── vb.png
│ ├── vs.png
│ ├── xaml.png
│ └── xml.png
├── Highlighting.xshd
├── Icon.png
├── addComments.png
├── addSummary.png
├── addSummaryForAll.png
├── addTests.png
├── api.png
├── askAnything.png
├── bot.png
├── cancel.png
├── cancelCommand.png
├── chatGPT.png
├── check.png
├── clear.png
├── close.png
├── cloud.png
├── codeReview.png
├── complete.png
├── copy.png
├── customAfter.png
├── customBefore.png
├── customReplace.png
├── diffView.png
├── edit_color.png
├── explain.png
├── findBugs.png
├── garbage.png
├── garbage_color.png
├── git.png
├── image.png
├── information.png
├── optimize.png
├── optimizeDiffView.png
├── paste.png
├── send.png
├── sendCode.png
├── solutionContext.png
├── translate.png
├── turbo.png
├── vs.png
└── wordWrap.png
├── VSCommandTable.cs
├── VSCommandTable.vsct
├── VisualChatGPTStudio.csproj
├── VisualChatGPTStudio.sln
├── VisualChatGPTStudio2019
├── .gitignore
├── Icon2019.png
├── Properties
│ └── AssemblyInfo.cs
├── Resources
│ └── Icon2019.png
├── VisualChatGPTStudio2019.csproj
├── source.extension.cs
└── source.extension.vsixmanifest
├── VisualChatGPTStudioShared
├── Agents
│ ├── ApiAgent
│ │ ├── ApiAgent.cs
│ │ ├── ApiItem.cs
│ │ └── ApiTagItem.cs
│ └── SqlServerAgent.cs
├── Commands
│ ├── AddComments.cs
│ ├── AddSummary.cs
│ ├── AddSummaryForAll.cs
│ ├── AddTests.cs
│ ├── AskAnything.cs
│ ├── BaseCommand.cs
│ ├── BaseGenericCommand.cs
│ ├── Cancel.cs
│ ├── Complete.cs
│ ├── CustomAfter.cs
│ ├── CustomBefore.cs
│ ├── CustomReplace.cs
│ ├── Explain.cs
│ ├── FindBugs.cs
│ ├── Optimize.cs
│ ├── OptimizeDiffView.cs
│ ├── TerminalWindowCodeReviewCommand.cs
│ ├── TerminalWindowCommand.cs
│ ├── TerminalWindowSolutionContextCommand.cs
│ ├── TerminalWindowTurboCommand.cs
│ └── Translate.cs
├── Options
│ ├── ApiAgent
│ │ ├── OptionApiAgent.cs
│ │ ├── OptionApiAgentWindow.xaml
│ │ └── OptionApiAgentWindow.xaml.cs
│ ├── Commands
│ │ ├── Commands.cs
│ │ ├── OptionCommands.cs
│ │ ├── OptionCommandsWindow.xaml
│ │ └── OptionCommandsWindow.xaml.cs
│ └── OptionPageGrid.cs
├── ToolWindows
│ ├── CodeReview
│ │ ├── CodeReviewItem.cs
│ │ ├── TerminalWindowCodeReview.cs
│ │ ├── TerminalWindowCodeReviewControl.cs
│ │ └── TerminalWindowCodeReviewControl.xaml
│ ├── SolutionContext
│ │ ├── TerminalWindowSolutionContext.cs
│ │ ├── TerminalWindowSolutionContextControl.cs
│ │ └── TerminalWindowSolutionContextControl.xaml
│ ├── TerminalWindow
│ │ ├── TerminalWindow.cs
│ │ ├── TerminalWindowControl.xaml
│ │ └── TerminalWindowControl.xaml.cs
│ ├── TerminalWindowHelper.cs
│ └── Turbo
│ │ ├── ChatEntity.cs
│ │ ├── ChatListControlItem.cs
│ │ ├── ChatMessageSegment.cs
│ │ ├── ChatUserControlsItem.cs
│ │ ├── TerminalWindowTurbo.cs
│ │ ├── TerminalWindowTurboControl.xaml
│ │ ├── TerminalWindowTurboControl.xaml.cs
│ │ ├── ucChat.xaml
│ │ ├── ucChat.xaml.cs
│ │ ├── ucChatHeader.xaml
│ │ ├── ucChatHeader.xaml.cs
│ │ ├── ucChatItem.xaml
│ │ └── ucChatItem.xaml.cs
├── Utils
│ ├── ApiHandler.cs
│ ├── AttachImage.cs
│ ├── CodeCompletion
│ │ ├── CompletionData.cs
│ │ └── CompletionManager.cs
│ ├── CommandImage.cs
│ ├── Constants.cs
│ ├── DiffView.cs
│ ├── EnumHelper.cs
│ ├── Enums.cs
│ ├── GitChanges.cs
│ ├── HighlightingDefinitionConverter.cs
│ ├── Http
│ │ ├── ChatGPTHttpClientFactory.cs
│ │ ├── HttpClientCustom.cs
│ │ ├── HttpLogs.cs
│ │ └── RequestCaptureHandler.cs
│ ├── Repositories
│ │ ├── ApiAgentRepository.cs
│ │ ├── ChatRepository.cs
│ │ └── Repository.cs
│ └── TextFormat.cs
├── VisualChatGPTStudioShared.projitems
├── VisualChatGPTStudioShared.shproj
└── VisuallChatGPTStudioPackage.cs
├── icons8-chatgpt-512.png
├── lib
├── osx-arm64
│ └── libgit2-a2bde63.dylib
└── win32
│ ├── arm64
│ └── git2-a2bde63.dll
│ ├── x64
│ └── git2-a2bde63.dll
│ └── x86
│ └── git2-a2bde63.dll
├── source.extension.cs
└── source.extension.vsixmanifest
/Copilot/TextViewCreationListener.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Editor;
2 | using Microsoft.VisualStudio.Shell;
3 | using Microsoft.VisualStudio.Shell.Interop;
4 | using Microsoft.VisualStudio.Text.Editor;
5 | using Microsoft.VisualStudio.TextManager.Interop;
6 | using Microsoft.VisualStudio.Utilities;
7 | using System.ComponentModel.Composition;
8 | using System.Threading.Tasks;
9 |
10 | namespace JeffPires.VisualChatGPTStudio.Copilot
11 | {
12 | ///
13 | /// Exports the IVsTextViewCreationListener to handle the creation of text views in Visual Studio.
14 | ///
15 | [Export(typeof(IVsTextViewCreationListener))]
16 | [ContentType("code")]
17 | [TextViewRole(PredefinedTextViewRoles.Editable)]
18 | internal class TextViewCreationListener : IVsTextViewCreationListener
19 | {
20 | ///
21 | /// Gets or sets the IVsEditorAdaptersFactoryService instance used to create and manage editor adapters.
22 | ///
23 | [Import]
24 | internal IVsEditorAdaptersFactoryService AdapterService { get; set; }
25 |
26 | ///
27 | /// Handles the creation of a Visual Studio text view, initializing necessary components such as the prediction manager and command filter.
28 | ///
29 | public void VsTextViewCreated(IVsTextView textViewAdapter)
30 | {
31 | IWpfTextView view = AdapterService.GetWpfTextView(textViewAdapter);
32 |
33 | if (view == null)
34 | {
35 | return;
36 | }
37 |
38 | VisuallChatGPTStudioPackage package = GetPackageAsync().Result;
39 |
40 | if (package == null)
41 | {
42 | return;
43 | }
44 |
45 | InlinePredictionManager predictionManager = new(view);
46 |
47 | CommandFilter commandFilter = new(view, predictionManager, package.OptionsGeneral);
48 | commandFilter.AttachToView(textViewAdapter);
49 | }
50 |
51 | ///
52 | /// Asynchronously retrieves the VisuallChatGPTStudioPackage instance.
53 | ///
54 | ///
55 | /// The task result contains the VisuallChatGPTStudioPackage instance if found; otherwise, null.
56 | ///
57 | private async Task GetPackageAsync()
58 | {
59 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
60 |
61 | IVsShell shell = (IVsShell)ServiceProvider.GlobalProvider.GetService(typeof(SVsShell));
62 |
63 | if (shell != null)
64 | {
65 | shell.LoadPackage(ref PackageGuids.VisuallChatGPTStudio, out IVsPackage package);
66 |
67 | return package as VisuallChatGPTStudioPackage;
68 | }
69 |
70 | return null;
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Jefferson Pires
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/OpenAI_API/ApiResultBase.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using OpenAI_API.Models;
3 | using System;
4 |
5 | namespace OpenAI_API
6 | {
7 | ///
8 | /// Represents a result from calling the OpenAI API, with all the common metadata returned from every endpoint
9 | ///
10 | abstract public class ApiResultBase
11 | {
12 |
13 | /// The time when the result was generated
14 | [JsonIgnore]
15 | public DateTime? Created => CreatedUnixTime.HasValue ? (DateTime?)(DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime.Value).DateTime) : null;
16 |
17 | ///
18 | /// The time when the result was generated in unix epoch format
19 | ///
20 | [JsonProperty("created")]
21 | public long? CreatedUnixTime { get; set; }
22 |
23 | ///
24 | /// Which model was used to generate this result.
25 | ///
26 | [JsonProperty("model")]
27 | public Model Model { get; set; }
28 |
29 | ///
30 | /// Object type, ie: text_completion, file, fine-tune, list, etc
31 | ///
32 | [JsonProperty("object")]
33 | public string Object { get; set; }
34 |
35 | ///
36 | /// The organization associated with the API request, as reported by the API.
37 | ///
38 | [JsonIgnore]
39 | public string Organization { get; internal set; }
40 |
41 | ///
42 | /// The server-side processing time as reported by the API. This can be useful for debugging where a delay occurs.
43 | ///
44 | [JsonIgnore]
45 | public TimeSpan ProcessingTime { get; internal set; }
46 |
47 | ///
48 | /// The request id of this API call, as reported in the response headers. This may be useful for troubleshooting or when contacting OpenAI support in reference to a specific request.
49 | ///
50 | [JsonIgnore]
51 | public string RequestId { get; internal set; }
52 |
53 | ///
54 | /// The Openai-Version used to generate this response, as reported in the response headers. This may be useful for troubleshooting or when contacting OpenAI support in reference to a specific request.
55 | ///
56 | [JsonIgnore]
57 | public string OpenaiVersion { get; internal set; }
58 | }
59 | }
--------------------------------------------------------------------------------
/OpenAI_API/Chat/ChatContent.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace OpenAI_API.Chat
5 | {
6 | ///
7 | /// Represents the base class for chat content, providing a common type identifier.
8 | ///
9 | public abstract class ChatContentBase
10 | {
11 | ///
12 | /// Represents the type of the object, initialized with a default value.
13 | ///
14 | [JsonProperty("type")]
15 | public string Type { get; private set; }
16 |
17 | ///
18 | /// Initializes a new instance of the ChatContentBase class with the specified type.
19 | ///
20 | /// The type of the chat content.
21 | public ChatContentBase(string type)
22 | {
23 | Type = type;
24 | }
25 | }
26 |
27 | ///
28 | /// Represents the content of a chat message in text format.
29 | /// Inherits from the ChatContentBase class, specifying the content type as "text".
30 | ///
31 | public class ChatContentForText : ChatContentBase
32 | {
33 | ///
34 | /// Represents a text property that is serialized to JSON with the key "text".
35 | ///
36 | [JsonProperty("text")]
37 | public string Text { get; set; }
38 |
39 | ///
40 | /// Initializes a new instance of the ChatContentForText class with the specified text.
41 | ///
42 | /// The text content to initialize the instance with.
43 | public ChatContentForText(string text) : base(text)
44 | {
45 | Text = text;
46 | }
47 | }
48 |
49 | ///
50 | /// Represents the content of a chat message that contains an image,
51 | /// initialized with the specified image data.
52 | ///
53 | public class ChatContentForImage : ChatContentBase
54 | {
55 | ///
56 | /// Represents the URL of an image, initialized with a base64 encoded JPEG image data.
57 | ///
58 | [JsonProperty("image_url")]
59 | public ImageUrl ImageUrl { get; private set; }
60 |
61 | ///
62 | /// Initializes a new instance of the ChatContentForImage class with the provided image data.
63 | /// Converts the byte array to a Base64 string and constructs an image URL in the "data:image/jpeg;base64" format.
64 | ///
65 | /// The byte array representing the image data.
66 | public ChatContentForImage(byte[] imageData) : base("image_url")
67 | {
68 | ImageUrl = new ImageUrl("data:image/jpeg;base64," + Convert.ToBase64String(imageData));
69 | }
70 | }
71 |
72 | ///
73 | /// Represents an image URL with a specified URL string.
74 | ///
75 | public class ImageUrl
76 | {
77 | ///
78 | /// Represents a URL property that can be serialized to and from JSON.
79 | ///
80 | [JsonProperty("url")]
81 | public string Url { get; set; }
82 |
83 | ///
84 | /// Initializes a new instance of the ImageUrl class with the specified URL.
85 | ///
86 | /// The URL of the image.
87 | public ImageUrl(string url)
88 | {
89 | Url = url;
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/OpenAI_API/Chat/ChatMessage.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using OpenAI_API.Functions;
3 | using System.Collections.Generic;
4 |
5 | namespace OpenAI_API.Chat
6 | {
7 | ///
8 | /// Chat message sent or received from the API. Includes who is speaking in the "role" and the message text in the "content"
9 | ///
10 | public class ChatMessage
11 | {
12 | ///
13 | /// Creates an empty , with defaulting to
14 | ///
15 | public ChatMessage()
16 | {
17 | this.Role = ChatMessageRole.User;
18 | }
19 |
20 | ///
21 | /// Initializes a new instance of the ChatMessage class with the specified role and content.
22 | ///
23 | /// The role associated with the chat message (e.g., user, system, assistant).
24 | /// The content of the chat message.
25 | public ChatMessage(ChatMessageRole role, object content)
26 | {
27 | this.Role = role;
28 | this.Content = content;
29 | }
30 |
31 | ///
32 | /// Initializes a new instance of the ChatMessage class with the specified role, content, and function ID.
33 | ///
34 | /// The role associated with the chat message.
35 | /// The content of the chat message.
36 | /// The identifier for the function associated with the chat message.
37 | public ChatMessage(ChatMessageRole role, object content, string functionId)
38 | {
39 | this.Role = role;
40 | this.Content = content;
41 | this.FunctionId = functionId;
42 | }
43 |
44 | [JsonProperty("role")]
45 | internal string rawRole { get; set; }
46 |
47 | ///
48 | /// The role of the message, which can be "system", "assistant" or "user"
49 | ///
50 | [JsonIgnore]
51 | public ChatMessageRole Role
52 | {
53 | get
54 | {
55 | return ChatMessageRole.FromString(rawRole);
56 | }
57 | set
58 | {
59 | rawRole = value.ToString();
60 | }
61 | }
62 |
63 | ///
64 | /// The content of the message
65 | ///
66 | [JsonProperty("content")]
67 | public object Content { get; set; }
68 |
69 | ///
70 | /// An optional name of the user in a multi-user chat
71 | ///
72 | [JsonProperty("name")]
73 | public string Name { get; set; }
74 |
75 | ///
76 | /// Functions to be executed.
77 | ///
78 | [JsonProperty("tool_calls")]
79 | public IReadOnlyList Functions { get; set; }
80 |
81 | ///
82 | /// The function id.
83 | ///
84 | [JsonProperty("tool_call_id")]
85 | public string FunctionId { get; set; }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/OpenAI_API/Chat/ChatMessageRole.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace OpenAI_API.Chat
4 | {
5 | ///
6 | /// Represents the Role of a . Typically, a conversation is formatted with a system message first, followed by alternating user and assistant messages. See the OpenAI docs for more details about usage.
7 | ///
8 | public class ChatMessageRole : IEquatable
9 | {
10 | ///
11 | /// Constructor is private to force usage of strongly typed values
12 | ///
13 | ///
14 | private ChatMessageRole(string value) { Value = value; }
15 |
16 | ///
17 | /// Gets the singleton instance of based on the string value.
18 | ///
19 | /// Muse be one of "system", "user", or "assistant"
20 | ///
21 | public static ChatMessageRole FromString(string roleName)
22 | {
23 | switch (roleName)
24 | {
25 | case "system":
26 | return ChatMessageRole.System;
27 | case "user":
28 | return ChatMessageRole.User;
29 | case "assistant":
30 | return ChatMessageRole.Assistant;
31 | case "tool":
32 | return ChatMessageRole.Tool;
33 | default:
34 | return null;
35 | }
36 | }
37 |
38 | private string Value { get; }
39 |
40 | ///
41 | /// The system message helps set the behavior of the assistant.
42 | ///
43 | public static ChatMessageRole System { get; } = new ChatMessageRole("system");
44 |
45 | ///
46 | /// The user messages help instruct the assistant. They can be generated by the end users of an application, or set by a developer as an instruction.
47 | ///
48 | public static ChatMessageRole User { get; } = new ChatMessageRole("user");
49 |
50 | ///
51 | /// The assistant messages help store prior responses. They can also be written by a developer to help give examples of desired behavior.
52 | ///
53 | public static ChatMessageRole Assistant { get; } = new ChatMessageRole("assistant");
54 |
55 | ///
56 | /// The tool message to indicates a result of a function execution
57 | ///
58 | public static ChatMessageRole Tool { get; } = new ChatMessageRole("tool");
59 |
60 | ///
61 | /// Gets the string value for this role to pass to the API
62 | ///
63 | /// The size as a string
64 | public override string ToString()
65 | {
66 | return Value;
67 | }
68 |
69 | ///
70 | /// Determines whether this instance and a specified object have the same value.
71 | ///
72 | /// The ChatMessageRole to compare to this instance
73 | /// true if obj is a ChatMessageRole and its value is the same as this instance; otherwise, false. If obj is null, the method returns false
74 | public override bool Equals(object obj)
75 | {
76 | return Value.Equals((obj as ChatMessageRole).Value);
77 | }
78 |
79 | ///
80 | /// Returns the hash code for this object
81 | ///
82 | /// A 32-bit signed integer hash code
83 | public override int GetHashCode()
84 | {
85 | return Value.GetHashCode();
86 | }
87 |
88 | ///
89 | /// Determines whether this instance and a specified object have the same value.
90 | ///
91 | /// The ChatMessageRole to compare to this instance
92 | /// true if other's value is the same as this instance; otherwise, false. If other is null, the method returns false
93 | public bool Equals(ChatMessageRole other)
94 | {
95 | return Value.Equals(other.Value);
96 | }
97 |
98 | ///
99 | /// Gets the string value for this role to pass to the API
100 | ///
101 | /// The ChatMessageRole to convert
102 | public static implicit operator String(ChatMessageRole value) { return value.Value; }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/OpenAI_API/Chat/ChatResult.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System.Collections.Generic;
3 |
4 | namespace OpenAI_API.Chat
5 | {
6 | ///
7 | /// Represents a result from calling the Chat API
8 | ///
9 | public class ChatResult : ApiResultBase
10 | {
11 | ///
12 | /// The identifier of the result, which may be used during troubleshooting
13 | ///
14 | [JsonProperty("id")]
15 | public string Id { get; set; }
16 |
17 | ///
18 | /// The list of choices that the user was presented with during the chat interaction
19 | ///
20 | [JsonProperty("choices")]
21 | public IReadOnlyList Choices { get; set; }
22 |
23 | ///
24 | /// The usage statistics for the chat interaction
25 | ///
26 | [JsonProperty("usage")]
27 | public ChatUsage Usage { get; set; }
28 |
29 | ///
30 | /// A convenience method to return the content of the message in the first choice of this response
31 | ///
32 | /// The content of the message, not including .
33 | public override string ToString()
34 | {
35 | if (Choices != null && Choices.Count > 0)
36 | {
37 | return Choices[0].ToString();
38 | }
39 | else
40 | {
41 | return null;
42 | }
43 | }
44 | }
45 |
46 | ///
47 | /// A message received from the API, including the message text, index, and reason why the message finished.
48 | ///
49 | public class ChatChoice
50 | {
51 | ///
52 | /// The index of the choice in the list of choices
53 | ///
54 | [JsonProperty("index")]
55 | public int Index { get; set; }
56 |
57 | ///
58 | /// The message that was presented to the user as the choice
59 | ///
60 | [JsonProperty("message")]
61 | public ChatMessage Message { get; set; }
62 |
63 | ///
64 | /// The reason why the chat interaction ended after this choice was presented to the user
65 | ///
66 | [JsonProperty("finish_reason")]
67 | public string FinishReason { get; set; }
68 |
69 | ///
70 | /// Partial message "delta" from a stream. For example, the result from StreamChatEnumerableAsync.
71 | /// If this result object is not from a stream, this will be null
72 | ///
73 | [JsonProperty("delta")]
74 | public ChatMessage Delta { get; set; }
75 |
76 | ///
77 | /// A convenience method to return the content of the message in this response
78 | ///
79 | /// The content of the message in this response, not including .
80 | public override string ToString()
81 | {
82 | return Message.Content?.ToString();
83 | }
84 | }
85 |
86 | ///
87 | /// How many tokens were used in this chat message.
88 | ///
89 | public class ChatUsage : Usage
90 | {
91 | ///
92 | /// The number of completion tokens used during the chat interaction
93 | ///
94 | [JsonProperty("completion_tokens")]
95 | public int CompletionTokens { get; set; }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/OpenAI_API/Completions/CompletionResult.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using OpenAI_API.Embedding;
3 | using System.Collections.Generic;
4 |
5 | namespace OpenAI_API.Completions
6 | {
7 | ///
8 | /// Represents a completion choice returned by the Completion API.
9 | ///
10 | public class Choice
11 | {
12 | ///
13 | /// The main text of the completion
14 | ///
15 | [JsonProperty("text")]
16 | public string Text { get; set; }
17 |
18 | ///
19 | /// If multiple completion choices we returned, this is the index withing the various choices
20 | ///
21 | [JsonProperty("index")]
22 | public int Index { get; set; }
23 |
24 | ///
25 | /// If the request specified , this contains the list of the most likely tokens.
26 | ///
27 | [JsonProperty("logprobs")]
28 | public Logprobs Logprobs { get; set; }
29 |
30 | ///
31 | /// If this is the last segment of the completion result, this specifies why the completion has ended.
32 | ///
33 | [JsonProperty("finish_reason")]
34 | public string FinishReason { get; set; }
35 |
36 | ///
37 | /// Gets the main text of this completion
38 | ///
39 | public override string ToString()
40 | {
41 | return Text;
42 | }
43 | }
44 |
45 | ///
46 | /// API usage as reported by the OpenAI API for this request
47 | ///
48 | public class CompletionUsage : Usage
49 | {
50 | ///
51 | /// How many tokens are in the completion(s)
52 | ///
53 | [JsonProperty("completion_tokens")]
54 | public short CompletionTokens { get; set; }
55 | }
56 |
57 | ///
58 | /// Represents a result from calling the Completion API
59 | ///
60 | public class CompletionResult : ApiResultBase
61 | {
62 | ///
63 | /// The identifier of the result, which may be used during troubleshooting
64 | ///
65 | [JsonProperty("id")]
66 | public string Id { get; set; }
67 |
68 | ///
69 | /// The completions returned by the API. Depending on your request, there may be 1 or many choices.
70 | ///
71 | [JsonProperty("choices")]
72 | public List Completions { get; set; }
73 |
74 | ///
75 | /// API token usage as reported by the OpenAI API for this request
76 | ///
77 | [JsonProperty("usage")]
78 | public CompletionUsage Usage { get; set; }
79 |
80 | ///
81 | /// Gets the text of the first completion, representing the main result
82 | ///
83 | public override string ToString()
84 | {
85 | if (Completions != null && Completions.Count > 0)
86 | return Completions[0].ToString();
87 | else
88 | return $"CompletionResult {Id} has no valid output";
89 | }
90 | }
91 |
92 |
93 | public class Logprobs
94 | {
95 | [JsonProperty("tokens")]
96 | public List Tokens { get; set; }
97 |
98 | [JsonProperty("token_logprobs")]
99 | public List TokenLogprobs { get; set; }
100 |
101 | [JsonProperty("top_logprobs")]
102 | public IList> TopLogprobs { get; set; }
103 |
104 | [JsonProperty("text_offset")]
105 | public List TextOffsets { get; set; }
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/OpenAI_API/Embedding/EmbeddingEndpoint.cs:
--------------------------------------------------------------------------------
1 | using OpenAI_API.Models;
2 | using System.Threading.Tasks;
3 |
4 | namespace OpenAI_API.Embedding
5 | {
6 | ///
7 | /// OpenAI’s text embeddings measure the relatedness of text strings by generating an embedding, which is a vector (list) of floating point numbers. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.
8 | ///
9 | public class EmbeddingEndpoint : EndpointBase, IEmbeddingEndpoint
10 | {
11 | ///
12 | /// This allows you to send request to the recommended model without needing to specify. Every request uses the model
13 | ///
14 | public EmbeddingRequest DefaultEmbeddingRequestArgs { get; set; } = new EmbeddingRequest() { Model = Model.AdaTextEmbedding };
15 |
16 | ///
17 | /// The name of the endpoint, which is the final path segment in the API URL. For example, "embeddings".
18 | ///
19 | protected override string Endpoint { get { return "embeddings"; } }
20 |
21 | ///
22 | /// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of as .
23 | ///
24 | ///
25 | internal EmbeddingEndpoint(OpenAIAPI api) : base(api) { }
26 |
27 | ///
28 | /// Ask the API to embedd text using the default embedding model
29 | ///
30 | /// Text to be embedded
31 | /// Asynchronously returns the embedding result. Look in its property of to find the vector of floating point numbers
32 | public async Task CreateEmbeddingAsync(string input)
33 | {
34 | EmbeddingRequest req = new EmbeddingRequest(DefaultEmbeddingRequestArgs.Model, input);
35 | return await CreateEmbeddingAsync(req);
36 | }
37 |
38 | ///
39 | /// Ask the API to embedd text using a custom request
40 | ///
41 | /// Request to be send
42 | /// Asynchronously returns the embedding result. Look in its property of to find the vector of floating point numbers
43 | public async Task CreateEmbeddingAsync(EmbeddingRequest request)
44 | {
45 | return await HttpPost(postData: request);
46 | }
47 |
48 | ///
49 | /// Ask the API to embedd text using the default embedding model
50 | ///
51 | /// Text to be embedded
52 | /// Asynchronously returns the first embedding result as an array of floats.
53 | public async Task GetEmbeddingsAsync(string input)
54 | {
55 | EmbeddingRequest req = new EmbeddingRequest(DefaultEmbeddingRequestArgs.Model, input);
56 | var embeddingResult = await CreateEmbeddingAsync(req);
57 | return embeddingResult?.Data?[0]?.Embedding;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/OpenAI_API/Embedding/EmbeddingRequest.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using OpenAI_API.Models;
3 |
4 | namespace OpenAI_API.Embedding
5 | {
6 | ///
7 | /// Represents a request to the Completions API. Matches with the docs at the OpenAI docs
8 | ///
9 | public class EmbeddingRequest
10 | {
11 | ///
12 | /// ID of the model to use. You can use to see all of your available models, or use a standard model like .
13 | ///
14 | [JsonProperty("model")]
15 | public string Model { get; set; }
16 |
17 | ///
18 | /// Main text to be embedded
19 | ///
20 | [JsonProperty("input")]
21 | public string Input { get; set; }
22 |
23 | ///
24 | /// Cretes a new, empty
25 | ///
26 | public EmbeddingRequest()
27 | {
28 |
29 | }
30 |
31 | ///
32 | /// Creates a new with the specified parameters
33 | ///
34 | /// The model to use. You can use to see all of your available models, or use a standard model like .
35 | /// The prompt to transform
36 | public EmbeddingRequest(Model model, string input)
37 | {
38 | Model = model;
39 | this.Input = input;
40 | }
41 |
42 | ///
43 | /// Creates a new with the specified input and the model.
44 | ///
45 | /// The prompt to transform
46 | public EmbeddingRequest(string input)
47 | {
48 | Model = OpenAI_API.Models.Model.AdaTextEmbedding;
49 | this.Input = input;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/OpenAI_API/Embedding/EmbeddingResult.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace OpenAI_API.Embedding
6 | {
7 | ///
8 | /// Represents an embedding result returned by the Embedding API.
9 | ///
10 | public class EmbeddingResult : ApiResultBase
11 | {
12 | ///
13 | /// List of results of the embedding
14 | ///
15 | [JsonProperty("data")]
16 | public List Data { get; set; }
17 |
18 | ///
19 | /// Usage statistics of how many tokens have been used for this request
20 | ///
21 | [JsonProperty("usage")]
22 | public Usage Usage { get; set; }
23 |
24 | ///
25 | /// Allows an EmbeddingResult to be implicitly cast to the array of floats repsresenting the first ebmedding result
26 | ///
27 | /// The to cast to an array of floats.
28 | public static implicit operator float[](EmbeddingResult embeddingResult)
29 | {
30 | return embeddingResult.Data.FirstOrDefault()?.Embedding;
31 | }
32 | }
33 |
34 | ///
35 | /// Data returned from the Embedding API.
36 | ///
37 | public class Data
38 | {
39 | ///
40 | /// Type of the response. In case of Data, this will be "embedding"
41 | ///
42 | [JsonProperty("object")]
43 |
44 | public string Object { get; set; }
45 |
46 | ///
47 | /// The input text represented as a vector (list) of floating point numbers
48 | ///
49 | [JsonProperty("embedding")]
50 | public float[] Embedding { get; set; }
51 |
52 | ///
53 | /// Index
54 | ///
55 | [JsonProperty("index")]
56 | public int Index { get; set; }
57 |
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/OpenAI_API/Embedding/IEmbeddingEndpoint.cs:
--------------------------------------------------------------------------------
1 | using OpenAI_API.Models;
2 | using System.Threading.Tasks;
3 |
4 | namespace OpenAI_API.Embedding
5 | {
6 | ///
7 | /// An interface for , for ease of mock testing, etc
8 | ///
9 | public interface IEmbeddingEndpoint
10 | {
11 | ///
12 | /// This allows you to send request to the recommended model without needing to specify. Every request uses the model
13 | ///
14 | EmbeddingRequest DefaultEmbeddingRequestArgs { get; set; }
15 |
16 | ///
17 | /// Ask the API to embedd text using the default embedding model
18 | ///
19 | /// Text to be embedded
20 | /// Asynchronously returns the embedding result. Look in its property of to find the vector of floating point numbers
21 | Task CreateEmbeddingAsync(string input);
22 |
23 | ///
24 | /// Ask the API to embedd text using a custom request
25 | ///
26 | /// Request to be send
27 | /// Asynchronously returns the embedding result. Look in its property of to find the vector of floating point numbers
28 | Task CreateEmbeddingAsync(EmbeddingRequest request);
29 |
30 | ///
31 | /// Ask the API to embedd text using the default embedding model
32 | ///
33 | /// Text to be embedded
34 | /// Asynchronously returns the first embedding result as an array of floats.
35 | Task GetEmbeddingsAsync(string input);
36 | }
37 | }
--------------------------------------------------------------------------------
/OpenAI_API/Files/File.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace OpenAI_API.Files
4 | {
5 | ///
6 | /// Represents a single file used with the OpenAI Files endpoint. Files are used to upload and manage documents that can be used with features like Fine-tuning.
7 | ///
8 | public class File : ApiResultBase
9 | {
10 | ///
11 | /// Unique id for this file, so that it can be referenced in other operations
12 | ///
13 | [JsonProperty("id")]
14 | public string Id { get; set; }
15 |
16 | ///
17 | /// The name of the file
18 | ///
19 | [JsonProperty("filename")]
20 | public string Name { get; set; }
21 |
22 | ///
23 | /// What is the purpose of this file, fine-tune, search, etc
24 | ///
25 | [JsonProperty("purpose")]
26 | public string Purpose { get; set; }
27 |
28 | ///
29 | /// The size of the file in bytes
30 | ///
31 | [JsonProperty("bytes")]
32 | public long Bytes { get; set; }
33 |
34 | ///
35 | /// Timestamp for the creation time of this file
36 | ///
37 | [JsonProperty("created_at")]
38 | public long CreatedAt { get; set; }
39 |
40 | ///
41 | /// When the object is deleted, this attribute is used in the Delete file operation
42 | ///
43 | [JsonProperty("deleted")]
44 | public bool Deleted { get; set; }
45 |
46 | ///
47 | /// The status of the File (ie when an upload operation was done: "uploaded")
48 | ///
49 | [JsonProperty("status")]
50 | public string Status { get; set; }
51 |
52 | ///
53 | /// The status details, it could be null
54 | ///
55 | [JsonProperty("status_details")]
56 | public string StatusDetails { get; set; }
57 |
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/OpenAI_API/Files/FilesEndpoint.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Net.Http;
5 | using System.Threading.Tasks;
6 |
7 | namespace OpenAI_API.Files
8 | {
9 | ///
10 | /// The API endpoint for operations List, Upload, Delete, Retrieve files
11 | ///
12 | public class FilesEndpoint : EndpointBase, IFilesEndpoint
13 | {
14 | ///
15 | /// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of as .
16 | ///
17 | ///
18 | internal FilesEndpoint(OpenAIAPI api) : base(api) { }
19 |
20 | ///
21 | /// The name of the endpoint, which is the final path segment in the API URL. For example, "files".
22 | ///
23 | protected override string Endpoint { get { return "files"; } }
24 |
25 | ///
26 | /// Get the list of all files
27 | ///
28 | ///
29 | ///
30 | public async Task> GetFilesAsync()
31 | {
32 | return (await HttpGet()).Data;
33 | }
34 |
35 | ///
36 | /// Returns information about a specific file
37 | ///
38 | /// The ID of the file to use for this request
39 | ///
40 | public async Task GetFileAsync(string fileId)
41 | {
42 | return await HttpGet($"{Url}/{fileId}");
43 | }
44 |
45 |
46 | ///
47 | /// Returns the contents of the specific file as string
48 | ///
49 | /// The ID of the file to use for this request
50 | ///
51 | public async Task GetFileContentAsStringAsync(string fileId)
52 | {
53 | return await HttpGetContent($"{Url}/{fileId}/content");
54 | }
55 |
56 | ///
57 | /// Delete a file
58 | ///
59 | /// The ID of the file to use for this request
60 | ///
61 | public async Task DeleteFileAsync(string fileId)
62 | {
63 | return await HttpDelete($"{Url}/{fileId}");
64 | }
65 |
66 |
67 | ///
68 | /// Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact OpenAI if you need to increase the storage limit
69 | ///
70 | /// The name of the file to use for this request
71 | /// The intendend purpose of the uploaded documents. Use "fine-tune" for Fine-tuning. This allows us to validate the format of the uploaded file.
72 | public async Task UploadFileAsync(string filePath, string purpose = "fine-tune")
73 | {
74 | var content = new MultipartFormDataContent
75 | {
76 | { new StringContent(purpose), "purpose" },
77 | { new ByteArrayContent(System.IO.File.ReadAllBytes(filePath)), "file", Path.GetFileName(filePath) }
78 | };
79 |
80 | return await HttpPost(Url, content);
81 | }
82 |
83 | ///
84 | /// A helper class to deserialize the JSON API responses. This should not be used directly.
85 | ///
86 | private class FilesData : ApiResultBase
87 | {
88 | [JsonProperty("data")]
89 | public List Data { get; set; }
90 | [JsonProperty("object")]
91 | public string Obj { get; set; }
92 | }
93 | }
94 |
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/OpenAI_API/Files/IFilesEndpoint.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 |
4 | namespace OpenAI_API.Files
5 | {
6 | ///
7 | /// An interface for , for ease of mock testing, etc
8 | ///
9 | public interface IFilesEndpoint
10 | {
11 | ///
12 | /// Get the list of all files
13 | ///
14 | ///
15 | ///
16 | Task> GetFilesAsync();
17 |
18 | ///
19 | /// Returns information about a specific file
20 | ///
21 | /// The ID of the file to use for this request
22 | ///
23 | Task GetFileAsync(string fileId);
24 |
25 | ///
26 | /// Returns the contents of the specific file as string
27 | ///
28 | /// The ID of the file to use for this request
29 | ///
30 | Task GetFileContentAsStringAsync(string fileId);
31 |
32 | ///
33 | /// Delete a file
34 | ///
35 | /// The ID of the file to use for this request
36 | ///
37 | Task DeleteFileAsync(string fileId);
38 |
39 | ///
40 | /// Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact OpenAI if you need to increase the storage limit
41 | ///
42 | /// The name of the file to use for this request
43 | /// The intendend purpose of the uploaded documents. Use "fine-tune" for Fine-tuning. This allows us to validate the format of the uploaded file.
44 | Task UploadFileAsync(string filePath, string purpose = "fine-tune");
45 | }
46 | }
--------------------------------------------------------------------------------
/OpenAI_API/Functions/FunctionRequest.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace OpenAI_API.Functions
6 | {
7 | ///
8 | /// Class to request functions executions from AI
9 | ///
10 | public class FunctionRequest
11 | {
12 | ///
13 | /// Request type
14 | ///
15 | [JsonProperty("type")]
16 | public string Type => "function";
17 |
18 | ///
19 | /// Details of the function to be executed
20 | ///
21 | [JsonProperty("function")]
22 | public Function Function { get; set; }
23 | }
24 |
25 | ///
26 | /// Details of the function to be executed
27 | ///
28 | public class Function
29 | {
30 | ///
31 | /// Function name
32 | ///
33 | [JsonProperty("name")]
34 | public string Name { get; set; }
35 |
36 | ///
37 | /// Details on when and how to use the function
38 | ///
39 | [JsonProperty("description")]
40 | public string Description { get; set; }
41 |
42 | ///
43 | /// Function parameters
44 | ///
45 | [JsonProperty("parameters")]
46 | public Parameter Parameters { get; set; }
47 |
48 | ///
49 | /// Setting strict to true will ensure function calls reliably adhere to the function schema, instead of being best effort. We recommend always enabling strict mode.
50 | ///
51 | [JsonProperty("strict")]
52 | public bool Strict => false;
53 | }
54 |
55 | ///
56 | /// Function parameter
57 | ///
58 | public class Parameter
59 | {
60 | ///
61 | /// Parameter type
62 | ///
63 | [JsonProperty("type")]
64 | public string Type => "object";
65 |
66 | ///
67 | /// Parameter properties list
68 | ///
69 | [JsonProperty("properties")]
70 | public Dictionary Properties { get; set; }
71 |
72 | ///
73 | /// Indicate if the parameter is mandatory.
74 | /// All fields in properties must be marked as required.
75 | ///
76 | [JsonProperty("required")]
77 | public List Required
78 | {
79 | get
80 | {
81 | return Properties.Select(p => p.Key).ToList();
82 | }
83 | }
84 |
85 | ///
86 | /// Must be set to false for each object in the parameters
87 | ///
88 | [JsonProperty("additionalProperties")]
89 | public bool AdditionalProperties => false;
90 | }
91 |
92 | ///
93 | /// Represents a parameter property
94 | ///
95 | public class Property
96 | {
97 | ///
98 | /// Property types
99 | /// You can denote optional fields by adding null as a type option
100 | ///
101 | [JsonProperty("type")]
102 | public List Types { get; set; }
103 |
104 | ///
105 | /// Property description
106 | ///
107 | [JsonProperty("description")]
108 | public string Description { get; set; }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/OpenAI_API/Functions/FunctionResult.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace OpenAI_API.Functions
4 | {
5 | ///
6 | /// Details of the function to be executed
7 | ///
8 | public class FunctionResult
9 | {
10 | ///
11 | /// Used later to submit the function result back to the AI.
12 | ///
13 | [JsonProperty("id")]
14 | public string Id { get; set; }
15 |
16 | ///
17 | /// It will probably always be "function", indicating that the execution of a function is being requested.
18 | ///
19 | ///
20 | [JsonProperty("type")]
21 | public string Type { get; set; }
22 |
23 | ///
24 | /// Gets or sets the function to call, represented by the object.
25 | ///
26 | [JsonProperty("function")]
27 | public FunctionToCall Function { get; set; }
28 | }
29 |
30 | ///
31 | /// Represents a class that encapsulates a function or method to be called.
32 | ///
33 | public class FunctionToCall
34 | {
35 | ///
36 | /// The name of the function to be executed.
37 | ///
38 | [JsonProperty("name")]
39 | public string Name { get; set; }
40 |
41 | ///
42 | /// Gets or sets the function's arguments.
43 | ///
44 | [JsonProperty("arguments")]
45 | public string Arguments { get; set; }
46 | }
47 | }
--------------------------------------------------------------------------------
/OpenAI_API/IOpenAIAPI.cs:
--------------------------------------------------------------------------------
1 | using OpenAI_API.Chat;
2 | using OpenAI_API.Completions;
3 | using OpenAI_API.Embedding;
4 | using OpenAI_API.Files;
5 | using OpenAI_API.Images;
6 | using OpenAI_API.Models;
7 | using OpenAI_API.Moderation;
8 |
9 | namespace OpenAI_API
10 | {
11 | ///
12 | /// An interface for , for ease of mock testing, etc
13 | ///
14 | public interface IOpenAIAPI
15 | {
16 | ///
17 | /// Base url for OpenAI
18 | /// for OpenAI, should be "https://api.openai.com/{0}/{1}"
19 | /// for Azure, should be "https://(your-resource-name.openai.azure.com/openai/deployments/(deployment-id)/{1}?api-version={0}"
20 | ///
21 | string ApiUrlFormat { get; set; }
22 |
23 | ///
24 | /// Version of the Rest Api
25 | ///
26 | string ApiVersion { get; set; }
27 |
28 | ///
29 | /// The API authentication information to use for API calls
30 | ///
31 | APIAuthentication Auth { get; set; }
32 |
33 | ///
34 | /// Text generation in the form of chat messages. This interacts with the ChatGPT API.
35 | ///
36 | IChatEndpoint Chat { get; }
37 |
38 | ///
39 | /// Classify text against the OpenAI Content Policy.
40 | ///
41 | IModerationEndpoint Moderation { get; }
42 |
43 | ///
44 | /// Text generation is the core function of the API. You give the API a prompt, and it generates a completion. The way you “program” the API to do a task is by simply describing the task in plain english or providing a few written examples. This simple approach works for a wide range of use cases, including summarization, translation, grammar correction, question answering, chatbots, composing emails, and much more (see the prompt library for inspiration).
45 | ///
46 | ICompletionEndpoint Completions { get; }
47 |
48 | ///
49 | /// The API lets you transform text into a vector (list) of floating point numbers. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.
50 | ///
51 | IEmbeddingEndpoint Embeddings { get; }
52 |
53 | ///
54 | /// The API endpoint for querying available Engines/models
55 | ///
56 | IModelsEndpoint Models { get; }
57 |
58 | ///
59 | /// The API lets you do operations with files. You can upload, delete or retrieve files. Files can be used for fine-tuning, search, etc.
60 | ///
61 | IFilesEndpoint Files { get; }
62 |
63 | ///
64 | /// The API lets you do operations with images. You can Given a prompt and/or an input image, the model will generate a new image.
65 | ///
66 | IImageGenerationEndpoint ImageGenerations { get; }
67 | }
68 | }
--------------------------------------------------------------------------------
/OpenAI_API/Images/IImageGenerationEndpoint.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using OpenAI_API.Models;
3 |
4 | namespace OpenAI_API.Images
5 | {
6 | ///
7 | /// An interface for . Given a prompt, the model will generate a new image.
8 | ///
9 | public interface IImageGenerationEndpoint
10 | {
11 | ///
12 | /// Ask the API to Creates an image given a prompt.
13 | ///
14 | /// Request to be send
15 | /// Asynchronously returns the image result. Look in its
16 | Task CreateImageAsync(ImageGenerationRequest request);
17 |
18 | ///
19 | /// Ask the API to Creates an image given a prompt.
20 | ///
21 | /// A text description of the desired image(s)
22 | /// The model to use for generating the image. Defaults to .
23 | /// Asynchronously returns the image result. Look in its
24 | Task CreateImageAsync(string input, Model model = null);
25 | }
26 | }
--------------------------------------------------------------------------------
/OpenAI_API/Images/ImageGenerationEndpoint.cs:
--------------------------------------------------------------------------------
1 | using OpenAI_API.Models;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace OpenAI_API.Images
8 | {
9 | ///
10 | /// Given a prompt, the model will generate a new image.
11 | ///
12 | public class ImageGenerationEndpoint : EndpointBase, IImageGenerationEndpoint
13 | {
14 | ///
15 | /// The name of the endpoint, which is the final path segment in the API URL. For example, "image".
16 | ///
17 | protected override string Endpoint { get { return "images/generations"; } }
18 |
19 | ///
20 | /// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of as .
21 | ///
22 | ///
23 | internal ImageGenerationEndpoint(OpenAIAPI api) : base(api) { }
24 |
25 | ///
26 | /// Ask the API to Creates an image given a prompt.
27 | ///
28 | /// A text description of the desired image(s)
29 | /// The model to use for generating the image. Defaults to .
30 | /// Asynchronously returns the image result. Look in its
31 | public async Task CreateImageAsync(string input, Model model = null)
32 | {
33 | ImageGenerationRequest req = new ImageGenerationRequest(prompt: input, model: model);
34 | return await CreateImageAsync(req);
35 | }
36 |
37 | ///
38 | /// Ask the API to Creates an image given a prompt.
39 | ///
40 | /// Request to be send
41 | /// Asynchronously returns the image result. Look in its
42 | public async Task CreateImageAsync(ImageGenerationRequest request)
43 | {
44 | return await HttpPost(postData: request);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/OpenAI_API/Images/ImageResponseFormat.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace OpenAI_API.Images
7 | {
8 | ///
9 | /// Represents available response formats for image generation endpoints
10 | ///
11 | public class ImageResponseFormat
12 | {
13 | private ImageResponseFormat(string value) { Value = value; }
14 |
15 | private string Value { get; set; }
16 |
17 | ///
18 | /// Requests an image that is 256x256
19 | ///
20 | public static ImageResponseFormat Url { get { return new ImageResponseFormat("url"); } }
21 | ///
22 | /// Requests an image that is 512x512
23 | ///
24 | public static ImageResponseFormat B64_json { get { return new ImageResponseFormat("b64_json"); } }
25 |
26 |
27 | ///
28 | /// Gets the string value for this response format to pass to the API
29 | ///
30 | /// The response format as a string
31 | public override string ToString()
32 | {
33 | return Value;
34 | }
35 |
36 | ///
37 | /// Gets the string value for this response format to pass to the API
38 | ///
39 | /// The ImageResponseFormat to convert
40 | public static implicit operator String(ImageResponseFormat value) { return value; }
41 |
42 | internal class ImageResponseJsonConverter : JsonConverter
43 | {
44 | public override ImageResponseFormat ReadJson(JsonReader reader, Type objectType, ImageResponseFormat existingValue, bool hasExistingValue, JsonSerializer serializer)
45 | {
46 | return new ImageResponseFormat(reader.ReadAsString());
47 | }
48 |
49 | public override void WriteJson(JsonWriter writer, ImageResponseFormat value, JsonSerializer serializer)
50 | {
51 | writer.WriteValue(value.ToString());
52 | }
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/OpenAI_API/Images/ImageResult.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace OpenAI_API.Images
7 | {
8 | ///
9 | /// Represents an image result returned by the Image API.
10 | ///
11 | public class ImageResult : ApiResultBase
12 | {
13 | ///
14 | /// List of results of the embedding
15 | ///
16 | [JsonProperty("data")]
17 | public List Data { get; set; }
18 |
19 | ///
20 | /// Gets the url or base64-encoded image data of the first result, or null if there are no results
21 | ///
22 | ///
23 | public override string ToString()
24 | {
25 | if (Data?.Count > 0)
26 | {
27 | return Data[0].Url ?? Data[0].Base64Data;
28 | }
29 | else
30 | {
31 | return null;
32 | }
33 | }
34 | }
35 |
36 | ///
37 | /// Data returned from the Image API.
38 | ///
39 | public class Data
40 | {
41 | ///
42 | /// The url of the image result
43 | ///
44 | [JsonProperty("url")]
45 |
46 | public string Url { get; set; }
47 |
48 | ///
49 | /// The base64-encoded image data as returned by the API
50 | ///
51 | [JsonProperty("b64_json")]
52 | public string Base64Data { get; set; }
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/OpenAI_API/Images/ImageSize.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using OpenAI_API.Models;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace OpenAI_API.Images
8 | {
9 | ///
10 | /// Represents available sizes for image generation endpoints
11 | ///
12 | public class ImageSize
13 | {
14 | internal ImageSize(string value) { Value = value; }
15 |
16 | private string Value { get; set; }
17 |
18 | ///
19 | /// Only for DALL-E 2. Requests an image that is 256x256
20 | ///
21 | public static ImageSize _256 { get { return new ImageSize("256x256"); } }
22 | ///
23 | /// Only for DALL-E 2. Requests an image that is 512x512
24 | ///
25 | public static ImageSize _512 { get { return new ImageSize("512x512"); } }
26 | ///
27 | /// Works with both DALL-E 2 and 3. Requests and image that is 1024x1024.
28 | ///
29 | public static ImageSize _1024 { get { return new ImageSize("1024x1024"); } }
30 |
31 | ///
32 | /// Only for DALL-E 3. Requests a tall image that is 1024x1792.
33 | ///
34 | public static ImageSize _1024x1792 { get { return new ImageSize("1024x1792"); } }
35 |
36 | ///
37 | /// Only for DALL-E 3. Requests a wide image that is 1792x1024.
38 | ///
39 | public static ImageSize _1792x1024 { get { return new ImageSize("1792x1024"); } }
40 |
41 | ///
42 | /// Gets the string value for this size to pass to the API
43 | ///
44 | /// The size as a string
45 | public override string ToString()
46 | {
47 | return Value;
48 | }
49 |
50 | ///
51 | /// Returns true is the string value of the sizes match
52 | ///
53 | /// The other object to compare to
54 | /// True is the sizes are the same
55 | public override bool Equals(object obj)
56 | {
57 | if (obj is null)
58 | return false;
59 | else if (obj is ImageSize)
60 | return this.Value.Equals(((ImageSize)obj).Value);
61 | else if (obj is string)
62 | return this.Value.Equals((string)obj);
63 | else
64 | return false;
65 | }
66 |
67 | ///
68 | public override int GetHashCode()
69 | {
70 | return Value.GetHashCode();
71 | }
72 |
73 | public static bool operator ==(ImageSize a, ImageSize b)
74 | {
75 | return a.Equals(b);
76 | }
77 | public static bool operator !=(ImageSize a, ImageSize b)
78 | {
79 | return !a.Equals(b);
80 | }
81 |
82 | ///
83 | /// Gets the string value for this size to pass to the API
84 | ///
85 | /// The ImageSize to convert
86 | public static implicit operator String(ImageSize value) { return value; }
87 |
88 | internal class ImageSizeJsonConverter : JsonConverter
89 | {
90 | public override void WriteJson(JsonWriter writer, ImageSize value, JsonSerializer serializer)
91 | {
92 | writer.WriteValue(value.ToString());
93 | }
94 |
95 | public override ImageSize ReadJson(JsonReader reader, Type objectType, ImageSize existingValue, bool hasExistingValue, JsonSerializer serializer)
96 | {
97 | return new ImageSize(reader.ReadAsString());
98 | }
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/OpenAI_API/Model/IModelsEndpoint.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 |
4 | namespace OpenAI_API.Models
5 | {
6 | ///
7 | /// An interface for , for ease of mock testing, etc
8 | ///
9 | public interface IModelsEndpoint
10 | {
11 | ///
12 | /// Get details about a particular Model from the API, specifically properties such as and permissions.
13 | ///
14 | /// The id/name of the model to get more details about
15 | /// Asynchronously returns the with all available properties
16 | Task RetrieveModelDetailsAsync(string id);
17 |
18 | ///
19 | /// Get details about a particular Model from the API, specifically properties such as and permissions.
20 | ///
21 | /// The id/name of the model to get more details about
22 | /// Obsolete: IGNORED
23 | /// Asynchronously returns the with all available properties
24 | Task RetrieveModelDetailsAsync(string id, APIAuthentication auth = null);
25 |
26 | ///
27 | /// List all models via the API
28 | ///
29 | /// Asynchronously returns the list of all s
30 | Task> GetModelsAsync();
31 | }
32 | }
--------------------------------------------------------------------------------
/OpenAI_API/Model/ModelsEndpoint.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Threading.Tasks;
5 |
6 | namespace OpenAI_API.Models
7 | {
8 | ///
9 | /// The API endpoint for querying available models
10 | ///
11 | public class ModelsEndpoint : EndpointBase, IModelsEndpoint
12 | {
13 | ///
14 | /// The name of the endpoint, which is the final path segment in the API URL. For example, "models".
15 | ///
16 | protected override string Endpoint { get { return "models"; } }
17 |
18 | ///
19 | /// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of as .
20 | ///
21 | ///
22 | internal ModelsEndpoint(OpenAIAPI api) : base(api) { }
23 |
24 | ///
25 | /// Get details about a particular Model from the API, specifically properties such as and permissions.
26 | ///
27 | /// The id/name of the model to get more details about
28 | /// Asynchronously returns the with all available properties
29 | public async Task RetrieveModelDetailsAsync(string id)
30 | {
31 | string resultAsString = await HttpGetContent($"{Url}/{id}");
32 | var model = JsonConvert.DeserializeObject(resultAsString);
33 | return model;
34 | }
35 |
36 | ///
37 | /// List all models via the API
38 | ///
39 | /// Asynchronously returns the list of all s
40 | public async Task> GetModelsAsync()
41 | {
42 | return (await HttpGet()).data;
43 | }
44 |
45 | ///
46 | /// Get details about a particular Model from the API, specifically properties such as and permissions.
47 | ///
48 | /// The id/name of the model to get more details about
49 | /// Obsolete: IGNORED
50 | /// Asynchronously returns the with all available properties
51 | [Obsolete("Use the overload without the APIAuthentication parameter instead, as custom auth is no longer used.", false)]
52 | public async Task RetrieveModelDetailsAsync(string id, APIAuthentication auth = null)
53 | {
54 | return await this.RetrieveModelDetailsAsync(id);
55 | }
56 |
57 | ///
58 | /// A helper class to deserialize the JSON API responses. This should not be used directly.
59 | ///
60 | private class JsonHelperRoot : ApiResultBase
61 | {
62 | [JsonProperty("data")]
63 | public List data { get; set; }
64 | [JsonProperty("object")]
65 | public string obj { get; set; }
66 |
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/OpenAI_API/Moderation/IModerationEndpoint.cs:
--------------------------------------------------------------------------------
1 | using OpenAI_API.Models;
2 | using System.Threading.Tasks;
3 |
4 | namespace OpenAI_API.Moderation
5 | {
6 | ///
7 | /// An interface for , which classifies text against the OpenAI Content Policy
8 | ///
9 | public interface IModerationEndpoint
10 | {
11 | ///
12 | /// This allows you to send request to the recommended model without needing to specify. OpenAI recommends using the model
13 | ///
14 | ModerationRequest DefaultModerationRequestArgs { get; set; }
15 |
16 | ///
17 | /// Ask the API to classify the text using a custom request.
18 | ///
19 | /// Request to send to the API
20 | /// Asynchronously returns the classification result
21 | Task CallModerationAsync(ModerationRequest request);
22 |
23 | ///
24 | /// Ask the API to classify the text using the default model.
25 | ///
26 | /// Text to classify
27 | /// Asynchronously returns the classification result
28 | Task CallModerationAsync(string input);
29 | }
30 | }
--------------------------------------------------------------------------------
/OpenAI_API/Moderation/ModerationEndpoint.cs:
--------------------------------------------------------------------------------
1 | using OpenAI_API.Models;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace OpenAI_API.Moderation
8 | {
9 | ///
10 | /// This endpoint classifies text against the OpenAI Content Policy
11 | ///
12 | public class ModerationEndpoint : EndpointBase, IModerationEndpoint
13 | {
14 | ///
15 | /// This allows you to send request to the recommended model without needing to specify. OpenAI recommends using the model
16 | ///
17 | public ModerationRequest DefaultModerationRequestArgs { get; set; } = new ModerationRequest() { Model = Model.TextModerationLatest };
18 |
19 | ///
20 | /// The name of the endpoint, which is the final path segment in the API URL. For example, "completions".
21 | ///
22 | protected override string Endpoint { get { return "moderations"; } }
23 |
24 | ///
25 | /// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of as .
26 | ///
27 | ///
28 | internal ModerationEndpoint(OpenAIAPI api) : base(api) { }
29 |
30 | ///
31 | /// Ask the API to classify the text using the default model.
32 | ///
33 | /// Text to classify
34 | /// Asynchronously returns the classification result
35 | public async Task CallModerationAsync(string input)
36 | {
37 | ModerationRequest req = new ModerationRequest(input, DefaultModerationRequestArgs.Model);
38 | return await CallModerationAsync(req);
39 | }
40 |
41 | ///
42 | /// Ask the API to classify the text using a custom request.
43 | ///
44 | /// Request to send to the API
45 | /// Asynchronously returns the classification result
46 | public async Task CallModerationAsync(ModerationRequest request)
47 | {
48 | return await HttpPost(postData: request);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/OpenAI_API/Moderation/ModerationRequest.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using OpenAI_API.Models;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Reflection;
7 | using System.Text;
8 |
9 | namespace OpenAI_API.Moderation
10 | {
11 | ///
12 | /// Represents a request to the Moderations API.
13 | ///
14 | public class ModerationRequest
15 | {
16 |
17 | ///
18 | /// Which Moderation model to use for this request. Two content moderations models are available: and . The default is which will be automatically upgraded over time.This ensures you are always using our most accurate model.If you use , we will provide advanced notice before updating the model. Accuracy of may be slightly lower than for .
19 | ///
20 | [JsonProperty("model")]
21 | public string Model { get; set; }
22 |
23 | ///
24 | /// The input text to classify
25 | ///
26 | [JsonIgnore]
27 | public string Input
28 | {
29 | get
30 | {
31 | if (Inputs == null)
32 | return null;
33 | else
34 | return Inputs.FirstOrDefault();
35 | }
36 | set
37 | {
38 | Inputs = new string[] { value };
39 | }
40 | }
41 |
42 | ///
43 | /// An array of inputs to classify
44 | ///
45 | [JsonProperty("input")]
46 | public string[] Inputs { get; set; }
47 |
48 | ///
49 | /// Cretes a new, empty
50 | ///
51 | public ModerationRequest()
52 | {
53 |
54 | }
55 |
56 | ///
57 | /// Creates a new with the specified parameters
58 | ///
59 | /// The prompt to classify
60 | /// The model to use. You can use to see all of your available models, or use a standard model like .
61 | public ModerationRequest(string input, Model model)
62 | {
63 | Model = model;
64 | this.Input = input;
65 | }
66 |
67 | ///
68 | /// Creates a new with the specified parameters
69 | ///
70 | /// An array of prompts to classify
71 | /// The model to use. You can use to see all of your available models, or use a standard model like .
72 | public ModerationRequest(string[] inputs, Model model)
73 | {
74 | Model = model;
75 | this.Inputs = inputs;
76 | }
77 |
78 | ///
79 | /// Creates a new with the specified input(s) and the model.
80 | ///
81 | /// One or more prompts to classify
82 | public ModerationRequest(params string[] input)
83 | {
84 | Model = OpenAI_API.Models.Model.TextModerationLatest;
85 | this.Inputs = input;
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/OpenAI_API/OpenAIAPI.cs:
--------------------------------------------------------------------------------
1 | using OpenAI_API.Chat;
2 | using OpenAI_API.Completions;
3 | using OpenAI_API.Embedding;
4 | using OpenAI_API.Files;
5 | using OpenAI_API.Images;
6 | using OpenAI_API.Models;
7 | using OpenAI_API.Moderation;
8 | using System.Net.Http;
9 |
10 | namespace OpenAI_API
11 | {
12 | ///
13 | /// Entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
14 | ///
15 | public class OpenAIAPI : IOpenAIAPI
16 | {
17 | ///
18 | /// Base url for OpenAI
19 | /// for OpenAI, should be "https://api.openai.com/{0}/{1}"
20 | /// for Azure, should be "https://(your-resource-name.openai.azure.com/openai/deployments/(deployment-id)/{1}?api-version={0}"
21 | ///
22 | public string ApiUrlFormat { get; set; } = "https://api.openai.com/{0}/{1}";
23 |
24 | ///
25 | /// Version of the Rest Api
26 | ///
27 | public string ApiVersion { get; set; } = "v1";
28 |
29 | ///
30 | /// The API authentication information to use for API calls
31 | ///
32 | public APIAuthentication Auth { get; set; }
33 |
34 | ///
35 | /// Optionally provide an IHttpClientFactory to create the client to send requests.
36 | ///
37 | public IHttpClientFactory HttpClientFactory { get; set; }
38 |
39 | ///
40 | /// Creates a new entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
41 | ///
42 | /// The API authentication information to use for API calls, or to attempt to use the , potentially loading from environment vars or from a config file.
43 | public OpenAIAPI(APIAuthentication apiKeys = null)
44 | {
45 | this.Auth = apiKeys.ThisOrDefault();
46 | Completions = new CompletionEndpoint(this);
47 | Models = new ModelsEndpoint(this);
48 | Files = new FilesEndpoint(this);
49 | Embeddings = new EmbeddingEndpoint(this);
50 | Chat = new ChatEndpoint(this);
51 | Moderation = new ModerationEndpoint(this);
52 | ImageGenerations = new ImageGenerationEndpoint(this);
53 | }
54 |
55 | ///
56 | /// Creates an instance of the OpenAIAPI configured for Azure with the specified resource name and deployment ID.
57 | ///
58 | /// The name of the Azure resource where the OpenAI service is deployed.
59 | /// The ID of the specific deployment of the OpenAI model.
60 | /// The API authentication key used to access the OpenAI service.
61 | ///
62 | /// An instance of the OpenAIAPI configured for Azure with the provided parameters.
63 | ///
64 | public static OpenAIAPI ForAzure(string YourResourceName, string deploymentId, APIAuthentication apiKey)
65 | {
66 | return new OpenAIAPI(apiKey)
67 | {
68 | ApiVersion = "2022-12-01",
69 | ApiUrlFormat = $"https://{YourResourceName}.openai.azure.com/openai/deployments/{deploymentId}/" + "{1}?api-version={0}"
70 | };
71 | }
72 |
73 | ///
74 | /// Creates an instance of the OpenAIAPI configured for Azure with the specified URL and API key.
75 | ///
76 | /// The endpoint URL for the Azure OpenAI service.
77 | /// The API authentication key used to access the service.
78 | ///
79 | /// An instance of OpenAIAPI configured to communicate with the Azure service at the specified URL.
80 | ///
81 | public static OpenAIAPI ForAzure(string url, APIAuthentication apiKey)
82 | {
83 | return new OpenAIAPI(apiKey) { ApiVersion = string.Empty, ApiUrlFormat = url };
84 | }
85 |
86 | ///
87 | /// Text generation is the core function of the API. You give the API a prompt, and it generates a completion. The way you “program” the API to do a task is by simply describing the task in plain english or providing a few written examples. This simple approach works for a wide range of use cases, including summarization, translation, grammar correction, question answering, chatbots, composing emails, and much more (see the prompt library for inspiration).
88 | ///
89 | public ICompletionEndpoint Completions { get; }
90 |
91 | ///
92 | /// The API lets you transform text into a vector (list) of floating point numbers. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.
93 | ///
94 | public IEmbeddingEndpoint Embeddings { get; }
95 |
96 | ///
97 | /// Text generation in the form of chat messages. This interacts with the ChatGPT API.
98 | ///
99 | public IChatEndpoint Chat { get; }
100 |
101 | ///
102 | /// Classify text against the OpenAI Content Policy.
103 | ///
104 | public IModerationEndpoint Moderation { get; }
105 |
106 | ///
107 | /// The API endpoint for querying available Engines/models
108 | ///
109 | public IModelsEndpoint Models { get; }
110 |
111 | ///
112 | /// The API lets you do operations with files. You can upload, delete or retrieve files. Files can be used for fine-tuning, search, etc.
113 | ///
114 | public IFilesEndpoint Files { get; }
115 |
116 | ///
117 | /// The API lets you do operations with images. Given a prompt and/or an input image, the model will generate a new image.
118 | ///
119 | public IImageGenerationEndpoint ImageGenerations { get; }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/OpenAI_API/OpenAI_API.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | 8.0
6 | False
7 |
8 | OpenAI API
9 | A simple C# / .NET library to use with OpenAI's APIs, including GPT 3.5, GPT 4, ChatGPT, DALL-E, etc. Independently developed, this is not an official library and I am not affiliated with OpenAI. An OpenAI or Azure OpenAI account is required.
10 | This library is licensed CC-0, in the public domain
11 | CC0-1.0
12 |
13 |
14 | OpenAI, AI, ML, API, ChatGPT, DALLE, GPT3, GPT-3, GPT4, GPT-4, DALL-E
15 | OpenAI API
16 |
17 | OpenAI
18 | 1.8
19 | 1.8.0.0
20 | 1.8.0.0
21 | True
22 |
23 | True
24 | git
25 |
26 |
27 | true
28 |
29 | true
30 | snupkg
31 |
32 | true
33 |
34 |
35 |
36 |
37 |
38 | False
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/OpenAI_API/Usage.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace OpenAI_API
7 | {
8 | ///
9 | /// Usage statistics of how many tokens have been used for this request.
10 | ///
11 | public class Usage
12 | {
13 | ///
14 | /// How many tokens did the prompt consist of
15 | ///
16 | [JsonProperty("prompt_tokens")]
17 | public int PromptTokens { get; set; }
18 |
19 | ///
20 | /// How many tokens did the request consume total
21 | ///
22 | [JsonProperty("total_tokens")]
23 | public int TotalTokens { get; set; }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio;
2 | using System.Reflection;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle(Vsix.Name)]
6 | [assembly: AssemblyDescription(Vsix.Description)]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany(Vsix.Author)]
9 | [assembly: AssemblyProduct(Vsix.Name)]
10 | [assembly: AssemblyCopyright(Vsix.Author)]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: AssemblyVersion(Vsix.Version)]
17 | [assembly: AssemblyFileVersion(Vsix.Version)]
18 |
19 | namespace System.Runtime.CompilerServices
20 | {
21 | public class IsExternalInit { }
22 | }
--------------------------------------------------------------------------------
/Resources/DB.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/DB.png
--------------------------------------------------------------------------------
/Resources/FileTypes/config.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/config.png
--------------------------------------------------------------------------------
/Resources/FileTypes/cs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/cs.png
--------------------------------------------------------------------------------
/Resources/FileTypes/css.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/css.png
--------------------------------------------------------------------------------
/Resources/FileTypes/folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/folder.png
--------------------------------------------------------------------------------
/Resources/FileTypes/html.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/html.png
--------------------------------------------------------------------------------
/Resources/FileTypes/js.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/js.png
--------------------------------------------------------------------------------
/Resources/FileTypes/json.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/json.png
--------------------------------------------------------------------------------
/Resources/FileTypes/md.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/md.png
--------------------------------------------------------------------------------
/Resources/FileTypes/sln.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/sln.png
--------------------------------------------------------------------------------
/Resources/FileTypes/sql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/sql.png
--------------------------------------------------------------------------------
/Resources/FileTypes/ts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/ts.png
--------------------------------------------------------------------------------
/Resources/FileTypes/vb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/vb.png
--------------------------------------------------------------------------------
/Resources/FileTypes/vs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/vs.png
--------------------------------------------------------------------------------
/Resources/FileTypes/xaml.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/xaml.png
--------------------------------------------------------------------------------
/Resources/FileTypes/xml.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/FileTypes/xml.png
--------------------------------------------------------------------------------
/Resources/Highlighting.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Resources/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/Icon.png
--------------------------------------------------------------------------------
/Resources/addComments.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/addComments.png
--------------------------------------------------------------------------------
/Resources/addSummary.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/addSummary.png
--------------------------------------------------------------------------------
/Resources/addSummaryForAll.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/addSummaryForAll.png
--------------------------------------------------------------------------------
/Resources/addTests.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/addTests.png
--------------------------------------------------------------------------------
/Resources/api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/api.png
--------------------------------------------------------------------------------
/Resources/askAnything.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/askAnything.png
--------------------------------------------------------------------------------
/Resources/bot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/bot.png
--------------------------------------------------------------------------------
/Resources/cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/cancel.png
--------------------------------------------------------------------------------
/Resources/cancelCommand.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/cancelCommand.png
--------------------------------------------------------------------------------
/Resources/chatGPT.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/chatGPT.png
--------------------------------------------------------------------------------
/Resources/check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/check.png
--------------------------------------------------------------------------------
/Resources/clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/clear.png
--------------------------------------------------------------------------------
/Resources/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/close.png
--------------------------------------------------------------------------------
/Resources/cloud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/cloud.png
--------------------------------------------------------------------------------
/Resources/codeReview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/codeReview.png
--------------------------------------------------------------------------------
/Resources/complete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/complete.png
--------------------------------------------------------------------------------
/Resources/copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/copy.png
--------------------------------------------------------------------------------
/Resources/customAfter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/customAfter.png
--------------------------------------------------------------------------------
/Resources/customBefore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/customBefore.png
--------------------------------------------------------------------------------
/Resources/customReplace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/customReplace.png
--------------------------------------------------------------------------------
/Resources/diffView.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/diffView.png
--------------------------------------------------------------------------------
/Resources/edit_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/edit_color.png
--------------------------------------------------------------------------------
/Resources/explain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/explain.png
--------------------------------------------------------------------------------
/Resources/findBugs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/findBugs.png
--------------------------------------------------------------------------------
/Resources/garbage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/garbage.png
--------------------------------------------------------------------------------
/Resources/garbage_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/garbage_color.png
--------------------------------------------------------------------------------
/Resources/git.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/git.png
--------------------------------------------------------------------------------
/Resources/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/image.png
--------------------------------------------------------------------------------
/Resources/information.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/information.png
--------------------------------------------------------------------------------
/Resources/optimize.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/optimize.png
--------------------------------------------------------------------------------
/Resources/optimizeDiffView.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/optimizeDiffView.png
--------------------------------------------------------------------------------
/Resources/paste.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/paste.png
--------------------------------------------------------------------------------
/Resources/send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/send.png
--------------------------------------------------------------------------------
/Resources/sendCode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/sendCode.png
--------------------------------------------------------------------------------
/Resources/solutionContext.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/solutionContext.png
--------------------------------------------------------------------------------
/Resources/translate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/translate.png
--------------------------------------------------------------------------------
/Resources/turbo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/turbo.png
--------------------------------------------------------------------------------
/Resources/vs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/vs.png
--------------------------------------------------------------------------------
/Resources/wordWrap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/Resources/wordWrap.png
--------------------------------------------------------------------------------
/VSCommandTable.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by the free extension VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | using System;
7 |
8 | namespace JeffPires.VisualChatGPTStudio
9 | {
10 | ///
11 | /// Helper class that exposes all GUIDs used across VS Package.
12 | ///
13 | internal sealed partial class PackageGuids
14 | {
15 | public const string VisuallChatGPTStudioString = "a8eb0343-b35c-4175-95d8-50549e609ff3";
16 | public static Guid VisuallChatGPTStudio = new Guid(VisuallChatGPTStudioString);
17 | }
18 |
19 | ///
20 | /// Helper class that encapsulates all CommandIDs uses across VS Package.
21 | ///
22 | internal sealed partial class PackageIds
23 | {
24 | public const int Complete = 0x0000;
25 | public const int AddTests = 0x0100;
26 | public const int FindBugs = 0x0200;
27 | public const int Optimize = 0x0300;
28 | public const int OptimizeDiffView = 0x0301;
29 | public const int Explain = 0x0400;
30 | public const int AddComments = 0x0500;
31 | public const int AddSummary = 0x0600;
32 | public const int AddSummaryForAll = 0x0601;
33 | public const int AskAnything = 0x0700;
34 | public const int Translate = 0x0701;
35 | public const int CustomBefore = 0x0800;
36 | public const int CustomAfter = 0x0900;
37 | public const int CustomReplace = 0x0901;
38 | public const int Cancel = 0x0999;
39 | }
40 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudio.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.3.32929.385
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisualChatGPTStudio", "VisualChatGPTStudio.csproj", "{E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}"
7 | EndProject
8 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "VisualChatGPTStudioShared", "VisualChatGPTStudioShared\VisualChatGPTStudioShared.shproj", "{8D02BB3E-2996-4B5C-A4BE-C1514B7B93DF}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisualChatGPTStudio2019", "VisualChatGPTStudio2019\VisualChatGPTStudio2019.csproj", "{17478673-FB35-4FF3-8EA2-9B2849B490BD}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI_API", "OpenAI_API\OpenAI_API.csproj", "{FB118D8F-18E1-4B77-9882-4EE77469CB8D}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Debug|arm64 = Debug|arm64
18 | Debug|x86 = Debug|x86
19 | Release|Any CPU = Release|Any CPU
20 | Release|arm64 = Release|arm64
21 | Release|x86 = Release|x86
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Debug|arm64.ActiveCfg = Debug|arm64
27 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Debug|arm64.Build.0 = Debug|arm64
28 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Debug|x86.ActiveCfg = Debug|x86
29 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Debug|x86.Build.0 = Debug|x86
30 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Release|arm64.ActiveCfg = Release|arm64
33 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Release|arm64.Build.0 = Release|arm64
34 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Release|x86.ActiveCfg = Release|x86
35 | {E0B7C5AC-2E05-4849-81E4-8BF62BBCD16A}.Release|x86.Build.0 = Release|x86
36 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Debug|arm64.ActiveCfg = Debug|arm64
39 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Debug|arm64.Build.0 = Debug|arm64
40 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Debug|x86.ActiveCfg = Debug|x86
41 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Debug|x86.Build.0 = Debug|x86
42 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Release|arm64.ActiveCfg = Release|arm64
45 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Release|arm64.Build.0 = Release|arm64
46 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Release|x86.ActiveCfg = Release|x86
47 | {17478673-FB35-4FF3-8EA2-9B2849B490BD}.Release|x86.Build.0 = Release|x86
48 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Debug|arm64.ActiveCfg = Debug|Any CPU
51 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Debug|arm64.Build.0 = Debug|Any CPU
52 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Debug|x86.ActiveCfg = Debug|Any CPU
53 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Debug|x86.Build.0 = Debug|Any CPU
54 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Release|arm64.ActiveCfg = Release|Any CPU
57 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Release|arm64.Build.0 = Release|Any CPU
58 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Release|x86.ActiveCfg = Release|Any CPU
59 | {FB118D8F-18E1-4B77-9882-4EE77469CB8D}.Release|x86.Build.0 = Release|Any CPU
60 | EndGlobalSection
61 | GlobalSection(SolutionProperties) = preSolution
62 | HideSolutionNode = FALSE
63 | EndGlobalSection
64 | GlobalSection(ExtensibilityGlobals) = postSolution
65 | SolutionGuid = {D6B55750-5329-496A-8EAD-898A2B73D370}
66 | EndGlobalSection
67 | GlobalSection(SharedMSBuildProjectFiles) = preSolution
68 | VisualChatGPTStudioShared\VisualChatGPTStudioShared.projitems*{17478673-fb35-4ff3-8ea2-9b2849b490bd}*SharedItemsImports = 4
69 | VisualChatGPTStudioShared\VisualChatGPTStudioShared.projitems*{8d02bb3e-2996-4b5c-a4be-c1514b7b93df}*SharedItemsImports = 13
70 | VisualChatGPTStudioShared\VisualChatGPTStudioShared.projitems*{e0b7c5ac-2e05-4849-81e4-8bf62bbcd16a}*SharedItemsImports = 4
71 | EndGlobalSection
72 | EndGlobal
73 |
--------------------------------------------------------------------------------
/VisualChatGPTStudio2019/Icon2019.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/VisualChatGPTStudio2019/Icon2019.png
--------------------------------------------------------------------------------
/VisualChatGPTStudio2019/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio;
2 | using System.Reflection;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle(Vsix.Name)]
6 | [assembly: AssemblyDescription(Vsix.Description)]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany(Vsix.Author)]
9 | [assembly: AssemblyProduct(Vsix.Name)]
10 | [assembly: AssemblyCopyright(Vsix.Author)]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: AssemblyVersion(Vsix.Version)]
17 | [assembly: AssemblyFileVersion(Vsix.Version)]
18 |
19 | namespace System.Runtime.CompilerServices
20 | {
21 | public class IsExternalInit { }
22 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudio2019/Resources/Icon2019.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/VisualChatGPTStudio2019/Resources/Icon2019.png
--------------------------------------------------------------------------------
/VisualChatGPTStudio2019/source.extension.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by the extension VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | internal sealed partial class Vsix
9 | {
10 | public const string Id = "VisuallChatGPTStudio.4854bc98-735d-4622-a0cf-30454b50aa0f";
11 | public const string Name = "VisuallChatGPTStudio";
12 | public const string Description = @"Empty VSIX Project.";
13 | public const string Language = "en-US";
14 | public const string Version = "1.0";
15 | public const string Author = "Avanade";
16 | public const string Tags = "";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/VisualChatGPTStudio2019/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Visual chatGPT Studio 2019
6 | Visual Studio extension that integrates advanced AI capabilities, enabling tasks like code suggestions, bug detection, optimization, unit test generation, and more directly within the development environment.
7 | Icon2019.png
8 | Resources\Icon.png
9 | Visual Studio, chatGPT, CoPilot, OpenAI
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Agents/ApiAgent/ApiItem.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace VisualChatGPTStudioShared.Agents.ApiAgent
4 | {
5 | ///
6 | /// Represents an API definition.
7 | ///
8 | public class ApiItem
9 | {
10 | ///
11 | /// API definition ID
12 | ///
13 | public string Id { get; set; }
14 |
15 | ///
16 | /// Gets or sets the API's name.
17 | ///
18 | public string Name { get; set; }
19 |
20 | ///
21 | /// Gets or sets the API's base URL.
22 | ///
23 | public string BaseUrl { get; set; }
24 |
25 | ///
26 | /// If true, all responses will be send to AI, when false, only HTTP status will be send.
27 | ///
28 | public bool SendResponsesToAI { get; set; }
29 |
30 | ///
31 | /// Gets or sets the collection of API tag items.
32 | ///
33 | public List Tags { get; set; }
34 |
35 | ///
36 | /// Gets or sets the API's definition.
37 | ///
38 | public string Definition { get; set; }
39 | }
40 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Agents/ApiAgent/ApiTagItem.cs:
--------------------------------------------------------------------------------
1 | namespace VisualChatGPTStudioShared.Agents.ApiAgent
2 | {
3 | ///
4 | /// Represents a tag used in an API context.
5 | ///
6 | public class ApiTagItem
7 | {
8 | private int type;
9 |
10 | ///
11 | /// Gets or sets the tag key.
12 | ///
13 | public string Key { get; set; }
14 |
15 | ///
16 | /// Gets or sets the tag value.
17 | ///
18 | public string Value { get; set; }
19 |
20 | ///
21 | /// Gets or sets the type of the API tag, represented by the enumeration.
22 | ///
23 | public ApiTagType Type
24 | {
25 | get
26 | {
27 | return (ApiTagType)type;
28 | }
29 | set
30 | {
31 | type = (int)value;
32 | }
33 | }
34 |
35 | ///
36 | /// Gets or sets the type as an integer.
37 | ///
38 | public int TypeAsInteger
39 | {
40 | get
41 | {
42 | return type;
43 | }
44 | set
45 | {
46 | type = value;
47 | }
48 | }
49 | }
50 |
51 | ///
52 | /// Represents the types of API tags, such as Header or QueryString, used for categorizing API parameters.
53 | ///
54 | public enum ApiTagType
55 | {
56 | Header = 0,
57 | QueryString = 1
58 | }
59 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/AddComments.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.AddComments)]
9 | internal sealed class AddComments : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | if (CodeContainsMultipleLines(selectedText))
14 | {
15 | return CommandType.Replace;
16 | }
17 |
18 | return CommandType.InsertBefore;
19 | }
20 |
21 | protected override string GetCommand(string selectedText)
22 | {
23 | if (CodeContainsMultipleLines(selectedText))
24 | {
25 | return OptionsCommands.GetCommandAsync(CommandsType.AddCommentsForLines).Result;
26 | }
27 |
28 | return OptionsCommands.GetCommandAsync(CommandsType.AddCommentsForLine).Result;
29 | }
30 |
31 | private bool CodeContainsMultipleLines(string code)
32 | {
33 | return code.Contains("\r\n") || code.Contains("\n") || code.Contains("\r");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/AddSummary.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.AddSummary)]
9 | internal sealed class AddSummary : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.InsertBefore;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | string command = OptionsCommands.GetCommandAsync(CommandsType.AddSummary).Result;
19 |
20 | if (string.IsNullOrWhiteSpace(command))
21 | {
22 | return string.Empty;
23 | }
24 |
25 | return TextFormat.FormatCommandForSummary($"{command}\r\n\r\n{{0}}\r\n\r\n", selectedText);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/AddTests.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using EnvDTE;
3 | using JeffPires.VisualChatGPTStudio.Commands;
4 | using JeffPires.VisualChatGPTStudio.Options.Commands;
5 | using JeffPires.VisualChatGPTStudio.Utils;
6 |
7 | namespace JeffPires.VisualChatGPTStudio
8 | {
9 | [Command(PackageIds.AddTests)]
10 | internal sealed class AddTests : BaseGenericCommand
11 | {
12 | protected override CommandType GetCommandType(string selectedText)
13 | {
14 | return CommandType.InsertAfter;
15 | }
16 |
17 | protected override string GetCommand(string selectedText)
18 | {
19 | return OptionsCommands.GetCommandAsync(CommandsType.AddTests).Result + Utils.Constants.PROVIDE_ONLY_CODE_INSTRUCTION;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/AskAnything.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Utils;
4 |
5 | namespace JeffPires.VisualChatGPTStudio
6 | {
7 | [Command(PackageIds.AskAnything)]
8 | internal sealed class AskAnything : BaseGenericCommand
9 | {
10 | protected override CommandType GetCommandType(string selectedText)
11 | {
12 | return CommandType.InsertAfter;
13 | }
14 |
15 | protected override string GetCommand(string selectedText)
16 | {
17 | return OptionsGeneral.ToolWindowSystemMessage;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/BaseCommand.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using EnvDTE;
3 | using JeffPires.VisualChatGPTStudio.Options;
4 | using JeffPires.VisualChatGPTStudio.Options.Commands;
5 | using Microsoft.VisualStudio.Shell;
6 | using System;
7 | using System.Threading;
8 | using Constants = JeffPires.VisualChatGPTStudio.Utils.Constants;
9 |
10 | namespace JeffPires.VisualChatGPTStudio.Commands
11 | {
12 | ///
13 | /// Base abstract class for commands
14 | ///
15 | /// The type of the command.
16 | internal abstract class BaseCommand : Community.VisualStudio.Toolkit.BaseCommand where TCommand : class, new()
17 | {
18 | ///
19 | /// Gets or sets the cancellation token source.
20 | ///
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 |
33 | ///
34 | /// Gets the OptionsGeneral property of the VisualChatGPTStudioPackage.
35 | ///
36 | protected OptionPageGridGeneral OptionsGeneral
37 | {
38 | get
39 | {
40 | return ((VisuallChatGPTStudioPackage)this.Package).OptionsGeneral;
41 | }
42 | }
43 |
44 | ///
45 | /// Gets the OptionsCommands property of the VisualChatGPTStudioPackage.
46 | ///
47 | protected OptionCommands OptionsCommands
48 | {
49 | get
50 | {
51 | return ((VisuallChatGPTStudioPackage)this.Package).OptionsCommands;
52 | }
53 | }
54 |
55 | ///
56 | /// Gets the DTE object.
57 | ///
58 | /// The DTE object.
59 | protected async System.Threading.Tasks.Task GetDTEAsync()
60 | {
61 | return await VS.GetServiceAsync();
62 | }
63 |
64 | ///
65 | /// Validates the API key stored in the OptionsGeneral class.
66 | ///
67 | ///
68 | /// Returns true if the API key is valid, false otherwise.
69 | ///
70 | protected bool ValidateAPIKey()
71 | {
72 | if (OptionsGeneral.AzureEntraIdAuthentication)
73 | {
74 | return true;
75 | }
76 |
77 | if (string.IsNullOrWhiteSpace(OptionsGeneral.ApiKey))
78 | {
79 | System.Windows.Forms.MessageBox.Show(Constants.MESSAGE_SET_API_KEY, Constants.EXTENSION_NAME);
80 |
81 | Package.ShowOptionPage(typeof(OptionPageGridGeneral));
82 |
83 | return false;
84 | }
85 |
86 | return true;
87 | }
88 |
89 | ///
90 | /// Validates the code selected by the user.
91 | ///
92 | /// The selected code.
93 | /// True if the code is valid, false otherwise.
94 | protected bool ValidateCodeSelected(string selectedCode)
95 | {
96 | if (string.IsNullOrWhiteSpace(selectedCode))
97 | {
98 | System.Windows.Forms.MessageBox.Show("Please select the code.", Constants.EXTENSION_NAME);
99 |
100 | return false;
101 | }
102 |
103 | return true;
104 | }
105 |
106 | ///
107 | /// Formats the document.
108 | ///
109 | protected async System.Threading.Tasks.Task FormatDocumentAsync()
110 | {
111 | try
112 | {
113 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
114 |
115 | (await GetDTEAsync()).ExecuteCommand(Constants.EDIT_DOCUMENT_COMMAND);
116 | }
117 | catch (Exception) //Some documents do not support formatting
118 | {
119 |
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/Cancel.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
using Microsoft.VisualStudio.Shell;
namespace JeffPires.VisualChatGPTStudio.Commands
{
2 | ///
3 | /// Command to cancel all another commands that is running.
4 | ///
5 | [Command(PackageIds.Cancel)]
internal sealed class Cancel : BaseCommand
{
6 | ///
7 | /// Executes the command asynchronously.
8 | ///
9 | protected override async System.Threading.Tasks.Task ExecuteAsync(OleMenuCmdEventArgs e)
{
CancellationTokenSource?.Cancel();
}
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/Complete.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using EnvDTE;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio.Commands
7 | {
8 | [Command(PackageIds.Complete)]
9 | internal sealed class Complete : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.InsertAfter;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | if (string.IsNullOrWhiteSpace(selectedText))
19 | {
20 | return string.Empty;
21 | }
22 |
23 | return TextFormat.FormatForCompleteCommand(OptionsCommands.GetCommandAsync(CommandsType.Complete).Result + Utils.Constants.PROVIDE_ONLY_CODE_INSTRUCTION, docView.FilePath);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/CustomAfter.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.CustomAfter)]
9 | internal sealed class CustomAfter : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.InsertAfter;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | return OptionsCommands.GetCommandAsync(CommandsType.CustomAfter).Result;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/CustomBefore.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.CustomBefore)]
9 | internal sealed class CustomBefore : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.InsertBefore;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | return OptionsCommands.GetCommandAsync(CommandsType.CustomBefore).Result;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/CustomReplace.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.CustomReplace)]
9 | internal sealed class CustomReplace : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.Replace;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | return OptionsCommands.GetCommandAsync(CommandsType.CustomReplace).Result;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/Explain.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.Explain)]
9 | internal sealed class Explain : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.InsertBefore;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | return OptionsCommands.GetCommandAsync(CommandsType.Explain).Result;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/FindBugs.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.FindBugs)]
9 | internal sealed class FindBugs : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.InsertAfter;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | return OptionsCommands.GetCommandAsync(CommandsType.FindBugs).Result;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/Optimize.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options.Commands;
4 | using JeffPires.VisualChatGPTStudio.Utils;
5 |
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | [Command(PackageIds.Optimize)]
9 | internal sealed class Optimize : BaseGenericCommand
10 | {
11 | protected override CommandType GetCommandType(string selectedText)
12 | {
13 | return CommandType.Replace;
14 | }
15 |
16 | protected override string GetCommand(string selectedText)
17 | {
18 | return OptionsCommands.GetCommandAsync(CommandsType.Optimize).Result + Utils.Constants.PROVIDE_ONLY_CODE_INSTRUCTION;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/OptimizeDiffView.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Options.Commands;
3 | using JeffPires.VisualChatGPTStudio.Utils;
4 | using JeffPires.VisualChatGPTStudio.Utils.API;
5 | using Microsoft.VisualStudio.Shell;
6 | using System;
7 | using System.Threading;
8 | using System.Windows.Forms;
9 | using VisualChatGPTStudioShared.Utils;
10 |
11 | namespace JeffPires.VisualChatGPTStudio.Commands
12 | {
13 | ///
14 | /// Command to add summary for the entire class.
15 | ///
16 | [Command(PackageIds.OptimizeDiffView)]
17 | internal sealed class OptimizeDiffView : BaseCommand
18 | {
19 | ///
20 | /// Executes the ChatGPT optimization process for the selected code and shows on a diff view.
21 | ///
22 | protected override async System.Threading.Tasks.Task ExecuteAsync(OleMenuCmdEventArgs e)
23 | {
24 | try
25 | {
26 | if (!ValidateAPIKey())
27 | {
28 | return;
29 | }
30 |
31 | string command = await OptionsCommands.GetCommandAsync(CommandsType.Optimize);
32 |
33 | if (string.IsNullOrWhiteSpace(command))
34 | {
35 | System.Windows.MessageBox.Show(string.Format(Constants.MESSAGE_SET_COMMAND, nameof(Optimize)), Constants.EXTENSION_NAME);
36 |
37 | return;
38 | }
39 |
40 | DocumentView docView = await VS.Documents.GetActiveDocumentViewAsync();
41 |
42 | string selectedText = docView.TextView.Selection.StreamSelectionSpan.GetText();
43 |
44 | if (!ValidateCodeSelected(selectedText))
45 | {
46 | return;
47 | }
48 |
49 | await VS.StatusBar.ShowProgressAsync(Constants.MESSAGE_WAITING_CHATGPT, 1, 2);
50 |
51 | CancellationTokenSource = new CancellationTokenSource();
52 |
53 | string result = OptionsGeneral.UseCompletion && OptionsGeneral.Service == OpenAIService.OpenAI
54 | ? await ApiHandler.GetCompletionResponseAsync(OptionsGeneral, command + Constants.PROVIDE_ONLY_CODE_INSTRUCTION, selectedText, OptionsGeneral.StopSequences?.Split([','], StringSplitOptions.RemoveEmptyEntries), CancellationTokenSource.Token)
55 | : await ApiHandler.GetResponseAsync(OptionsGeneral, command + Constants.PROVIDE_ONLY_CODE_INSTRUCTION, selectedText, OptionsGeneral.StopSequences?.Split([','], StringSplitOptions.RemoveEmptyEntries), CancellationTokenSource.Token);
56 |
57 | result = TextFormat.RemoveCodeTagsFromOpenAIResponses(result.ToString());
58 |
59 | await DiffView.ShowDiffViewAsync(docView.FilePath, selectedText, result);
60 |
61 | await VS.StatusBar.ShowProgressAsync(Constants.MESSAGE_WAITING_CHATGPT, 2, 2);
62 | }
63 | catch (Exception ex)
64 | {
65 | await VS.StatusBar.ShowProgressAsync(ex.Message, 2, 2);
66 |
67 | if (ex is not OperationCanceledException)
68 | {
69 | Logger.Log(ex);
70 |
71 | System.Windows.Forms.MessageBox.Show(ex.Message, Constants.EXTENSION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning);
72 | }
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/TerminalWindowCodeReviewCommand.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.ToolWindows;
2 | using Microsoft.VisualStudio.Shell;
3 | using System;
4 | using System.ComponentModel.Design;
5 |
6 | namespace JeffPires.VisualChatGPTStudio.Commands
7 | {
8 | ///
9 | /// Command handler
10 | ///
11 | internal sealed class TerminalWindowCodeReviewCommand
12 | {
13 | ///
14 | /// Command ID.
15 | ///
16 | public const int CommandId = 259;
17 |
18 | ///
19 | /// Command menu group (command set GUID).
20 | ///
21 | public static readonly Guid CommandSet = new("8b0b1a54-4655-4dae-8984-022f82a739f2");
22 |
23 | ///
24 | /// VS Package that provides this command, not null.
25 | ///
26 | private readonly AsyncPackage package;
27 |
28 | ///
29 | /// Initializes a new instance of the class.
30 | /// Adds our command handlers for menu (commands must exist in the command table file)
31 | ///
32 | /// Owner package, not null.
33 | /// Command service to add command to, not null.
34 | private TerminalWindowCodeReviewCommand(AsyncPackage package, OleMenuCommandService commandService)
35 | {
36 | this.package = package ?? throw new ArgumentNullException(nameof(package));
37 | commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
38 |
39 | CommandID menuCommandID = new(CommandSet, CommandId);
40 | MenuCommand menuItem = new(this.Execute, menuCommandID);
41 | commandService.AddCommand(menuItem);
42 | }
43 |
44 | ///
45 | /// Gets the instance of the command.
46 | ///
47 | public static TerminalWindowCodeReviewCommand Instance
48 | {
49 | get;
50 | private set;
51 | }
52 |
53 | ///
54 | /// Initializes the singleton instance of the command.
55 | ///
56 | /// Owner package, not null.
57 | public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
58 | {
59 | // Switch to the main thread - the call to AddCommand in TerminalWindowCommand's constructor requires
60 | // the UI thread.
61 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
62 |
63 | OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
64 | Instance = new TerminalWindowCodeReviewCommand(package, commandService);
65 | }
66 |
67 | ///
68 | /// Shows the tool window when the menu item is clicked.
69 | ///
70 | /// The event sender.
71 | /// The event args.
72 | private void Execute(object sender, EventArgs e)
73 | {
74 | _ = this.package.JoinableTaskFactory.RunAsync(async delegate
75 | {
76 | await package.ShowToolWindowAsync(typeof(TerminalWindowCodeReview), 0, true, package.DisposalToken);
77 | });
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/TerminalWindowCommand.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.ToolWindows;
2 | using Microsoft.VisualStudio.Shell;
3 | using System;
4 | using System.ComponentModel.Design;
5 |
6 | namespace JeffPires.VisualChatGPTStudio.Commands
7 | {
8 | ///
9 | /// Command handler
10 | ///
11 | internal sealed class TerminalWindowCommand
12 | {
13 | ///
14 | /// Command ID.
15 | ///
16 | public const int CommandId = 256;
17 |
18 | ///
19 | /// Command menu group (command set GUID).
20 | ///
21 | public static readonly Guid CommandSet = new("8b0b1a54-4655-4dae-8984-022f82a739f2");
22 |
23 | ///
24 | /// VS Package that provides this command, not null.
25 | ///
26 | private readonly AsyncPackage package;
27 |
28 | ///
29 | /// Initializes a new instance of the class.
30 | /// Adds our command handlers for menu (commands must exist in the command table file)
31 | ///
32 | /// Owner package, not null.
33 | /// Command service to add command to, not null.
34 | private TerminalWindowCommand(AsyncPackage package, OleMenuCommandService commandService)
35 | {
36 | this.package = package ?? throw new ArgumentNullException(nameof(package));
37 | commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
38 |
39 | CommandID menuCommandID = new(CommandSet, CommandId);
40 | MenuCommand menuItem = new(this.Execute, menuCommandID);
41 | commandService.AddCommand(menuItem);
42 | }
43 |
44 | ///
45 | /// Gets the instance of the command.
46 | ///
47 | public static TerminalWindowCommand Instance
48 | {
49 | get;
50 | private set;
51 | }
52 |
53 | ///
54 | /// Initializes the singleton instance of the command.
55 | ///
56 | /// Owner package, not null.
57 | public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
58 | {
59 | // Switch to the main thread - the call to AddCommand in TerminalWindowCommand's constructor requires
60 | // the UI thread.
61 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
62 |
63 | OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
64 | Instance = new TerminalWindowCommand(package, commandService);
65 | }
66 |
67 | ///
68 | /// Sends a request to the ChatGPT window.
69 | ///
70 | /// The command to send to the ChatGPT window.
71 | /// The selected text to be sent.
72 | public async System.Threading.Tasks.Task RequestToWindowAsync(string command, string selectedText)
73 | {
74 | TerminalWindow window = await package.ShowToolWindowAsync(typeof(TerminalWindow), 0, true, package.DisposalToken) as TerminalWindow;
75 |
76 | if (window == null)
77 | {
78 | throw new Exception("Please, open the tool window first.");
79 | }
80 |
81 | await window.RequestToWindowAsync(command, selectedText);
82 | }
83 |
84 | ///
85 | /// Shows the tool window when the menu item is clicked.
86 | ///
87 | /// The event sender.
88 | /// The event args.
89 | private void Execute(object sender, EventArgs e)
90 | {
91 | _ = this.package.JoinableTaskFactory.RunAsync(async delegate
92 | {
93 | await package.ShowToolWindowAsync(typeof(TerminalWindow), 0, true, package.DisposalToken);
94 | });
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/TerminalWindowTurboCommand.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.ToolWindows.Turbo;
2 | using Microsoft.VisualStudio.Shell;
3 | using System;
4 | using System.ComponentModel.Design;
5 |
6 | namespace JeffPires.VisualChatGPTStudio.Commands
7 | {
8 | ///
9 | /// Command handler
10 | ///
11 | internal sealed class TerminalWindowTurboCommand
12 | {
13 | ///
14 | /// Command ID.
15 | ///
16 | public const int CommandId = 257;
17 |
18 | ///
19 | /// Command menu group (command set GUID).
20 | ///
21 | public static readonly Guid CommandSet = new Guid("8b0b1a54-4655-4dae-8984-022f82a739f2");
22 |
23 | ///
24 | /// VS Package that provides this command, not null.
25 | ///
26 | private readonly AsyncPackage package;
27 |
28 | ///
29 | /// Initializes a new instance of the class.
30 | /// Adds our command handlers for menu (commands must exist in the command table file)
31 | ///
32 | /// Owner package, not null.
33 | /// Command service to add command to, not null.
34 | private TerminalWindowTurboCommand(AsyncPackage package, OleMenuCommandService commandService)
35 | {
36 | this.package = package ?? throw new ArgumentNullException(nameof(package));
37 | commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
38 |
39 | CommandID menuCommandID = new CommandID(CommandSet, CommandId);
40 | MenuCommand menuItem = new MenuCommand(this.Execute, menuCommandID);
41 | commandService.AddCommand(menuItem);
42 | }
43 |
44 | ///
45 | /// Gets the instance of the command.
46 | ///
47 | public static TerminalWindowTurboCommand Instance
48 | {
49 | get;
50 | private set;
51 | }
52 |
53 | ///
54 | /// Initializes the singleton instance of the command.
55 | ///
56 | /// Owner package, not null.
57 | public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
58 | {
59 | // Switch to the main thread - the call to AddCommand in TerminalWindowTurboCommand's constructor requires
60 | // the UI thread.
61 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
62 |
63 | OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
64 | Instance = new TerminalWindowTurboCommand(package, commandService);
65 | }
66 |
67 | ///
68 | /// Shows the tool window when the menu item is clicked.
69 | ///
70 | /// The event sender.
71 | /// The event args.
72 | private void Execute(object sender, EventArgs e)
73 | {
74 | _ = this.package.JoinableTaskFactory.RunAsync(async delegate
75 | {
76 | await package.ShowToolWindowAsync(typeof(TerminalWindowTurbo), 0, true, package.DisposalToken);
77 | });
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Commands/Translate.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio;
3 | using JeffPires.VisualChatGPTStudio.Commands;
4 | using JeffPires.VisualChatGPTStudio.Options.Commands;
5 | using JeffPires.VisualChatGPTStudio.Utils;
6 |
7 | namespace VisualChatGPTStudioShared.Commands
8 | {
9 | [Command(PackageIds.Translate)]
10 | internal sealed class Translate : BaseGenericCommand
11 | {
12 | protected override CommandType GetCommandType(string selectedText)
13 | {
14 | return CommandType.Replace;
15 | }
16 |
17 | protected override string GetCommand(string selectedText)
18 | {
19 | return OptionsCommands.GetCommandAsync(CommandsType.Translate).Result;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Options/ApiAgent/OptionApiAgent.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.Options.ApiAgent;
2 | using Microsoft.VisualStudio.Shell;
3 | using System.Runtime.InteropServices;
4 | using System.Windows;
5 |
6 | namespace VisualChatGPTStudioShared.Options.ApiAgent
7 | {
8 | ///
9 | /// Represents a handling options within a UI element dialog page for the Agents APIs.
10 | ///
11 | [ComVisible(true)]
12 | public class OptionApiAgent : UIElementDialogPage
13 | {
14 | protected override UIElement Child
15 | {
16 | get
17 | {
18 | return new OptionApiAgentWindow();
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Options/Commands/Commands.cs:
--------------------------------------------------------------------------------
1 | namespace JeffPires.VisualChatGPTStudio.Options.Commands
{
2 | ///
3 | /// Represents a class that contains various commands.
4 | ///
5 | public class Commands
{
public string ProjectName { get; set; } = "SetProjectName";
public string Complete { get; set; }
public string AddTests { get; set; }
public string FindBugs { get; set; }
public string Optimize { get; set; }
public string Explain { get; set; }
public string AddSummary { get; set; }
public string AddCommentsForLine { get; set; }
public string AddCommentsForLines { get; set; }
public string Translate { get; set; }
public string CustomBefore { get; set; }
public string CustomAfter { get; set; }
public string CustomReplace { get; set; }
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Options/Commands/OptionCommandsWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Options/Commands/OptionCommandsWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Constants = JeffPires.VisualChatGPTStudio.Utils.Constants;
using MessageBox = System.Windows.MessageBox;
using UserControl = System.Windows.Controls.UserControl;
namespace JeffPires.VisualChatGPTStudio.Options.Commands
{
3 | ///
4 | /// Represents a user control for displaying and interacting with option commands.
5 | ///
6 | public partial class OptionCommandsWindow : UserControl
{
7 | #region Delegates
8 | ///
9 | /// Delegate for updating a list of commands.
10 | ///
11 | /// The list of commands to update.
12 | public delegate void DelegateUpdateCommands(List commands);
public event DelegateUpdateCommands EventUpdateCommands;
13 |
14 | #endregion Delegates
15 | #region Properties
16 | private readonly string originalCommands;
17 | private List commands;
18 |
19 | #endregion Properties
20 | #region Constructors
21 | ///
22 | /// Initializes a new instance of the OptionCommandsWindow class.
23 | ///
24 | /// The list of commands to display.
25 | public OptionCommandsWindow(List commands)
{
this.InitializeComponent();
this.originalCommands = JsonConvert.SerializeObject(commands);
this.commands = commands;
grdCommands.ItemsSource = this.commands;
}
26 |
27 | #endregion Constructors
28 | #region Event Handlers
29 | ///
30 | /// Handles the click event of the Cancel button.
31 | ///
32 | private void Cancel_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Cancel all changes?", Constants.EXTENSION_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
{
return;
}
commands = JsonConvert.DeserializeObject>(originalCommands);
grdCommands.ItemsSource = commands;
}
33 |
34 | ///
35 | /// Removes the selected command from the grid.
36 | ///
37 | private void RemoveCommand_Click(object sender, RoutedEventArgs e)
{
Commands selectCommands = grdCommands.SelectedItem as Commands;
if (selectCommands == null)
{
MessageBox.Show("Please, select a line to be removed.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
if (commands.Count == 1)
{
MessageBox.Show("Must have at least one commands line.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
38 |
39 | if (string.IsNullOrWhiteSpace(selectCommands.ProjectName))
40 | {
41 | MessageBox.Show("Remove the default commands are not allowed.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
42 | }
43 |
44 | if (MessageBox.Show("Remove the line?", Constants.EXTENSION_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
{
return;
}
commands.Remove(selectCommands);
grdCommands.Items.Refresh();
}
45 |
46 | ///
47 | /// Event handler for the AddCommand button click event. Adds a new Commands object to the commands collection and refreshes the grid view.
48 | ///
49 | private void AddCommand_Click(object sender, RoutedEventArgs e)
{
commands.Add(new Commands());
grdCommands.Items.Refresh();
}
50 |
51 | ///
52 | /// Saves the commands and updates the command list.
53 | ///
54 | /// The object that raised the event.
55 | /// The event arguments.
56 | private void SaveCommands_Click(object sender, RoutedEventArgs e)
{
try
{
if (commands.Count(c => string.IsNullOrWhiteSpace(c.ProjectName)) != 1)
{
MessageBox.Show("Must have only one default commands without specifying the project name.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
if (commands.GroupBy(c => c.ProjectName).Where(c => c.Count() > 1).Any())
{
MessageBox.Show("Lines with the same Project name are not allowed.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
EventUpdateCommands?.Invoke(commands);
MessageBox.Show("Commands updated successfully.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
Logger.Log(ex);
MessageBox.Show(ex.Message, Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
57 |
58 | #endregion Event Handlers
59 | }
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/CodeReview/CodeReviewItem.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
namespace VisualChatGPTStudioShared.ToolWindows.CodeReview
{
2 | ///
3 | /// Represents an item for code review that notifies when a property changes.
4 | ///
5 | public class CodeReviewItem : INotifyPropertyChanged
{
6 | public event PropertyChangedEventHandler PropertyChanged;
7 |
8 | ///
9 | /// Gets or sets the name of the file.
10 | ///
11 | public string FileName { get; set; }
12 |
13 | ///
14 | /// Gets or sets the file path.
15 | ///
16 | public string FilePath { get; set; }
17 |
18 | ///
19 | /// Gets or sets the code review details.
20 | ///
21 | public string CodeReview { get; set; }
22 |
23 | ///
24 | /// Gets or sets the original code.
25 | ///
26 | public string OriginalCode { get; set; }
27 |
28 | ///
29 | /// Gets or sets the altered code.
30 | ///
31 | public string AlteredCode { get; set; }
private bool isExpanded;
32 |
33 | ///
34 | /// Gets or sets a value indicating whether the item is expanded.
35 | ///
36 | ///
37 | /// When set, if the current value differs from the provided value, it triggers a property changed notification.
38 | ///
39 | public bool IsExpanded
{
get
{
return isExpanded;
}
set
{
if (isExpanded != value)
{
isExpanded = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsExpanded)));
}
}
}
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/CodeReview/TerminalWindowCodeReview.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace JeffPires.VisualChatGPTStudio.ToolWindows
6 | {
7 | ///
8 | /// This class implements the tool window exposed by this package and hosts a user control.
9 | ///
10 | ///
11 | /// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
12 | /// usually implemented by the package implementer.
13 | ///
14 | /// This class derives from the ToolWindowPane class provided from the MPF in order to use its
15 | /// implementation of the IVsUIElementPane interface.
16 | ///
17 | ///
18 | [Guid("3CF59F3B-AB43-4723-A204-C1473A2C7F44")]
19 | public class TerminalWindowCodeReview : ToolWindowPane
20 | {
21 | ///
22 | /// Initializes a new instance of the class.
23 | ///
24 | public TerminalWindowCodeReview() : base(null)
25 | {
26 | this.Caption = "Visual chatGPT Studio Code Review";
27 |
28 | // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
29 | // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
30 | // the object returned by the Content property.
31 | this.Content = new TerminalWindowCodeReviewControl();
32 | }
33 |
34 | protected override void OnCreate()
35 | {
36 | base.OnCreate();
37 |
38 | ((TerminalWindowCodeReviewControl)this.Content).StartControl(((VisuallChatGPTStudioPackage)this.Package).OptionsGeneral);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/SolutionContext/TerminalWindowSolutionContext.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace JeffPires.VisualChatGPTStudio.ToolWindows
6 | {
7 | ///
8 | /// This class implements the tool window exposed by this package and hosts a user control.
9 | ///
10 | ///
11 | /// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
12 | /// usually implemented by the package implementer.
13 | ///
14 | /// This class derives from the ToolWindowPane class provided from the MPF in order to use its
15 | /// implementation of the IVsUIElementPane interface.
16 | ///
17 | ///
18 | [Guid("0AAD7BCB-A453-468F-9F00-73DE72C01A15")]
19 | public class TerminalWindowSolutionContext : ToolWindowPane
20 | {
21 | ///
22 | /// Initializes a new instance of the class.
23 | ///
24 | public TerminalWindowSolutionContext() : base(null)
25 | {
26 | this.Caption = "Visual chatGPT Studio Solution Context";
27 |
28 | // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
29 | // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
30 | // the object returned by the Content property.
31 | this.Content = new TerminalWindowSolutionContextControl();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/SolutionContext/TerminalWindowSolutionContextControl.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | Here you can add project items to the context of requests to OpenAI.
41 | Ideal for making requests that require knowledge of other points of the project.
42 |
43 |
44 |
52 |
53 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/TerminalWindow/TerminalWindow.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System;
3 | using System.Runtime.InteropServices;
4 | using Package = Microsoft.VisualStudio.Shell.Package;
5 |
6 | namespace JeffPires.VisualChatGPTStudio.ToolWindows
7 | {
8 | ///
9 | /// This class implements the tool window exposed by this package and hosts a user control.
10 | ///
11 | ///
12 | /// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
13 | /// usually implemented by the package implementer.
14 | ///
15 | /// This class derives from the ToolWindowPane class provided from the MPF in order to use its
16 | /// implementation of the IVsUIElementPane interface.
17 | ///
18 | ///
19 | [Guid("904d9a5a-bbb5-47da-9531-d910e81fa928")]
20 | public class TerminalWindow : ToolWindowPane
21 | {
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | public TerminalWindow() : base(null)
26 | {
27 | this.Caption = "Visual chatGPT Studio";
28 |
29 | // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
30 | // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
31 | // the object returned by the Content property.
32 | this.Content = new TerminalWindowControl();
33 | }
34 |
35 | protected override void OnCreate()
36 | {
37 | base.OnCreate();
38 |
39 | ((TerminalWindowControl)this.Content).StartControl(((VisuallChatGPTStudioPackage)this.Package).OptionsGeneral, (Package)this.Package);
40 | }
41 |
42 | ///
43 | /// Sends a request to the ChatGPT window.
44 | ///
45 | /// The command to send to the ChatGPT window.
46 | /// The selected text to be sent.
47 | public async System.Threading.Tasks.Task RequestToWindowAsync(string command, string selectedText)
48 | {
49 | await ((TerminalWindowControl)this.Content).RequestToWindowAsync(command, selectedText);
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/TerminalWindowHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 | using System.Windows.Automation;
4 | using System.Windows.Controls;
5 | using System.Windows.Media.Imaging;
6 |
7 | namespace JeffPires.VisualChatGPTStudio.ToolWindows
8 | {
9 | ///
10 | /// Helper class for the terminal windows
11 | ///
12 | public static class TerminalWindowHelper
13 | {
14 | ///
15 | /// Copies the given text to the clipboard and updates the given image to show a checkmark and tooltip indicating the text has been copied. After 2 seconds, the image is updated back to its original state.
16 | ///
17 | /// The image to update.
18 | /// The text to copy to the clipboard.
19 | public static void Copy(Image image, string text)
20 | {
21 | Clipboard.SetText(text);
22 |
23 | image.Source = new BitmapImage(new Uri("pack://application:,,,/VisualChatGPTStudio;component/Resources/check.png"));
24 | image.ToolTip = "Copied!";
25 | image.IsEnabled = false;
26 |
27 | AutomationProperties.SetHelpText(image, "Copied!");
28 |
29 | System.Timers.Timer timer = new(2000) { Enabled = true };
30 |
31 | timer.Elapsed += (s, args) =>
32 | {
33 | Application.Current.Dispatcher.Invoke(new Action(() =>
34 | {
35 | image.Source = new BitmapImage(new Uri("pack://application:,,,/VisualChatGPTStudio;component/Resources/copy.png"));
36 | image.ToolTip = "Copy code";
37 | image.IsEnabled = true;
38 |
39 | AutomationProperties.SetHelpText(image, "Copy code");
40 | }));
41 |
42 | timer.Enabled = false;
43 | timer.Dispose();
44 | };
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ChatEntity.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.ToolWindows.Turbo;
using System;
using System.Collections.Generic;
namespace VisualChatGPTStudioShared.ToolWindows.Turbo
{
2 | ///
3 | /// Represents the Turbo Chat.
4 | ///
5 | public class ChatEntity
{
6 | ///
7 | /// The Chat ID
8 | ///
9 | public string Id { get; set; }
10 |
11 | ///
12 | /// The Chat Name
13 | ///
14 | public string Name { get; set; }
15 |
16 | ///
17 | /// Chat's creation date
18 | ///
19 | public DateTime Date { get; set; }
20 |
21 | ///
22 | /// Chat Messages
23 | ///
24 | public List Messages { get; set; }
}
25 |
26 | ///
27 | /// Represents a Turbo Chat message.
28 | ///
29 | public class MessageEntity
{
30 | ///
31 | /// Indicates the message order
32 | ///
33 | public int Order { get; set; }
34 |
35 | ///
36 | /// The message segments.
37 | ///
38 | public List Segments { get; set; }
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ChatListControlItem.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.Utils;
2 |
3 | namespace JeffPires.VisualChatGPTStudio.ToolWindows.Turbo
4 | {
5 | ///
6 | /// Represents an item on the ucChat ListControl.
7 | ///
8 | public class ChatListControlItem
9 | {
10 | public string ImageSource { get; private set; }
11 |
12 | public string Text { get; set; }
13 |
14 | public int Index { get; set; }
15 |
16 | ///
17 | /// Constructor for ChatTurboItem class.
18 | ///
19 | /// Author of the message.
20 | /// Message content.
21 | public ChatListControlItem(AuthorEnum author, string message)
22 | {
23 | Text = TextFormat.AdjustCodeLanguage(message);
24 |
25 | if (author == AuthorEnum.Me)
26 | {
27 | ImageSource = "pack://application:,,,/VisualChatGPTStudio;component/Resources/vs.png";
28 | }
29 | else if (author == AuthorEnum.ChatGPT)
30 | {
31 | ImageSource = "pack://application:,,,/VisualChatGPTStudio;component/Resources/chatGPT.png";
32 | }
33 | else if (author == AuthorEnum.ApiResult)
34 | {
35 | ImageSource = "pack://application:,,,/VisualChatGPTStudio;component/Resources/api.png";
36 | }
37 | }
38 | }
39 |
40 | public enum AuthorEnum
41 | {
42 | Me,
43 | ChatGPT,
44 | ChatGPTCode,
45 | FunctionCall,
46 | FunctionRequest,
47 | ApiResult
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ChatMessageSegment.cs:
--------------------------------------------------------------------------------
1 | namespace JeffPires.VisualChatGPTStudio.ToolWindows.Turbo
2 | {
3 | ///
4 | /// This class represents a chat message segment.
5 | ///
6 | public class ChatMessageSegment
7 | {
8 | ///
9 | /// Segment author.
10 | ///
11 | public AuthorEnum Author { get; set; }
12 |
13 | ///
14 | /// The message content.
15 | ///
16 | public string Content { get; set; }
17 |
18 | ///
19 | /// To Control the segment position by the start.
20 | ///
21 | public int SegmentOrderStart { get; set; }
22 |
23 | ///
24 | /// To Control the segment position by the end.
25 | ///
26 | public int SegmentOrderEnd { get; set; }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ChatUserControlsItem.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
using VisualChatGPTStudioShared.ToolWindows.Turbo;
2 |
3 | namespace JeffPires.VisualChatGPTStudio.ToolWindows.Turbo
{
4 | ///
5 | /// This class keep the items and controls chat references
6 | ///
7 | internal class ChatUserControlsItem
{
8 | ///
9 | /// The Chat Entity.
10 | ///
11 | public ChatEntity Chat { get; set; }
12 |
13 | ///
14 | /// Gets or sets the chat header user control.
15 | ///
16 | public ucChatHeader Header { get; set; }
17 |
18 | ///
19 | /// Gets or sets the TabItem associated with this chat.
20 | ///
21 | public TabItem TabItem { get; set; }
22 |
23 | ///
24 | /// Gets or sets the ucChatItem object representing a chat item in the chat list.
25 | ///
26 | public ucChatItem ListItem { get; set; }
///
27 | /// Indicates if this chat item was opened before
28 | ///
public bool OpenedBefore { get; set; }
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/TerminalWindowTurbo.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace JeffPires.VisualChatGPTStudio.ToolWindows.Turbo
5 | {
6 | ///
7 | /// This class implements the tool window exposed by this package and hosts a user control.
8 | ///
9 | ///
10 | /// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
11 | /// usually implemented by the package implementer.
12 | ///
13 | /// This class derives from the ToolWindowPane class provided from the MPF in order to use its
14 | /// implementation of the IVsUIElementPane interface.
15 | ///
16 | ///
17 | [Guid("51d8ca1e-4698-404c-a37b-a4a41603557b")]
18 | public class TerminalWindowTurbo : ToolWindowPane
19 | {
20 | ///
21 | /// Initializes a new instance of the class.
22 | ///
23 | public TerminalWindowTurbo() : base(null)
24 | {
25 | this.Caption = "Visual chatGPT Studio Turbo";
26 |
27 | // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
28 | // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
29 | // the object returned by the Content property.
30 | this.Content = new TerminalWindowTurboControl();
31 | }
32 |
33 | protected override void OnCreate()
34 | {
35 | base.OnCreate();
36 |
37 | ((TerminalWindowTurboControl)this.Content).StartControl(((VisuallChatGPTStudioPackage)this.Package).OptionsGeneral, (Package)this.Package);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ucChatHeader.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
28 |
29 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ucChatHeader.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
using System.Windows.Controls;
namespace JeffPires.VisualChatGPTStudio.ToolWindows.Turbo
{
2 | ///
3 | /// Represents a user control for the header section of a chat window.
4 | ///
5 | public partial class ucChatHeader : UserControl
{
6 | #region Properties
7 | private readonly TerminalWindowTurboControl parentControl;
8 |
9 | #endregion Properties
10 | #region Constructors
11 | ///
12 | /// Initializes a new instance of the ucChatHeader class.
13 | ///
14 | /// The parent control of the ucChatHeader.
15 | /// The header text to be displayed.
16 | public ucChatHeader(TerminalWindowTurboControl parentControl, string chatName)
{
this.InitializeComponent();
this.parentControl = parentControl;
lblHeader.Text = chatName;
}
17 |
18 | #endregion Constructors
19 | #region Event Handlers
20 | ///
21 | /// Event handler for the btnClose button click event. Closes the current tab by calling the CloseTab method of the parent control.
22 | ///
23 | /// The object that raised the event.
24 | /// The event arguments.
25 | private void btnClose_Click(object sender, RoutedEventArgs e)
{
parentControl.CloseTab(this);
}
26 |
27 | #endregion Event Handlers
28 | #region Methods
29 | ///
30 | /// Updates the text of the header label with the specified value.
31 | ///
32 | /// The new text for the header label.
33 | public void UpdateChatName(string chatName)
{
lblHeader.Text = chatName;
}
34 |
35 | #endregion Methods
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ucChatItem.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
28 |
37 |
38 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/ToolWindows/Turbo/ucChatItem.xaml.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.Utils;
2 | using Microsoft.VisualStudio.Shell;
3 | using System;
4 | using System.Windows;
5 | using System.Windows.Controls;
6 | using System.Windows.Input;
7 |
8 | namespace JeffPires.VisualChatGPTStudio.ToolWindows.Turbo
9 | {
10 | ///
11 | /// Represents a user control for displaying a chat item in a chat interface.
12 | ///
13 | public partial class ucChatItem : UserControl
14 | {
15 | #region Properties
16 |
17 | private readonly TerminalWindowTurboControl parentControl;
18 |
19 | #endregion Properties
20 |
21 | #region Constructors
22 |
23 | ///
24 | /// Initializes a new instance of the ucChatItem class.
25 | ///
26 | /// The parent TerminalWindowTurboControl.
27 | /// The name of the chat item.
28 | public ucChatItem(TerminalWindowTurboControl parentControl, string chatName)
29 | {
30 | this.InitializeComponent();
31 |
32 | this.parentControl = parentControl;
33 | lblName.Text = chatName;
34 | }
35 |
36 | #endregion Constructors
37 |
38 | ///
39 | /// This method returns the chat name so screen readers can announce it.
40 | ///
41 | ///
42 | /// A string representing the chat name.
43 | ///
44 | public override string ToString()
45 | {
46 | return lblName.Text;
47 | }
48 |
49 | #region Event Handlers
50 |
51 | ///
52 | /// Event handler for the click event of the delete image button.
53 | ///
54 | /// The object that raised the event.
55 | /// The MouseEventArgs containing event data.
56 | public void imgDelete_Click(object sender, MouseEventArgs e)
57 | {
58 | if (!imgDelete.IsEnabled)
59 | {
60 | return;
61 | }
62 |
63 | if (MessageBox.Show($"Delete the chat \"{lblName.Text}\"?", Constants.EXTENSION_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
64 | {
65 | parentControl.DeleteChat(this);
66 | }
67 | }
68 |
69 | ///
70 | /// Event handler for the click event of the imgEdit control.
71 | ///
72 | /// The object that raised the event.
73 | /// The MouseEventArgs containing event data.
74 | public async void imgEdit_Click(object sender, MouseEventArgs e)
75 | {
76 | if (!imgEdit.IsEnabled)
77 | {
78 | return;
79 | }
80 |
81 | txtName.Width = lblName.ActualWidth;
82 | txtName.Text = lblName.Text;
83 |
84 | SetEditModeAsync(true);
85 |
86 | await Dispatcher.BeginInvoke(new Action(() =>
87 | {
88 | txtName.Focus();
89 | }), System.Windows.Threading.DispatcherPriority.Background);
90 | }
91 |
92 | ///
93 | /// Event handler for the PreviewKeyDown event of the txtName TextBox.
94 | ///
95 | /// The object that raised the event.
96 | /// The KeyEventArgs containing information about the key that was pressed.
97 | private async void txtName_PreviewKeyDown(object sender, KeyEventArgs e)
98 | {
99 | if (e.Key == Key.Escape)
100 | {
101 | SetEditModeAsync(false);
102 | }
103 |
104 | if (e.Key != Key.Enter)
105 | {
106 | return;
107 | }
108 |
109 | string newName = txtName.Text.Trim();
110 |
111 | if (lblName.Text == newName)
112 | {
113 | SetEditModeAsync(false);
114 |
115 | return;
116 | }
117 |
118 | if (string.IsNullOrWhiteSpace(txtName.Text))
119 | {
120 | MessageBox.Show("The name can not be null.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
121 |
122 | return;
123 | }
124 |
125 | bool result = parentControl.SetChatNewName(this, newName);
126 |
127 | if (!result)
128 | {
129 | MessageBox.Show("Already have an item with this name.", Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
130 |
131 | return;
132 | }
133 |
134 | lblName.Text = newName;
135 |
136 | SetEditModeAsync(false);
137 | }
138 |
139 | ///
140 | /// Event handler for when the TxtName textbox loses focus.
141 | /// It hides the TxtName textbox and shows the lblName label.
142 | /// It also enables the imgDelete and imgEdit images.
143 | ///
144 | private void TxtName_LostFocus(object sender, RoutedEventArgs e)
145 | {
146 | SetEditModeAsync(false);
147 | }
148 |
149 | ///
150 | /// Sets the edit mode for the chat item asynchronously, toggling visibility of the text box and label,
151 | /// and enabling or disabling the delete and edit image controls accordingly.
152 | ///
153 | /// True to enable edit mode; false to disable it.
154 | private async void SetEditModeAsync(bool isEditing)
155 | {
156 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
157 |
158 | txtName.Visibility = isEditing ? Visibility.Visible : Visibility.Collapsed;
159 | lblName.Visibility = isEditing ? Visibility.Collapsed : Visibility.Visible;
160 |
161 | imgDelete.IsEnabled = !isEditing;
162 | imgEdit.IsEnabled = !isEditing;
163 | }
164 |
165 | #endregion Event Handlers
166 | }
167 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/CommandImage.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace VisualChatGPTStudioShared.Utils
{
2 | ///
3 | /// Represents an image control that can be used as a command button.
4 | ///
5 | public class CommandImage : Image
{
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(CommandImage), new PropertyMetadata(null));
6 |
7 | ///
8 | /// Gets or sets the command associated with this control.
9 | ///
10 | public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
11 |
12 | ///
13 | /// Overrides the OnMouseLeftButtonDown method to execute the Command if it is not null and can be executed.
14 | ///
15 | /// The MouseButtonEventArgs parameter.
16 | protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
if (Command != null && Command.CanExecute(null))
{
Command.Execute(null);
}
}
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/Constants.cs:
--------------------------------------------------------------------------------
1 | namespace JeffPires.VisualChatGPTStudio.Utils
2 | {
3 | ///
4 | /// Contains constants used throughout the application.
5 | ///
6 | public static class Constants
7 | {
8 | public const string EDIT_DOCUMENT_COMMAND = "Edit.FormatDocument";
9 |
10 | public const string EXTENSION_NAME = "Visual chatGPT Studio";
11 | public const string EXTENSION_NAME_UNDERLINED = "Visual_chatGPT_Studio";
12 | public const string MESSAGE_SET_API_KEY = "Please, set the OpenAI API key.";
13 | public const string MESSAGE_WAITING_CHATGPT = "Visual chatGPT Studio - Waiting API response... (Alt+Z To Cancel)";
14 | public const string MESSAGE_WAITING_COPILOT = "Visual chatGPT Studio Copilot - Fetching suggestion...";
15 | public const string MESSAGE_WRITE_REQUEST = "Please write a request.";
16 | public const string MESSAGE_SET_COMMAND = "Please, set the command for \"{0}\" through the Options.";
17 | public const string PROVIDE_ONLY_CODE_INSTRUCTION = ". Please, only provide the code without additional comments or text.";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/DiffView.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using EnvDTE;
3 | using Microsoft.VisualStudio.Shell;
4 |
5 | namespace VisualChatGPTStudioShared.Utils
6 | {
7 | ///
8 | /// Provides functionality to compare and display differences between two versions of code.
9 | ///
10 | public static class DiffView
11 | {
12 | ///
13 | /// Shows a diff view of two strings of code.
14 | ///
15 | /// The original code.
16 | /// The optimized code.
17 | public static async System.Threading.Tasks.Task ShowDiffViewAsync(string filePath, string originalCode, string optimizedCode)
18 | {
19 | string extension = System.IO.Path.GetExtension(filePath).TrimStart('.');
20 |
21 | string tempFolder = System.IO.Path.GetTempPath();
22 | string tempFilePath1 = System.IO.Path.Combine(tempFolder, $"Original.{extension}");
23 | string tempFilePath2 = System.IO.Path.Combine(tempFolder, $"Optimized.{extension}");
24 |
25 | System.IO.File.WriteAllText(tempFilePath1, originalCode);
26 | System.IO.File.WriteAllText(tempFilePath2, optimizedCode);
27 |
28 | DTE dte = await VS.GetServiceAsync();
29 |
30 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
31 |
32 | dte.ExecuteCommand("Tools.DiffFiles", $"\"{tempFilePath1}\" \"{tempFilePath2}\"");
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/EnumHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
using System.Reflection;
namespace JeffPires.VisualChatGPTStudio.Utils
{
2 | ///
3 | /// A helper class for working with enums in C#.
4 | ///
5 | public static class EnumHelper
{
6 | ///
7 | /// Gets the string value associated with the specified enum item.
8 | ///
9 | /// The enum item.
10 | /// The string value associated with the enum item.
11 | public static string GetStringValue(this Enum enumItem)
{
string enumStringValue = string.Empty;
Type type = enumItem.GetType();
FieldInfo objFieldInfo = type.GetField(enumItem.ToString());
EnumStringValue[] enumStringValues = objFieldInfo.GetCustomAttributes(typeof(EnumStringValue), false) as EnumStringValue[];
if (enumStringValues.Length > 0)
{
enumStringValue = enumStringValues[0].Value;
}
return enumStringValue;
}
}
12 |
13 | ///
14 | /// Represents an attribute that can be used to associate a string value with an enum value.
15 | ///
16 | public class EnumStringValue : Attribute
{
private readonly string value;
17 |
18 | ///
19 | /// Initializes a new instance of the EnumStringValue class with the specified value.
20 | ///
21 | /// The value of the EnumStringValue.
22 | public EnumStringValue(string value)
{
this.value = value;
}
23 |
24 | ///
25 | /// Gets the value of the property.
26 | ///
27 | /// The value of the property.
28 | public string Value
{
get
{
return value;
}
}
}
}
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/Enums.cs:
--------------------------------------------------------------------------------
1 | namespace JeffPires.VisualChatGPTStudio.Utils
2 | {
3 | ///
4 | /// Represents the different types of requests that can be used.
5 | ///
6 | enum RequestType
7 | {
8 | Code = 0,
9 | Request = 1
10 | }
11 |
12 | ///
13 | /// Enum to represent the different types of commands that can be used.
14 | ///
15 | enum CommandType
16 | {
17 | Replace,
18 | InsertBefore,
19 | InsertAfter
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/GitChanges.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using EnvDTE;
3 | using JeffPires.VisualChatGPTStudio.Utils;
4 | using LibGit2Sharp;
5 | using Microsoft.VisualStudio.Shell;
6 | using System;
7 | using System.Text;
8 |
9 | namespace VisualChatGPTStudioShared.Utils
10 | {
11 | ///
12 | /// Provides functionality to Git changes.
13 | ///
14 | public static class GitChanges
15 | {
16 | ///
17 | /// Retrieves the current changes in the Git repository of the solution, including file changes and their statuses.
18 | ///
19 | public static string GetCurrentChangesAsString()
20 | {
21 | string repositoryPath = GetSolutionGitRepositoryPath();
22 |
23 | if (string.IsNullOrWhiteSpace(repositoryPath))
24 | {
25 | throw new ArgumentNullException(nameof(repositoryPath));
26 | }
27 |
28 | StringBuilder result = new();
29 |
30 | using (Repository repo = new(repositoryPath))
31 | {
32 | // Capture the differences between the index (staging area) and the working directory
33 | Patch changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory);
34 |
35 | foreach (PatchEntryChanges change in changes)
36 | {
37 | result.AppendLine($"File: {change.Path}");
38 | result.AppendLine($"Status: {change.Status}");
39 | result.AppendLine("Changes:");
40 | result.AppendLine(change.Patch);
41 | result.AppendLine();
42 | }
43 | }
44 |
45 | return result.ToString();
46 | }
47 |
48 | ///
49 | /// Retrieves the current changes in the Git repository of the solution as a patch.
50 | ///
51 | /// A Patch object representing the current changes.
52 | public static Patch GetCurrentChanges()
53 | {
54 | string repositoryPath = GetSolutionGitRepositoryPath();
55 |
56 | if (string.IsNullOrWhiteSpace(repositoryPath))
57 | {
58 | throw new ArgumentNullException(nameof(repositoryPath));
59 | }
60 |
61 | using (Repository repo = new(repositoryPath))
62 | {
63 | // Capture the differences between the index (staging area) and the working directory
64 | return repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory);
65 | }
66 | }
67 |
68 | ///
69 | /// Separates the given git changes into original and altered code.
70 | ///
71 | /// The string containing git changes.
72 | /// The output string containing the original code.
73 | /// The output string containing the altered code.
74 | public static void SeparateCodeChanges(string gitChanges, out string originalCode, out string alteredCode)
75 | {
76 | originalCode = string.Empty;
77 | alteredCode = string.Empty;
78 |
79 | string[] lines = TextFormat.SplitTextByLine(gitChanges);
80 |
81 | foreach (string line in lines)
82 | {
83 | // Filters out rows that should not be included in the final result
84 | if (line.StartsWith("---") || line.StartsWith("+++") || line.Contains("diff --git") || line.StartsWith("@@") || line.StartsWith("index "))
85 | {
86 | continue;
87 | }
88 |
89 | // Check if the line is original code (-)
90 | if (line.StartsWith("-"))
91 | {
92 | originalCode += line.Substring(1) + Environment.NewLine; // Remove the prefix '-' and add it to the original code string.
93 | }
94 | // Check if the line is of modified code (+)
95 | else if (line.StartsWith("+"))
96 | {
97 | alteredCode += line.Substring(1) + Environment.NewLine; // Remove the '+' prefix and add it to the modified code string
98 | }
99 | // For unchanged lines
100 | else
101 | {
102 | originalCode += line + Environment.NewLine; // Add the line to the original code
103 | alteredCode += line + Environment.NewLine; // Add the line to the modified code
104 | }
105 | }
106 | }
107 |
108 | ///
109 | /// Retrieves the file system path of the Git repository that contains the currently opened solution in Visual Studio.
110 | ///
111 | ///
112 | /// The file system path of the Git repository containing the solution, or an empty string if the solution is not part of a Git repository.
113 | ///
114 | public static string GetSolutionGitRepositoryPath()
115 | {
116 | ThreadHelper.ThrowIfNotOnUIThread();
117 |
118 | DTE dte = VS.GetServiceAsync().Result;
119 |
120 | System.IO.DirectoryInfo directoryInfo = new(System.IO.Path.GetDirectoryName(dte.Solution.FullName));
121 |
122 | while (directoryInfo?.Parent != null)
123 | {
124 | string path = System.IO.Path.Combine(directoryInfo.FullName, ".git");
125 | if (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))
126 | {
127 | return directoryInfo.FullName;
128 | }
129 |
130 | directoryInfo = directoryInfo.Parent;
131 | }
132 |
133 | return string.Empty;
134 | }
135 | }
136 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/HighlightingDefinitionConverter.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.AvalonEdit.Highlighting;
2 | using System;
3 | using System.Globalization;
4 | using System.Windows.Data;
5 |
6 | namespace JeffPires.VisualChatGPTStudio.Utils
7 | {
8 | ///
9 | /// Syntax binding converter for the AvalonEdit
10 | ///
11 | public class HighlightingDefinitionConverter : IValueConverter
12 | {
13 | private static readonly HighlightingDefinitionTypeConverter Converter = new();
14 |
15 | ///
16 | /// Converts an object to a specified type.
17 | ///
18 | /// The object to convert.
19 | /// The type to convert the object to.
20 | /// A parameter to use during the conversion.
21 | /// The culture to use during the conversion.
22 | /// The converted object.
23 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
24 | {
25 | return Converter.ConvertFrom(value);
26 | }
27 |
28 | ///
29 | /// Converts a value.
30 | ///
31 | /// The value that is produced by the binding target.
32 | /// The type to convert to.
33 | /// The converter parameter to use.
34 | /// The culture to use in the converter.
35 | ///
36 | /// A converted value. If the method returns , the valid null value is used.
37 | ///
38 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
39 | {
40 | return Converter.ConvertToString(value);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/Http/ChatGPTHttpClientFactory.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.Options;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Net;
6 | using System.Net.Http;
7 | using System.Net.Security;
8 |
9 | namespace JeffPires.VisualChatGPTStudio.Utils.Http
10 | {
11 | ///
12 | /// This class provides a factory for creating HttpClient instances for use with the ChatGPT API.
13 | ///
14 | class ChatGPTHttpClientFactory : IHttpClientFactory
15 | {
16 | private readonly Dictionary httpClients = new();
17 | private static readonly object objLock = new();
18 | private readonly OptionPageGridGeneral options;
19 |
20 | public string Proxy { get; private set; }
21 |
22 | ///
23 | /// Initializes a new instance of the ChatGPTHttpClientFactory class.
24 | ///
25 | /// The options for configuring the HttpClient.
26 | public ChatGPTHttpClientFactory(OptionPageGridGeneral options)
27 | {
28 | this.options = options;
29 | }
30 |
31 | ///
32 | /// Creates an HttpClient with the given name.
33 | ///
34 | /// The name of the HttpClient.
35 | /// The created HttpClient.
36 | public HttpClient CreateClient(string name)
37 | {
38 | if (!httpClients.TryGetValue(name, out HttpClientCustom client))
39 | {
40 | lock (objLock)
41 | {
42 | if (!httpClients.TryGetValue(name, out client))
43 | {
44 | client = CreateHttpClient(CreateMessageHandler());
45 | httpClients.Add(name, client);
46 | }
47 | }
48 | }
49 |
50 | if (client.IsDisposed)
51 | {
52 | httpClients.Remove(name);
53 | return CreateClient(name);
54 | }
55 |
56 | return client;
57 | }
58 |
59 | ///
60 | /// Sets the proxy for the HttpClient.
61 | ///
62 | /// The proxy to set.
63 | public void SetProxy(string proxy)
64 | {
65 | if (proxy != Proxy)
66 | {
67 | Proxy = proxy;
68 |
69 | KeyValuePair[] list = httpClients.ToArray();
70 |
71 | foreach (KeyValuePair item in list)
72 | {
73 | item.Value.Dispose();
74 | httpClients.Remove(item.Key);
75 | }
76 | }
77 | }
78 |
79 | ///
80 | /// Creates an HttpClient with the specified message handler and default settings.
81 | ///
82 | /// The message handler.
83 | /// An HttpClient with the specified message handler and default settings.
84 | protected HttpClientCustom CreateHttpClient(HttpMessageHandler handler)
85 | {
86 | HttpClientCustom lookHttp = new(handler);
87 |
88 | lookHttp.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
89 | lookHttp.DefaultRequestHeaders.Connection.Add("keep-alive");
90 | lookHttp.Timeout = new TimeSpan(0, 0, 120);
91 |
92 | return lookHttp;
93 | }
94 |
95 | ///
96 | /// Creates an HttpMessageHandler with the specified proxy settings.
97 | ///
98 | /// An HttpMessageHandler with the specified proxy settings.
99 | protected HttpMessageHandler CreateMessageHandler()
100 | {
101 | HttpClientHandler handler = new RequestCaptureHandler(options)
102 | {
103 | AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
104 | UseCookies = true,
105 | AllowAutoRedirect = true,
106 | ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => {
107 | if (sslPolicyErrors == SslPolicyErrors.None)
108 | {
109 | return true;
110 | }
111 |
112 | // Do not allow this client to communicate with unauthenticated servers.
113 | return false;
114 | },
115 | MaxConnectionsPerServer = 256,
116 | SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls
117 | };
118 |
119 | if (!string.IsNullOrWhiteSpace(Proxy))
120 | {
121 | handler.Proxy = new WebProxy(new Uri(Proxy));
122 | }
123 |
124 | return handler;
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/Http/HttpClientCustom.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Http;
2 |
3 | namespace JeffPires.VisualChatGPTStudio.Utils.Http
4 | {
5 | ///
6 | /// This class is a custom implementation of the HttpClient class.
7 | ///
8 | class HttpClientCustom : HttpClient
9 | {
10 | ///
11 | /// Checks if the object has been disposed.
12 | ///
13 | public bool IsDisposed { get; private set; }
14 |
15 | ///
16 | /// Initializes a new instance of the HttpClientCustom class with the specified HttpMessageHandler and streaming flag.
17 | ///
18 | /// The HttpMessageHandler to use for sending HTTP requests.
19 | public HttpClientCustom(HttpMessageHandler handler) : base(handler) { }
20 |
21 | ///
22 | /// Disposes the object and releases any associated resources.
23 | ///
24 | /// A boolean value indicating whether to dispose managed resources.
25 | protected override void Dispose(bool disposing)
26 | {
27 | IsDisposed = true;
28 | base.Dispose(disposing);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/Http/HttpLogs.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Net.Http;
3 | using System.Threading.Tasks;
4 |
5 | namespace VisualChatGPTStudioShared.Utils.Http
6 | {
7 | ///
8 | /// Represents a class for handling HTTP logs, which may include logging HTTP requests, responses, and related metadata.
9 | ///
10 | public class HttpLogs
11 | {
12 | ///
13 | /// Logs the details of an HTTP request, including URI, method, headers, and content if available.
14 | ///
15 | public static async Task LogRequestAsync(HttpRequestMessage request)
16 | {
17 | Logger.Log($"Request URI: {request.RequestUri}");
18 | Logger.Log($"Request Method: {request.Method}");
19 | Logger.Log("Request Headers:");
20 |
21 | foreach (KeyValuePair> header in request.Headers)
22 | {
23 | Logger.Log($"{header.Key}: {string.Join(", ", header.Value)}");
24 | }
25 |
26 | if (request.Content != null)
27 | {
28 | string content = await request.Content.ReadAsStringAsync();
29 |
30 | Logger.Log("Request Content: " + content);
31 | }
32 |
33 | Logger.Log(new string('_', 100));
34 | }
35 |
36 | ///
37 | /// Logs the details of an HTTP response, including headers, status code, and content (if available).
38 | ///
39 | public static async Task LogResponseAsync(HttpResponseMessage response)
40 | {
41 | if (response == null)
42 | {
43 | return;
44 | }
45 |
46 | Logger.Log("Response Headers:");
47 |
48 | foreach (KeyValuePair> header in response.Headers)
49 | {
50 | Logger.Log($"{header.Key}: {string.Join(", ", header.Value)}");
51 | }
52 |
53 | Logger.Log($"Response Status Code: {response.StatusCode}");
54 |
55 | if (response.Content != null)
56 | {
57 | string content = await response.Content.ReadAsStringAsync();
58 |
59 | Logger.Log("Response Content: " + content);
60 | }
61 |
62 | Logger.Log(new string('_', 100));
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/Http/RequestCaptureHandler.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.Options;
2 | using Microsoft.Identity.Client;
3 | using Microsoft.Identity.Client.Extensions.Msal;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Net.Http;
9 | using System.Threading;
10 | using System.Threading.Tasks;
11 | using VisualChatGPTStudioShared.Utils.Http;
12 |
13 | namespace JeffPires.VisualChatGPTStudio.Utils.Http
14 | {
15 | ///
16 | /// Represents a custom HTTP client handler that captures the request data.
17 | ///
18 | /// The app options.
19 | public class RequestCaptureHandler(OptionPageGridGeneral options) : HttpClientHandler
20 | {
21 | ///
22 | /// Overrides the SendAsync method to log the request and response information.
23 | ///
24 | /// The HTTP request message.
25 | /// The cancellation token.
26 | /// The HTTP response message.
27 | protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
28 | {
29 | if (options.AzureEntraIdAuthentication)
30 | {
31 | await LoginAzureApiByEntraIdAsync(request);
32 | }
33 |
34 | request.Headers.Remove("User-Agent");
35 |
36 | request.Headers.Add("User-Agent", Constants.EXTENSION_NAME_UNDERLINED);
37 |
38 | string content;
39 |
40 | if (options.LogRequests)
41 | {
42 | await HttpLogs.LogRequestAsync(request);
43 | }
44 |
45 | HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
46 |
47 | if (options.LogResponses)
48 | {
49 | await HttpLogs.LogResponseAsync(response);
50 | }
51 |
52 | return response;
53 | }
54 |
55 | ///
56 | /// Logs in to Azure API using Entra ID, handling token acquisition through both cache and interactive login methods.
57 | ///
58 | /// The HTTP request message to which the authorization header will be added.
59 | private async Task LoginAzureApiByEntraIdAsync(HttpRequestMessage request)
60 | {
61 | if (string.IsNullOrWhiteSpace(options.AzureEntraIdApplicationId))
62 | {
63 | throw new ArgumentNullException("Application Id", "When choosing to authenticate with Entra ID, you need to define the Application ID.");
64 | }
65 |
66 | if (string.IsNullOrWhiteSpace(options.AzureEntraIdTenantId))
67 | {
68 | throw new ArgumentNullException("Tenant Id", "When choosing to authenticate with Entra ID, you need to define the Tenant ID.");
69 | }
70 |
71 | string[] scopes = ["https://cognitiveservices.azure.com/.default"];
72 |
73 | IPublicClientApplication app = PublicClientApplicationBuilder.Create(options.AzureEntraIdApplicationId)
74 | .WithAuthority(AzureCloudInstance.AzurePublic, options.AzureEntraIdTenantId)
75 | .WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
76 | .Build();
77 |
78 | //Set up token cache persistence in file
79 | StorageCreationProperties storageProperties = new StorageCreationPropertiesBuilder(
80 | "msal_cache.dat", // File name
81 | Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Constants.EXTENSION_NAME)) // Path to save
82 | .Build();
83 |
84 | MsalCacheHelper cacheHelper = await MsalCacheHelper.CreateAsync(storageProperties);
85 |
86 | cacheHelper.RegisterCache(app.UserTokenCache);
87 |
88 | AuthenticationResult result;
89 |
90 | try
91 | {
92 | //Try to obtain the user's token from the cache
93 | IEnumerable accounts = await app.GetAccountsAsync();
94 |
95 | result = await app.AcquireTokenSilent(scopes, accounts.FirstOrDefault()).ExecuteAsync();
96 | }
97 | catch (Exception)
98 | {
99 | //If there is no valid token in cache, request interactive login.
100 | result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();
101 | }
102 |
103 | request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", result.AccessToken);
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/Utils/Repositories/Repository.cs:
--------------------------------------------------------------------------------
1 | using JeffPires.VisualChatGPTStudio.Utils;
2 | using SQLite;
3 | using System;
4 | using System.IO;
5 |
6 | namespace VisualChatGPTStudioShared.Utils.Repositories
7 | {
8 | ///
9 | /// Provides methods and functionality for data access and management within the application.
10 | ///
11 | internal static class Repository
12 | {
13 | #region Methods
14 |
15 | ///
16 | /// Creates and initializes a SQLite database connection. Ensures the database file is located in a specific folder within the local application data directory.
17 | /// If the folder does not exist, it is created.
18 | ///
19 | ///
20 | /// A new instance of SQLiteConnection pointing to the database file.
21 | ///
22 | public static SQLiteConnection CreateDataBaseAndConnection()
23 | {
24 | string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Constants.EXTENSION_NAME);
25 |
26 | string filePath = Path.Combine(folder, "VisualChatGptStudio.db");
27 |
28 | if (!Directory.Exists(folder))
29 | {
30 | Directory.CreateDirectory(folder);
31 | }
32 |
33 | return new(filePath);
34 | }
35 |
36 | #endregion Methods
37 | }
38 | }
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/VisualChatGPTStudioShared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 8d02bb3e-2996-4b5c-a4be-c1514b7b93df
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/VisualChatGPTStudioShared/VisuallChatGPTStudioPackage.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using JeffPires.VisualChatGPTStudio.Commands;
3 | using JeffPires.VisualChatGPTStudio.Options;
4 | using JeffPires.VisualChatGPTStudio.Options.Commands;
5 | using JeffPires.VisualChatGPTStudio.ToolWindows;
6 | using JeffPires.VisualChatGPTStudio.ToolWindows.Turbo;
7 | using JeffPires.VisualChatGPTStudio.Utils;
8 | using Microsoft.VisualStudio.Shell;
9 | using System;
10 | using System.Runtime.InteropServices;
11 | using System.Threading;
12 | using VisualChatGPTStudioShared.Options.ApiAgent;
13 |
14 | namespace JeffPires.VisualChatGPTStudio
15 | {
16 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
17 | [InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
18 | [ProvideMenuResource("Menus.ctmenu", 1)]
19 | [Guid(PackageGuids.VisuallChatGPTStudioString)]
20 | [ProvideOptionPage(typeof(OptionPageGridGeneral), "Visual chatGPT Studio", "General", 0, 0, true)]
21 | [ProvideProfile(typeof(OptionPageGridGeneral), "Visual chatGPT Studio", "General", 0, 0, true)]
22 | [ProvideOptionPage(typeof(OptionCommands), "Visual chatGPT Studio", "Commands", 1, 1, true)]
23 | [ProvideProfile(typeof(OptionCommands), "Visual chatGPT Studio", "Commands", 1, 1, true)]
24 | [ProvideOptionPage(typeof(OptionApiAgent), "Visual chatGPT Studio", "API Agent", 2, 2, true)]
25 | [ProvideProfile(typeof(OptionApiAgent), "Visual chatGPT Studio", "API Agent", 2, 2, true)]
26 | [ProvideToolWindow(typeof(TerminalWindow))]
27 | [ProvideToolWindow(typeof(TerminalWindowTurbo))]
28 | [ProvideToolWindow(typeof(TerminalWindowSolutionContext))]
29 | [ProvideToolWindow(typeof(TerminalWindowCodeReview))]
30 | public sealed class VisuallChatGPTStudioPackage : ToolkitPackage
31 | {
32 | ///
33 | /// Gets or sets the cancellation token source.
34 | ///
35 | public CancellationTokenSource CancellationTokenSource { get; set; }
36 |
37 | ///
38 | /// Gets the OptionPageGridGeneral object.
39 | ///
40 | public OptionPageGridGeneral OptionsGeneral
41 | {
42 | get
43 | {
44 | return (OptionPageGridGeneral)GetDialogPage(typeof(OptionPageGridGeneral));
45 | }
46 | }
47 |
48 | ///
49 | /// Retrieves the instance of the associated with the dialog page.
50 | ///
51 | ///
52 | /// The instance obtained from the dialog page.
53 | ///
54 | public OptionCommands OptionsCommands
55 | {
56 | get
57 | {
58 | return (OptionCommands)GetDialogPage(typeof(OptionCommands));
59 | }
60 | }
61 |
62 | ///
63 | /// Retrieves the instance of the associated with the dialog page.
64 | ///
65 | ///
66 | /// The instance obtained from the dialog page.
67 | ///
68 | public OptionApiAgent OptionApiAgent
69 | {
70 | get
71 | {
72 | return (OptionApiAgent)GetDialogPage(typeof(OptionApiAgent));
73 | }
74 | }
75 |
76 | ///
77 | /// Initializes the terminal window commands.
78 | ///
79 | protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress progress)
80 | {
81 | Logger.Initialize(this, Constants.EXTENSION_NAME);
82 |
83 | await this.RegisterCommandsAsync();
84 | await TerminalWindowCommand.InitializeAsync(this);
85 | await TerminalWindowTurboCommand.InitializeAsync(this);
86 | await TerminalWindowSolutionContextCommand.InitializeAsync(this);
87 | await TerminalWindowCodeReviewCommand.InitializeAsync(this);
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/icons8-chatgpt-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/icons8-chatgpt-512.png
--------------------------------------------------------------------------------
/lib/osx-arm64/libgit2-a2bde63.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/lib/osx-arm64/libgit2-a2bde63.dylib
--------------------------------------------------------------------------------
/lib/win32/arm64/git2-a2bde63.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/lib/win32/arm64/git2-a2bde63.dll
--------------------------------------------------------------------------------
/lib/win32/x64/git2-a2bde63.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/lib/win32/x64/git2-a2bde63.dll
--------------------------------------------------------------------------------
/lib/win32/x86/git2-a2bde63.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeffdapaz/VisualChatGPTStudio/2c3bd8d3d4b0320af2f014519e38b5b32b3f9bca/lib/win32/x86/git2-a2bde63.dll
--------------------------------------------------------------------------------
/source.extension.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by the extension VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace JeffPires.VisualChatGPTStudio
7 | {
8 | internal sealed partial class Vsix
9 | {
10 | public const string Id = "VisuallChatGPTStudio.4854bc98-735d-4622-a0cf-30454b50aa0f";
11 | public const string Name = "VisuallChatGPTStudio";
12 | public const string Description = @"Empty VSIX Project.";
13 | public const string Language = "en-US";
14 | public const string Version = "1.0";
15 | public const string Author = "Avanade";
16 | public const string Tags = "";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Visual chatGPT Studio
6 | Visual Studio extension that integrates advanced AI capabilities, enabling tasks like code suggestions, bug detection, optimization, unit test generation, and more directly within the development environment.
7 | icons8-chatgpt-512.png
8 | Resources\Icon.png
9 | chatGPT, CoPilot, OpenAI, Visual Studio
10 |
11 |
12 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------