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

Commit 030556c

Browse files
authored
v1.4.7
2 parents 4766a07 + 9720991 commit 030556c

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
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": 11,
4-
"VersionName": "1.4.6",
3+
"Version": 12,
4+
"VersionName": "1.4.7",
55
"FriendlyName": "HttpGPT - ChatGPT integrated in the Engine",
66
"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.",
77
"Category": "Messaging",

Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ void UHttpGPTMessagingHandler::ProcessCompleted(const FHttpGPTResponse& Response
4141

4242
void UHttpGPTMessagingHandler::ProcessResponse(const FHttpGPTResponse& Response)
4343
{
44+
bool bScrollToEnd = false;
45+
if (ScrollBoxReference.IsValid())
46+
{
47+
bScrollToEnd = FMath::Abs(ScrollBoxReference->GetScrollOffsetOfEnd() - ScrollBoxReference->GetScrollOffset()) <= 8.f;
48+
}
49+
4450
if (!Response.bSuccess)
4551
{
4652
const FStringFormatOrderedArguments Arguments_ErrorDetails{
@@ -63,7 +69,7 @@ void UHttpGPTMessagingHandler::ProcessResponse(const FHttpGPTResponse& Response)
6369
return;
6470
}
6571

66-
if (ScrollBoxReference.IsValid())
72+
if (ScrollBoxReference.IsValid() && bScrollToEnd)
6773
{
6874
ScrollBoxReference->ScrollToEnd();
6975
}
@@ -82,17 +88,32 @@ void UHttpGPTMessagingHandler::Destroy()
8288

8389
void SHttpGPTChatItem::Construct(const FArguments& InArgs)
8490
{
85-
Message = FHttpGPTMessage(InArgs._MessageRole, InArgs._InputText);
86-
87-
MessagingHandlerObject = NewObject<UHttpGPTMessagingHandler>();
88-
MessagingHandlerObject->SetFlags(RF_Standalone);
91+
if (InArgs._MessageRole == EHttpGPTRole::Assistant)
92+
{
93+
MessagingHandlerObject = NewObject<UHttpGPTMessagingHandler>();
94+
MessagingHandlerObject->SetFlags(RF_Standalone);
95+
96+
MessagingHandlerObject->OnMessageContentUpdated.BindLambda(
97+
[this](FString Content)
98+
{
99+
if (!Message.IsValid())
100+
{
101+
return;
102+
}
103+
104+
#if ENGINE_MAJOR_VERSION > 5 || (ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1)
105+
const FTextSelection SelectedText = Message->GetSelection();
106+
Message->SetText(FText::FromString(Content));
107+
Message->SelectText(SelectedText.GetBeginning(), SelectedText.GetEnd());
108+
#else
109+
Message->SetText(FText::FromString(Content));
110+
#endif
111+
}
112+
);
113+
}
89114

90-
MessagingHandlerObject->OnMessageContentUpdated.BindLambda(
91-
[this](FString Content)
92-
{
93-
Message.Content = Content;
94-
}
95-
);
115+
const FText RoleText = FText::FromString(InArgs._MessageRole == EHttpGPTRole::User ? "User:" : "Assistant:");
116+
const FMargin SlotPadding = InArgs._MessageRole == EHttpGPTRole::User ? FMargin(Slot_Padding * 16.f, Slot_Padding, Slot_Padding, Slot_Padding) : FMargin(Slot_Padding, Slot_Padding, Slot_Padding * 16.f, Slot_Padding);
96117

97118
#if ENGINE_MAJOR_VERSION < 5
98119
using FAppStyle = FEditorStyle;
@@ -104,7 +125,7 @@ void SHttpGPTChatItem::Construct(const FArguments& InArgs)
104125
[
105126
SNew(SVerticalBox)
106127
+ SVerticalBox::Slot()
107-
.Padding(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))
128+
.Padding(SlotPadding)
108129
[
109130
SNew(SBorder)
110131
.BorderImage(AppStyle.GetBrush("Menu.Background"))
@@ -114,26 +135,34 @@ void SHttpGPTChatItem::Construct(const FArguments& InArgs)
114135
.Padding(Slot_Padding)
115136
.AutoHeight()
116137
[
117-
SNew(STextBlock)
138+
SAssignNew(Role, STextBlock)
118139
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 10))
119-
.Text(FText::FromString(Message.Role == EHttpGPTRole::User ? "User:" : "Assistant:"))
140+
.Text(RoleText)
120141
]
121142
+ SVerticalBox::Slot()
122143
.Padding(FMargin(Slot_Padding * 4, Slot_Padding, Slot_Padding, Slot_Padding))
123144
.FillHeight(1.f)
124145
[
125-
SAssignNew(MessageBox, STextBlock)
146+
SAssignNew(Message, SMultiLineEditableText)
147+
.AllowMultiLine(true)
126148
.AutoWrapText(true)
127-
.Text(this, &SHttpGPTChatItem::GetMessageText)
149+
.IsReadOnly(true)
150+
.AllowContextMenu(true)
151+
.Text(FText::FromString(InArgs._InputText))
128152
]
129153
]
130154
]
131155
];
132156
}
133157

134-
FText SHttpGPTChatItem::GetMessageText() const
158+
FString SHttpGPTChatItem::GetRoleText() const
159+
{
160+
return Role.IsValid() ? Role->GetText().ToString() : FString();
161+
}
162+
163+
FString SHttpGPTChatItem::GetMessageText() const
135164
{
136-
return FText::FromString(Message.Content);
165+
return Message.IsValid() ? Message->GetText().ToString() : FString();
137166
}
138167

139168
void SHttpGPTChatView::Construct([[maybe_unused]] const FArguments&)
@@ -278,7 +307,7 @@ TArray<FHttpGPTMessage> SHttpGPTChatView::GetChatHistory() const
278307

279308
for (const auto& Item : ChatItems)
280309
{
281-
Output.Add(Item->Message);
310+
Output.Add(FHttpGPTMessage(*Item->GetRoleText(), Item->GetMessageText()));
282311
}
283312

284313
return Output;

Source/HttpGPTEditor/Private/SHttpGPTChatView.h

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

77
#include <CoreMinimal.h>
88
#include <HttpGPTTypes.h>
9-
#include <Widgets/Input/SEditableTextBox.h>
9+
#include <Widgets/Text/STextBlock.h>
10+
#include <Widgets/Text/SMultiLineEditableText.h>
1011
#include <Widgets/Input/STextComboBox.h>
1112
#include <Widgets/Layout/SScrollBox.h>
1213
#include "SHttpGPTChatView.generated.h"
@@ -55,13 +56,14 @@ class SHttpGPTChatItem final : public SCompoundWidget
5556

5657
void Construct(const FArguments& InArgs);
5758

58-
FText GetMessageText() const;
59+
FString GetRoleText() const;
60+
FString GetMessageText() const;
5961

6062
TWeakObjectPtr<UHttpGPTMessagingHandler> MessagingHandlerObject;
61-
FHttpGPTMessage Message;
6263

6364
private:
64-
TSharedPtr<STextBlock> MessageBox;
65+
TSharedPtr<STextBlock> Role;
66+
TSharedPtr<SMultiLineEditableText> Message;
6567
};
6668

6769
typedef TSharedPtr<SHttpGPTChatItem> SHttpGPTChatItemPtr;

0 commit comments

Comments
 (0)