diff --git a/HttpGPT.uplugin b/HttpGPT.uplugin index 287cd25..a584033 100644 --- a/HttpGPT.uplugin +++ b/HttpGPT.uplugin @@ -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", diff --git a/Source/HttpGPT/Private/HttpGPTRequest.cpp b/Source/HttpGPT/Private/HttpGPTRequest.cpp index f655672..caeef01 100644 --- a/Source/HttpGPT/Private/HttpGPTRequest.cpp +++ b/Source/HttpGPT/Private/HttpGPTRequest.cpp @@ -25,6 +25,16 @@ #include UE_INLINE_GENERATED_CPP_BY_NAME(HttpGPTRequest) #endif +#if WITH_EDITOR +UHttpGPTRequest* UHttpGPTRequest::EditorTask(const TArray& 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()); @@ -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& Messages, const FHttpGPTOptions& Options) +UHttpGPTRequest* UHttpGPTRequest::SendMessages_CustomOptions(UObject* WorldContextObject, const TArray& Messages, const FHttpGPTOptions Options) { - UHttpGPTRequest* const Task = NewObject(); - Task->Messages = Messages; - Task->TaskOptions = Options; + UHttpGPTRequest* const NewAsyncTask = NewObject(); + NewAsyncTask->Messages = Messages; + NewAsyncTask->TaskOptions = Options; - Task->RegisterWithGameInstance(WorldContextObject); + NewAsyncTask->RegisterWithGameInstance(WorldContextObject); - return Task; + return NewAsyncTask; } void UHttpGPTRequest::StopHttpGPTTask() @@ -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 } @@ -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); diff --git a/Source/HttpGPT/Public/HttpGPTRequest.h b/Source/HttpGPT/Public/HttpGPTRequest.h index b1c8ecd..0511d82 100644 --- a/Source/HttpGPT/Public/HttpGPTRequest.h +++ b/Source/HttpGPT/Public/HttpGPTRequest.h @@ -43,6 +43,10 @@ class HTTPGPT_API UHttpGPTRequest : public UBlueprintAsyncActionBase UPROPERTY(BlueprintAssignable, Category = "HttpGPT") FHttpGPTGenericDelegate RequestSent; +#if WITH_EDITOR + static UHttpGPTRequest* EditorTask(const TArray& 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); @@ -50,10 +54,10 @@ class HTTPGPT_API UHttpGPTRequest : public UBlueprintAsyncActionBase static UHttpGPTRequest* SendMessages_DefaultOptions(UObject* WorldContextObject, const TArray& 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& Messages, const FHttpGPTOptions& Options); + static UHttpGPTRequest* SendMessages_CustomOptions(UObject* WorldContextObject, const TArray& Messages, const FHttpGPTOptions Options); UFUNCTION(BlueprintCallable, Category = "HttpGPT", meta = (DisplayName = "Stop HttpGPT Task")) void StopHttpGPTTask(); @@ -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 }; diff --git a/Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp b/Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp index c3977da..fb271f7 100644 --- a/Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp +++ b/Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp @@ -71,6 +71,8 @@ void UHttpGPTMessagingHandler::ProcessResponse(const FHttpGPTResponse& Response) void UHttpGPTMessagingHandler::Destroy() { + ClearFlags(RF_Standalone); + #if ENGINE_MAJOR_VERSION >= 5 MarkAsGarbage(); #else @@ -83,6 +85,8 @@ void SHttpGPTChatItem::Construct(const FArguments& InArgs) Message = FHttpGPTMessage(InArgs._MessageRole, InArgs._InputText); MessagingHandlerObject = NewObject(); + MessagingHandlerObject->SetFlags(RF_Standalone); + MessagingHandlerObject->OnMessageContentUpdated.BindLambda( [this](FString Content) { @@ -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); diff --git a/Source/HttpGPTEditor/Private/SHttpGPTChatView.h b/Source/HttpGPTEditor/Private/SHttpGPTChatView.h index b907f9f..ef2faf2 100644 --- a/Source/HttpGPTEditor/Private/SHttpGPTChatView.h +++ b/Source/HttpGPTEditor/Private/SHttpGPTChatView.h @@ -91,12 +91,9 @@ class SHttpGPTChatView final : public SCompoundWidget private: TSharedPtr ChatBox; TArray ChatItems; - TSharedPtr ChatScrollBox; - TSharedPtr InputTextBox; TSharedPtr ModelsComboBox; - TArray> AvailableModels; TWeakObjectPtr RequestReference;