Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 93320ed

Browse files
authored
Hotfix v1.4.2: Fix HttpGPT Chat Scroll
2 parents b9c6a55 + 21391a0 commit 93320ed

File tree

3 files changed

+106
-99
lines changed

3 files changed

+106
-99
lines changed

HttpGPT.uplugin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
3-
"Version": 6,
4-
"VersionName": "1.4.1",
3+
"Version": 7,
4+
"VersionName": "1.4.2",
55
"EngineVersion": "5.1.0",
66
"FriendlyName": "HttpGPT - ChatGPT integrated in the Engine",
77
"Description": "HttpGPT is an Unreal Engine plugin that facilitates integration with Chat GPT through asynchronous REST requests, making it easy for developers to communicate with the chatbot. HttpGPT also includes a new Editor Tool to integrate Chat GPT directly in the Engine.",

Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "SHttpGPTChatView.h"
66
#include <HttpGPTHelper.h>
77
#include <Interfaces/IPluginManager.h>
8+
#include <Widgets/Layout/SScrollBox.h>
89

910
#ifdef UE_INLINE_GENERATED_CPP_BY_NAME
1011
#include UE_INLINE_GENERATED_CPP_BY_NAME(SHttpGPTChatView)
@@ -43,8 +44,61 @@ void UHttpGPTMessagingHandler::ResponseReceived(const FHttpGPTResponse& Response
4344
}
4445
}
4546

47+
void SHttpGPTChatItem::Construct(const FArguments& InArgs)
48+
{
49+
MessagingHandlerObject = NewObject<UHttpGPTMessagingHandler>();
50+
MessagingHandlerObject->Message = FHttpGPTMessage(InArgs._MessageRole, InArgs._InputText);
51+
52+
#if ENGINE_MAJOR_VERSION < 5
53+
using FAppStyle = FEditorStyle;
54+
#endif
55+
56+
const ISlateStyle& AppStyle = FAppStyle::Get();
57+
58+
ChildSlot
59+
[
60+
SNew(SVerticalBox)
61+
+ SVerticalBox::Slot()
62+
.Padding(MessagingHandlerObject->Message.Role == EHttpGPTRole::User ? FMargin(Slot_Padding * 16.f, Slot_Padding, Slot_Padding, Slot_Padding) : FMargin(Slot_Padding, Slot_Padding, Slot_Padding * 16.f, Slot_Padding))
63+
[
64+
SNew(SBorder)
65+
.BorderImage(AppStyle.GetBrush("Menu.Background"))
66+
[
67+
SNew(SVerticalBox)
68+
+ SVerticalBox::Slot()
69+
.Padding(Slot_Padding)
70+
.AutoHeight()
71+
[
72+
SNew(STextBlock)
73+
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 10))
74+
.Text(FText::FromString(MessagingHandlerObject->Message.Role == EHttpGPTRole::User ? "User:" : "Assistant:"))
75+
]
76+
+ SVerticalBox::Slot()
77+
.Padding(FMargin(Slot_Padding * 4, Slot_Padding, Slot_Padding, Slot_Padding))
78+
.FillHeight(1.f)
79+
[
80+
SAssignNew(MessageBox, STextBlock)
81+
.AutoWrapText(true)
82+
.Text(this, &SHttpGPTChatItem::GetMessageText)
83+
]
84+
]
85+
]
86+
];
87+
}
88+
89+
FText SHttpGPTChatItem::GetMessageText() const
90+
{
91+
return FText::FromString(MessagingHandlerObject->Message.Content);
92+
}
93+
4694
void SHttpGPTChatView::Construct([[maybe_unused]] const FArguments&)
4795
{
96+
#if ENGINE_MAJOR_VERSION < 5
97+
using FAppStyle = FEditorStyle;
98+
#endif
99+
100+
const ISlateStyle& AppStyle = FAppStyle::Get();
101+
48102
ModelsComboBox = SNew(STextComboBox)
49103
.OptionsSource(&AvailableModels)
50104
.ToolTipText(FText::FromString("Selected GPT Model"));
@@ -58,10 +112,15 @@ void SHttpGPTChatView::Construct([[maybe_unused]] const FArguments&)
58112
.Padding(Slot_Padding)
59113
.FillHeight(1.f)
60114
[
61-
SAssignNew(ListView, SListView<UHttpGPTMessagingHandlerPtr>)
62-
.ListItemsSource(&ListItems)
63-
.SelectionMode(ESelectionMode::None)
64-
.OnGenerateRow(this, &SHttpGPTChatView::OnGenerateRow)
115+
SNew(SBorder)
116+
.BorderImage(AppStyle.GetBrush("NoBorder"))
117+
[
118+
SNew(SScrollBox)
119+
+ SScrollBox::Slot()
120+
[
121+
SAssignNew(ChatBox, SVerticalBox)
122+
]
123+
]
65124
]
66125
+ SVerticalBox::Slot()
67126
.Padding(Slot_Padding)
@@ -104,45 +163,37 @@ void SHttpGPTChatView::Construct([[maybe_unused]] const FArguments&)
104163
];
105164
}
106165

107-
TSharedRef<ITableRow> SHttpGPTChatView::OnGenerateRow(UHttpGPTMessagingHandlerPtr Item, const TSharedRef<STableViewBase>& OwnerTable)
108-
{
109-
return SNew(SHttpGPTChatItem, OwnerTable, Item);
110-
}
111-
112166
FReply SHttpGPTChatView::HandleSendMessageButton()
113167
{
114-
UHttpGPTMessagingHandlerPtr UserMessage = NewObject<UHttpGPTMessagingHandler>();
115-
UserMessage->Message = FHttpGPTMessage(EHttpGPTRole::User, InputTextBox->GetText().ToString());
116-
117-
ListItems.Add(UserMessage);
168+
SHttpGPTChatItemPtr UserMessage = SNew(SHttpGPTChatItem).MessageRole(EHttpGPTRole::User).InputText(InputTextBox->GetText().ToString());
169+
ChatBox->AddSlot().AutoHeight() [ UserMessage.ToSharedRef() ];
170+
ChatItems.Add(UserMessage);
118171

119-
UHttpGPTMessagingHandlerPtr NewMessage = NewObject<UHttpGPTMessagingHandler>();
120-
NewMessage->Message.Role = EHttpGPTRole::Assistant;
172+
SHttpGPTChatItemPtr AssistantMessage = SNew(SHttpGPTChatItem).MessageRole(EHttpGPTRole::Assistant);
121173

122174
FHttpGPTOptions Options;
123175
Options.Model = UHttpGPTHelper::NameToModel(*(*ModelsComboBox->GetSelectedItem().Get()));
124176
Options.bStream = true;
125177

126178
RequestReference = UHttpGPTRequest::SendMessages_CustomOptions(GEditor->GetEditorWorldContext().World(), GetChatHistory(), Options);
127179

128-
RequestReference->ProgressStarted.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::ResponseReceived);
129-
RequestReference->ProgressUpdated.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::ResponseReceived);
130-
RequestReference->ProcessCompleted.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::ResponseReceived);
131-
RequestReference->ErrorReceived.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::ResponseReceived);
132-
RequestReference->RequestFailed.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::RequestFailed);
133-
RequestReference->RequestSent.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::RequestSent);
180+
RequestReference->ProgressStarted.AddDynamic(AssistantMessage->MessagingHandlerObject, &UHttpGPTMessagingHandler::ResponseReceived);
181+
RequestReference->ProgressUpdated.AddDynamic(AssistantMessage->MessagingHandlerObject, &UHttpGPTMessagingHandler::ResponseReceived);
182+
RequestReference->ProcessCompleted.AddDynamic(AssistantMessage->MessagingHandlerObject, &UHttpGPTMessagingHandler::ResponseReceived);
183+
RequestReference->ErrorReceived.AddDynamic(AssistantMessage->MessagingHandlerObject, &UHttpGPTMessagingHandler::ResponseReceived);
184+
RequestReference->RequestFailed.AddDynamic(AssistantMessage->MessagingHandlerObject, &UHttpGPTMessagingHandler::RequestFailed);
185+
RequestReference->RequestSent.AddDynamic(AssistantMessage->MessagingHandlerObject, &UHttpGPTMessagingHandler::RequestSent);
134186

135187
RequestReference->Activate();
136188

137189
if (RequestReference->IsTaskActive())
138190
{
139-
ListItems.Add(NewMessage);
191+
ChatBox->AddSlot().AutoHeight() [AssistantMessage.ToSharedRef()];
192+
ChatItems.Add(AssistantMessage);
140193
}
141194

142195
InputTextBox->SetText(FText::GetEmpty());
143196

144-
ListView->RequestListRefresh();
145-
146197
return FReply::Handled();
147198
}
148199

@@ -153,9 +204,8 @@ bool SHttpGPTChatView::IsSendMessageEnabled() const
153204

154205
FReply SHttpGPTChatView::HandleClearChatButton()
155206
{
156-
ListItems.Empty();
157-
158-
ListView->RequestListRefresh();
207+
ChatItems.Empty();
208+
ChatBox->ClearChildren();
159209

160210
if (RequestReference)
161211
{
@@ -167,7 +217,7 @@ FReply SHttpGPTChatView::HandleClearChatButton()
167217

168218
bool SHttpGPTChatView::IsClearChatEnabled() const
169219
{
170-
return !ListItems.IsEmpty();
220+
return !ChatItems.IsEmpty();
171221
}
172222

173223
TArray<FHttpGPTMessage> SHttpGPTChatView::GetChatHistory() const
@@ -177,9 +227,9 @@ TArray<FHttpGPTMessage> SHttpGPTChatView::GetChatHistory() const
177227
FHttpGPTMessage(EHttpGPTRole::System, GetSystemContext())
178228
};
179229

180-
for (const auto& Item : ListItems)
230+
for (const auto& Item : ChatItems)
181231
{
182-
Output.Add(Item->Message);
232+
Output.Add(Item->MessagingHandlerObject->Message);
183233
}
184234

185235
return Output;
@@ -213,50 +263,3 @@ void SHttpGPTChatView::InitializeModelsOptions()
213263
}
214264
}
215265
}
216-
217-
void SHttpGPTChatItem::Construct(const FArguments& InArgs, const TSharedRef<STableViewBase>& InOwnerTableView, const UHttpGPTMessagingHandlerPtr InMessagingHandlerObject)
218-
{
219-
#if ENGINE_MAJOR_VERSION < 5
220-
using FAppStyle = FEditorStyle;
221-
#endif
222-
223-
const ISlateStyle& AppStyle = FAppStyle::Get();
224-
225-
MessagingHandlerObject = InMessagingHandlerObject;
226-
227-
STableRow<UHttpGPTMessagingHandlerPtr>::Construct(STableRow<UHttpGPTMessagingHandlerPtr>::FArguments(), InOwnerTableView);
228-
229-
ChildSlot
230-
[
231-
SNew(SVerticalBox)
232-
+ SVerticalBox::Slot()
233-
.Padding(MessagingHandlerObject->Message.Role == EHttpGPTRole::User ? FMargin(Slot_Padding * 16.f, Slot_Padding, Slot_Padding, Slot_Padding) : FMargin(Slot_Padding, Slot_Padding, Slot_Padding * 16.f, Slot_Padding))
234-
[
235-
SNew(SBorder)
236-
.BorderImage(AppStyle.GetBrush("ToolPanel.GroupBorder"))
237-
[
238-
SNew(SVerticalBox)
239-
+ SVerticalBox::Slot()
240-
.Padding(Slot_Padding)
241-
.AutoHeight()
242-
[
243-
SNew(STextBlock)
244-
.Text(FText::FromString(MessagingHandlerObject->Message.Role == EHttpGPTRole::User ? "User:" : "Assistant:"))
245-
]
246-
+ SVerticalBox::Slot()
247-
.Padding(FMargin(Slot_Padding * 4, Slot_Padding, Slot_Padding, Slot_Padding))
248-
.FillHeight(1.f)
249-
[
250-
SAssignNew(MessageBox, STextBlock)
251-
.AutoWrapText(true)
252-
.Text(this, &SHttpGPTChatItem::GetMessageText)
253-
]
254-
]
255-
]
256-
];
257-
}
258-
259-
FText SHttpGPTChatItem::GetMessageText() const
260-
{
261-
return FText::FromString(MessagingHandlerObject->Message.Content);
262-
}

Source/HttpGPTEditor/Private/SHttpGPTChatView.h

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <CoreMinimal.h>
88
#include <HttpGPTTypes.h>
9-
#include <Widgets/Views/SListView.h>
109
#include <Widgets/Input/SEditableTextBox.h>
1110
#include <Widgets/Input/STextComboBox.h>
1211
#include "SHttpGPTChatView.generated.h"
@@ -33,6 +32,28 @@ class UHttpGPTMessagingHandler : public UObject
3332

3433
typedef UHttpGPTMessagingHandler* UHttpGPTMessagingHandlerPtr;
3534

35+
class SHttpGPTChatItem final : public SCompoundWidget
36+
{
37+
public:
38+
SLATE_BEGIN_ARGS(SHttpGPTChatItem) : _MessageRole(), _InputText()
39+
{
40+
}
41+
SLATE_ARGUMENT(EHttpGPTRole, MessageRole)
42+
SLATE_ARGUMENT(FString, InputText)
43+
SLATE_END_ARGS()
44+
45+
void Construct(const FArguments& InArgs);
46+
47+
FText GetMessageText() const;
48+
49+
UHttpGPTMessagingHandlerPtr MessagingHandlerObject;
50+
51+
private:
52+
TSharedPtr<STextBlock, ESPMode::ThreadSafe> MessageBox;
53+
};
54+
55+
typedef TSharedPtr<SHttpGPTChatItem, ESPMode::ThreadSafe> SHttpGPTChatItemPtr;
56+
3657
class SHttpGPTChatView final : public SCompoundWidget
3758
{
3859
public:
@@ -43,8 +64,6 @@ class SHttpGPTChatView final : public SCompoundWidget
4364

4465
void Construct(const FArguments& InArgs);
4566

46-
TSharedRef<ITableRow> OnGenerateRow(UHttpGPTMessagingHandlerPtr Item, const TSharedRef<STableViewBase>& OwnerTable);
47-
4867
FReply HandleSendMessageButton();
4968
bool IsSendMessageEnabled() const;
5069

@@ -58,8 +77,8 @@ class SHttpGPTChatView final : public SCompoundWidget
5877
void InitializeModelsOptions();
5978

6079
private:
61-
TArray<UHttpGPTMessagingHandlerPtr> ListItems;
62-
TSharedPtr<SListView<UHttpGPTMessagingHandlerPtr>> ListView;
80+
TSharedPtr<SVerticalBox> ChatBox;
81+
TArray<SHttpGPTChatItemPtr> ChatItems;
6382

6483
TSharedPtr<SEditableTextBox, ESPMode::ThreadSafe> InputTextBox;
6584
TSharedPtr<STextComboBox, ESPMode::ThreadSafe> ModelsComboBox;
@@ -72,18 +91,3 @@ class SHttpGPTChatView final : public SCompoundWidget
7291
class UHttpGPTRequest* RequestReference;
7392
#endif
7493
};
75-
76-
class SHttpGPTChatItem : public STableRow<UHttpGPTMessagingHandlerPtr>
77-
{
78-
public:
79-
SLATE_BEGIN_ARGS(SHttpGPTChatItem) { }
80-
SLATE_END_ARGS()
81-
82-
void Construct(const FArguments& InArgs, const TSharedRef<STableViewBase>& InOwnerTableView, const UHttpGPTMessagingHandlerPtr InMessagingHandlerObject);
83-
84-
FText GetMessageText() const;
85-
86-
private:
87-
UHttpGPTMessagingHandlerPtr MessagingHandlerObject;
88-
TSharedPtr<STextBlock, ESPMode::ThreadSafe> MessageBox;
89-
};

0 commit comments

Comments
 (0)