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

v1.4.6 #35

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions HttpGPT.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 10,
"VersionName": "1.4.5",
"Version": 11,
"VersionName": "1.4.6",
"FriendlyName": "HttpGPT - ChatGPT integrated in the Engine",
"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.",
"Category": "Messaging",
Expand Down
44 changes: 36 additions & 8 deletions Source/HttpGPT/Private/HttpGPTRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
#include UE_INLINE_GENERATED_CPP_BY_NAME(HttpGPTRequest)
#endif

#if WITH_EDITOR
UHttpGPTRequest* UHttpGPTRequest::EditorTask(const TArray<FHttpGPTMessage>& Messages, const FHttpGPTOptions Options)
{
UHttpGPTRequest* const NewAsyncTask = SendMessages_CustomOptions(GEditor->GetEditorWorldContext().World(), Messages, Options);
NewAsyncTask->bIsEditorTask = true;

return NewAsyncTask;
}
#endif

UHttpGPTRequest* UHttpGPTRequest::SendMessage_DefaultOptions(UObject* WorldContextObject, const FString& Message)
{
return SendMessage_CustomOptions(WorldContextObject, Message, FHttpGPTOptions());
Expand All @@ -35,20 +45,20 @@ UHttpGPTRequest* UHttpGPTRequest::SendMessages_DefaultOptions(UObject* WorldCont
return SendMessages_CustomOptions(WorldContextObject, Messages, FHttpGPTOptions());
}

UHttpGPTRequest* UHttpGPTRequest::SendMessage_CustomOptions(UObject* WorldContextObject, const FString& Message, const FHttpGPTOptions& Options)
UHttpGPTRequest* UHttpGPTRequest::SendMessage_CustomOptions(UObject* WorldContextObject, const FString& Message, const FHttpGPTOptions Options)
{
return SendMessages_CustomOptions(WorldContextObject, { FHttpGPTMessage(EHttpGPTRole::User, Message) }, Options);
}

UHttpGPTRequest* UHttpGPTRequest::SendMessages_CustomOptions(UObject* WorldContextObject, const TArray<FHttpGPTMessage>& Messages, const FHttpGPTOptions& Options)
UHttpGPTRequest* UHttpGPTRequest::SendMessages_CustomOptions(UObject* WorldContextObject, const TArray<FHttpGPTMessage>& Messages, const FHttpGPTOptions Options)
{
UHttpGPTRequest* const Task = NewObject<UHttpGPTRequest>();
Task->Messages = Messages;
Task->TaskOptions = Options;
UHttpGPTRequest* const NewAsyncTask = NewObject<UHttpGPTRequest>();
NewAsyncTask->Messages = Messages;
NewAsyncTask->TaskOptions = Options;

Task->RegisterWithGameInstance(WorldContextObject);
NewAsyncTask->RegisterWithGameInstance(WorldContextObject);

return Task;
return NewAsyncTask;
}

void UHttpGPTRequest::StopHttpGPTTask()
Expand Down Expand Up @@ -102,7 +112,14 @@ void UHttpGPTRequest::Activate()
);

#if WITH_EDITOR
FEditorDelegates::PrePIEEnded.AddUObject(this, &UHttpGPTRequest::PrePIEEnded);
if (bIsEditorTask)
{
SetFlags(RF_Standalone);
}
else
{
FEditorDelegates::PrePIEEnded.AddUObject(this, &UHttpGPTRequest::PrePIEEnded);
}
#endif
}

Expand All @@ -118,6 +135,17 @@ void UHttpGPTRequest::SetReadyToDestroy()
UE_LOG(LogHttpGPT, Display, TEXT("%s (%d): Setting task as Ready to Destroy"), *FString(__func__), GetUniqueID());

#if WITH_EDITOR
if (bIsEditorTask)
{
ClearFlags(RF_Standalone);

#if ENGINE_MAJOR_VERSION >= 5
MarkAsGarbage();
#else
MarkPendingKill();
#endif
}

if (FEditorDelegates::PrePIEEnded.IsBoundToObject(this))
{
FEditorDelegates::PrePIEEnded.RemoveAll(this);
Expand Down
13 changes: 9 additions & 4 deletions Source/HttpGPT/Public/HttpGPTRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ class HTTPGPT_API UHttpGPTRequest : public UBlueprintAsyncActionBase
UPROPERTY(BlueprintAssignable, Category = "HttpGPT")
FHttpGPTGenericDelegate RequestSent;

#if WITH_EDITOR
static UHttpGPTRequest* EditorTask(const TArray<FHttpGPTMessage>& Messages, const FHttpGPTOptions Options);
#endif

UFUNCTION(BlueprintCallable, Category = "HttpGPT | Default", meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", DisplayName = "Send Message with Default Options"))
static UHttpGPTRequest* SendMessage_DefaultOptions(UObject* WorldContextObject, const FString& Message);

UFUNCTION(BlueprintCallable, Category = "HttpGPT | Default", meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", DisplayName = "Send Messages with Default Options"))
static UHttpGPTRequest* SendMessages_DefaultOptions(UObject* WorldContextObject, const TArray<FHttpGPTMessage>& Messages);

UFUNCTION(BlueprintCallable, Category = "HttpGPT | Custom", meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", DisplayName = "Send Message with Custom Options"))
static UHttpGPTRequest* SendMessage_CustomOptions(UObject* WorldContextObject, const FString& Message, const FHttpGPTOptions& Options);
static UHttpGPTRequest* SendMessage_CustomOptions(UObject* WorldContextObject, const FString& Message, const FHttpGPTOptions Options);

UFUNCTION(BlueprintCallable, Category = "HttpGPT | Custom", meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", DisplayName = "Send Messages with Custom Options"))
static UHttpGPTRequest* SendMessages_CustomOptions(UObject* WorldContextObject, const TArray<FHttpGPTMessage>& Messages, const FHttpGPTOptions& Options);
static UHttpGPTRequest* SendMessages_CustomOptions(UObject* WorldContextObject, const TArray<FHttpGPTMessage>& Messages, const FHttpGPTOptions Options);

UFUNCTION(BlueprintCallable, Category = "HttpGPT", meta = (DisplayName = "Stop HttpGPT Task"))
void StopHttpGPTTask();
Expand Down Expand Up @@ -92,9 +96,10 @@ class HTTPGPT_API UHttpGPTRequest : public UBlueprintAsyncActionBase
bool bIsTaskActive = false;

#if WITH_EDITOR
virtual void PrePIEEnded(bool bIsSimulating);

bool bIsEditorTask = false;
bool bEndingPIE = false;

virtual void PrePIEEnded(bool bIsSimulating);
#endif
};

Expand Down
6 changes: 5 additions & 1 deletion Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void UHttpGPTMessagingHandler::ProcessResponse(const FHttpGPTResponse& Response)

void UHttpGPTMessagingHandler::Destroy()
{
ClearFlags(RF_Standalone);

#if ENGINE_MAJOR_VERSION >= 5
MarkAsGarbage();
#else
Expand All @@ -83,6 +85,8 @@ void SHttpGPTChatItem::Construct(const FArguments& InArgs)
Message = FHttpGPTMessage(InArgs._MessageRole, InArgs._InputText);

MessagingHandlerObject = NewObject<UHttpGPTMessagingHandler>();
MessagingHandlerObject->SetFlags(RF_Standalone);

MessagingHandlerObject->OnMessageContentUpdated.BindLambda(
[this](FString Content)
{
Expand Down Expand Up @@ -217,7 +221,7 @@ FReply SHttpGPTChatView::HandleSendMessageButton()
Options.Model = UHttpGPTHelper::NameToModel(*(*ModelsComboBox->GetSelectedItem().Get()));
Options.bStream = true;

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

RequestReference->ProgressStarted.AddDynamic(AssistantMessage->MessagingHandlerObject.Get(), &UHttpGPTMessagingHandler::ProcessUpdated);
RequestReference->ProgressUpdated.AddDynamic(AssistantMessage->MessagingHandlerObject.Get(), &UHttpGPTMessagingHandler::ProcessUpdated);
Expand Down
3 changes: 0 additions & 3 deletions Source/HttpGPTEditor/Private/SHttpGPTChatView.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ class SHttpGPTChatView final : public SCompoundWidget
private:
TSharedPtr<SVerticalBox> ChatBox;
TArray<SHttpGPTChatItemPtr> ChatItems;

TSharedPtr<SScrollBox> ChatScrollBox;

TSharedPtr<SEditableTextBox> InputTextBox;
TSharedPtr<STextComboBox> ModelsComboBox;

TArray<TSharedPtr<FString>> AvailableModels;

TWeakObjectPtr<class UHttpGPTRequest> RequestReference;
Expand Down