Unreal OpenAI API 1.0.0
ChatGPTWidget.h
1// OpenAI, Copyright LifeEXE. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "EditorUtilityWidget.h"
7#include "UI/ChatMessageWidget.h"
8#include "Provider/Types/ModelTypes.h"
9#include "Provider/Types/CommonTypes.h"
10#include "ChatGPT/BaseService.h"
11#include "ChatGPTWidget.generated.h"
12
13class UVerticalBox;
14class UScrollBox;
15class UEditableText;
16class UButton;
18class UComboBoxString;
19class UChatGPT;
20class UServiceWidget;
21class UGridPanel;
22class USaveSettings;
23class UTextBlock;
25
26UCLASS(BlueprintType)
27class OPENAIEDITOR_API UChatGPTWidget : public UEditorUtilityWidget
28{
29 GENERATED_BODY()
30
31protected:
32 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "OpenAI")
33 int32 MaxTokens{2000};
34
35protected:
36 UPROPERTY(meta = (BindWidget))
37 TObjectPtr<UVerticalBox> StartVerticalBox;
38
39 UPROPERTY(meta = (BindWidget))
40 TObjectPtr<UComboBoxString> ChatGPTModelComboBox;
41
42 UPROPERTY(meta = (BindWidget))
43 TObjectPtr<UVerticalBox> MessagesVerticalBox;
44
45 UPROPERTY(meta = (BindWidget))
46 TObjectPtr<UScrollBox> ChatScrollBox;
47
48 UPROPERTY(meta = (BindWidget), BlueprintReadWrite, Category = "OpenAI")
49 TObjectPtr<UEditableText> UserInputTextBox;
50
51 UPROPERTY(meta = (BindWidget))
52 TObjectPtr<UButton> SendMessageButton;
53
54 UPROPERTY(meta = (BindWidget))
55 TObjectPtr<UButton> DumpChatButton;
56
57 UPROPERTY(meta = (BindWidget))
58 TObjectPtr<UButton> ClearChatButton;
59
60 UPROPERTY(meta = (BindWidget))
61 TObjectPtr<UButton> AttachImageButton;
62
63 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "UI")
64 TSubclassOf<UChatMessageWidget> ChatMessageWidgetClass;
65
66 UPROPERTY(meta = (BindWidget))
67 TObjectPtr<UGridPanel> ServiceContainer;
68
69 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "UI")
70 TSubclassOf<UServiceWidget> ServiceWidgetClass;
71
72 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "OpenAI")
73 TArray<TSubclassOf<UBaseService>> Services;
74
75 UPROPERTY(meta = (BindWidget))
76 TObjectPtr<UTextBlock> ServicesWarningTextBlock;
77
78 UPROPERTY(meta = (BindWidget))
79 TObjectPtr<UAttachedFilesContainerWidget> AttachedFilesContainer;
80
81 virtual void NativeConstruct() override;
82
83private:
84 UPROPERTY()
85 TObjectPtr<UChatGPT> ChatGPT;
86
87 UPROPERTY()
88 TArray<TObjectPtr<UChatMessageWidget>> ChatWidgets;
89
90 UPROPERTY()
91 TObjectPtr<USaveSettings> SaveSettings;
92
93 UPROPERTY()
94 TArray<TObjectPtr<UServiceWidget>> ServiceWidgets;
95
96private:
97 UFUNCTION()
98 void OnSendMessage();
99
100 UFUNCTION()
101 void OnDumpChat();
102
103 UFUNCTION()
104 void OnClearChat();
105
106 UFUNCTION()
107 void OnTextCommitted(const FText& Text, ETextCommit::Type CommitMethod);
108
109 UFUNCTION()
110 void OnTextChanged(const FText& Text);
111
112 UFUNCTION()
113 void OnModelSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
114
115 UFUNCTION()
116 void OnImageSelected();
117
118 void InitChatGPT();
119 void InitModelsComboBox();
120
121 void OnRequestCompleted();
122 void OnRequestUpdated(const FMessage& Message, bool WasError);
123
124 void CreateMessageWidget(const FMessage& Message);
125 void EnableControls(bool Enabled);
126
127 FString GenerateFilePath() const;
128
129 void UpdateVisionElements();
130 void UpdateSendMessageButton();
131 void OnFileRemoved();
132
133private:
134 OpenAI::ServiceSecrets ServiceSecrets;
135
136 void CreateServiceWidgets();
137 void OnServiceEnabled(bool IsEnabled, const TSubclassOf<UBaseService>& ServiceClass, const TObjectPtr<UServiceWidget>& ServiceWidget);
138};
Definition: AttachedFilesContainerWidget.h:16
Definition: ChatGPT.h:21
Definition: ChatGPTWidget.h:28
Definition: ChatMessageWidget.h:20
Definition: SaveSettings.h:13
Definition: ServiceWidget.h:19
Definition: ChatCommonTypes.h:75