-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created functional test for completion, edits and embeddings TODO: functional test for files, fine tune, image and moderations
- Loading branch information
Showing
30 changed files
with
576 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
Source/UnrealOpenAI/Private/Tests/Actors/FunctionalTestPawn.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Created, maintained by Vanan A. - rezonated @ github.com | ||
|
||
#include "Tests/Actors/FunctionalTestPawn.h" | ||
|
||
#include "Enums/CompletionEnums.h" | ||
#include "Proxies/CompletionProxies.h" | ||
#include "Proxies/EditsProxies.h" | ||
#include "Proxies/EmbeddingsProxies.h" | ||
#include "Tests/FunctionalTests/CompletionFunctionalTest.h" | ||
#include "Tests/FunctionalTests/EditsFunctionalTest.h" | ||
#include "Tests/FunctionalTests/EmbeddingsFunctionalTest.h" | ||
|
||
|
||
AFunctionalTestPawn::AFunctionalTestPawn() | ||
{ | ||
PrimaryActorTick.bCanEverTick = false; | ||
} | ||
|
||
|
||
void AFunctionalTestPawn::StartCreateCompletionTest(FString Prompt) | ||
{ | ||
if (!CreateCompletionFunctionalTest) | ||
return; | ||
|
||
if (Prompt.IsEmpty() || Prompt.Len() <= 0 || Prompt == TEXT("")) | ||
{ | ||
CreateCompletionFunctionalTest->FailTest(TEXT("Prompt is empty")); | ||
} | ||
|
||
const auto Proxy = UCreateCompletionRequestProxy::CreateCompletion(this, Prompt, ECompletionModel::ECM_Davinci); | ||
|
||
if (!Proxy) | ||
{ | ||
CreateCompletionFunctionalTest->FailTest(TEXT("Failed to create completion request proxy")); | ||
return; | ||
} | ||
|
||
Proxy->OnSuccess.AddDynamic(this, &AFunctionalTestPawn::OnCompletionSuccess); | ||
|
||
Proxy->OnFailure.AddDynamic(this, &AFunctionalTestPawn::OnCompletionFailure); | ||
|
||
Proxy->Activate(); | ||
} | ||
|
||
void AFunctionalTestPawn::OnCompletionSuccess(FCreateCompletionResponse Response, FString JSONString, FString Error) | ||
{ | ||
if (JSONString.IsEmpty()) | ||
{ | ||
CreateCompletionFunctionalTest->FailTest(TEXT("No JSON String returned")); | ||
return; | ||
} | ||
|
||
if (!Error.IsEmpty()) | ||
{ | ||
CreateCompletionFunctionalTest->FailTest(TEXT("Error returned")); | ||
return; | ||
} | ||
|
||
if (Response.choices[0].text.IsEmpty()) | ||
{ | ||
CreateCompletionFunctionalTest->FailTest(TEXT("No response text returned")); | ||
return; | ||
} | ||
|
||
CreateCompletionFunctionalTest->PassTest(FString::Printf(TEXT("Response text returned %s"), *Response.choices[0].text)); | ||
} | ||
|
||
void AFunctionalTestPawn::OnCompletionFailure(FCreateCompletionResponse Response, FString JSONString, FString Error) | ||
{ | ||
CreateCompletionFunctionalTest->FailTest(TEXT("Should not fire failure delegate")); | ||
} | ||
|
||
void AFunctionalTestPawn::StartCreateEditsTest(FString Input, FString Instruction) | ||
{ | ||
if (!CreateEditsFunctionalTest) | ||
return; | ||
|
||
if (Input.IsEmpty() || Input.Len() <= 0 || Input == TEXT("")) | ||
{ | ||
CreateEditsFunctionalTest->FailTest(TEXT("Input is empty")); | ||
return; | ||
} | ||
|
||
if (Instruction.IsEmpty() || Instruction.Len() <= 0 || Instruction == TEXT("")) | ||
{ | ||
CreateEditsFunctionalTest->FailTest(TEXT("Instruction is empty")); | ||
return; | ||
} | ||
|
||
const auto Proxy = UCreateEditsRequestProxy::CreateEdits(this, Input, Instruction); | ||
|
||
if (!Proxy) | ||
{ | ||
CreateEditsFunctionalTest->FailTest(TEXT("Failed to create edits request proxy")); | ||
return; | ||
} | ||
|
||
Proxy->OnSuccess.AddDynamic(this, &AFunctionalTestPawn::OnEditsSuccess); | ||
Proxy->OnFailure.AddDynamic(this, &AFunctionalTestPawn::OnEditsFailure); | ||
|
||
Proxy->Activate(); | ||
} | ||
|
||
void AFunctionalTestPawn::OnEditsSuccess(FCreateEditsResponse Response, FString JSONString, FString Error) | ||
{ | ||
if (JSONString.IsEmpty()) | ||
{ | ||
CreateEditsFunctionalTest->FailTest(TEXT("No JSON String returned")); | ||
return; | ||
} | ||
|
||
if (!Error.IsEmpty()) | ||
{ | ||
CreateEditsFunctionalTest->FailTest(TEXT("Error returned")); | ||
return; | ||
} | ||
if (Response.choices[0].text.IsEmpty()) | ||
{ | ||
CreateEditsFunctionalTest->FailTest(TEXT("No response text returned")); | ||
return; | ||
} | ||
|
||
CreateEditsFunctionalTest->PassTest(FString::Printf(TEXT("Response text returned %s"), *Response.choices[0].text)); | ||
} | ||
|
||
void AFunctionalTestPawn::OnEditsFailure(FCreateEditsResponse Response, FString JSONString, FString Error) | ||
{ | ||
CreateEditsFunctionalTest->FailTest(TEXT("Should not fire failure delegate")); | ||
} | ||
|
||
void AFunctionalTestPawn::StartCreateEmbeddingsTest(FString Input) | ||
{ | ||
if (!CreateEmbeddingsFunctionalTest) | ||
{ | ||
return; | ||
} | ||
|
||
if (Input.IsEmpty() || Input.Len() <= 0 || Input == TEXT("")) | ||
{ | ||
CreateEmbeddingsFunctionalTest->FailTest(TEXT("Input is empty")); | ||
return; | ||
} | ||
|
||
const auto Proxy = UCreateEmbeddingsRequestProxy::CreateEmbeddings(this, Input); | ||
|
||
if (!Proxy) | ||
{ | ||
CreateEmbeddingsFunctionalTest->FailTest(TEXT("Failed to create embeddings request proxy")); | ||
return; | ||
} | ||
|
||
Proxy->OnSuccess.AddDynamic(this, &AFunctionalTestPawn::OnEmbeddingsSuccess); | ||
Proxy->OnFailure.AddDynamic(this, &AFunctionalTestPawn::OnEmbeddingsFailure); | ||
|
||
Proxy->Activate(); | ||
} | ||
|
||
void AFunctionalTestPawn::OnEmbeddingsSuccess(FCreateEmbeddingsResponse Response, FString JSONString, FString Error) | ||
{ | ||
if (JSONString.IsEmpty()) | ||
{ | ||
CreateEmbeddingsFunctionalTest->FailTest(TEXT("No JSON String returned")); | ||
return; | ||
} | ||
|
||
if (!Error.IsEmpty()) | ||
{ | ||
CreateEmbeddingsFunctionalTest->FailTest(TEXT("Error returned")); | ||
return; | ||
} | ||
|
||
if (Response.data.Num() < 0) | ||
{ | ||
CreateEmbeddingsFunctionalTest->FailTest(TEXT("No response data returned")); | ||
return; | ||
} | ||
|
||
CreateEmbeddingsFunctionalTest->PassTest(FString::Printf(TEXT("Response data returned with length of %d"), Response.data.Num())); | ||
} | ||
|
||
void AFunctionalTestPawn::OnEmbeddingsFailure(FCreateEmbeddingsResponse Response, FString JSONString, FString Error) | ||
{ | ||
CreateEmbeddingsFunctionalTest->FailTest(TEXT("Should not fire failure delegate")); | ||
} |
25 changes: 25 additions & 0 deletions
25
Source/UnrealOpenAI/Private/Tests/FunctionalTests/CompletionFunctionalTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Created, maintained by Vanan A. - rezonated @ github.com | ||
|
||
|
||
#include "Tests/FunctionalTests/CompletionFunctionalTest.h" | ||
|
||
#include "Tests/Actors/FunctionalTestPawn.h" | ||
|
||
ACreateCompletionFunctionalTest::ACreateCompletionFunctionalTest() | ||
{ | ||
PrimaryActorTick.bCanEverTick = false; | ||
} | ||
|
||
void ACreateCompletionFunctionalTest::OnTestStartHandler() | ||
{ | ||
Super::OnTestStartHandler(); | ||
if (!TestPawn) | ||
{ | ||
FailTest(TEXT("TestPawn is not set")); | ||
return; | ||
} | ||
|
||
TestPawn->CreateCompletionFunctionalTest = this; | ||
|
||
TestPawn->StartCreateCompletionTest("Say this is a test"); | ||
} |
26 changes: 26 additions & 0 deletions
26
Source/UnrealOpenAI/Private/Tests/FunctionalTests/EditsFunctionalTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Created, maintained by Vanan A. - rezonated @ github.com | ||
|
||
|
||
#include "Tests/FunctionalTests/EditsFunctionalTest.h" | ||
|
||
#include "Tests/Actors/FunctionalTestPawn.h" | ||
|
||
ACreateEditsFunctionalTest::ACreateEditsFunctionalTest() | ||
{ | ||
PrimaryActorTick.bCanEverTick = false; | ||
} | ||
|
||
void ACreateEditsFunctionalTest::OnTestStartHandler() | ||
{ | ||
Super::OnTestStartHandler(); | ||
|
||
if (!TestPawn) | ||
{ | ||
FailTest("TestPawn is not set"); | ||
return; | ||
} | ||
|
||
TestPawn->CreateEditsFunctionalTest = this; | ||
|
||
TestPawn->StartCreateEditsTest("What day of the wek is it?", "Fix the spelling mistakes"); | ||
} |
29 changes: 29 additions & 0 deletions
29
Source/UnrealOpenAI/Private/Tests/FunctionalTests/EmbeddingsFunctionalTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Created, maintained by Vanan A. - rezonated @ github.com | ||
|
||
|
||
#include "Tests/FunctionalTests/EmbeddingsFunctionalTest.h" | ||
|
||
#include "Tests/Actors/FunctionalTestPawn.h" | ||
|
||
|
||
ACreateEmbeddingsFunctionalTest::ACreateEmbeddingsFunctionalTest() | ||
{ | ||
PrimaryActorTick.bCanEverTick = false; | ||
} | ||
|
||
void ACreateEmbeddingsFunctionalTest::OnTestStartHandler() | ||
{ | ||
Super::OnTestStartHandler(); | ||
|
||
if (!TestPawn) | ||
{ | ||
FailTest("TestPawn is not set"); | ||
return; | ||
} | ||
|
||
TestPawn->CreateEmbeddingsFunctionalTest = this; | ||
|
||
TestPawn->StartCreateEmbeddingsTest(TEXT("The food was delicious and the waiter...")); | ||
} | ||
|
||
|
71 changes: 71 additions & 0 deletions
71
Source/UnrealOpenAI/Private/Tests/FunctionalTests/OpenAIFunctionalTestBase.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Created, maintained by Vanan A. - rezonated @ github.com | ||
|
||
|
||
#include "Tests/FunctionalTests/OpenAIFunctionalTestBase.h" | ||
|
||
#include "Kismet/GameplayStatics.h" | ||
#include "Kismet/KismetSystemLibrary.h" | ||
#include "Utils/Utils.h" | ||
|
||
AOpenAIFunctionalTestBase::AOpenAIFunctionalTestBase() | ||
{ | ||
PrimaryActorTick.bCanEverTick = true; | ||
} | ||
|
||
void AOpenAIFunctionalTestBase::OnTestPrepareHandler() | ||
{ | ||
PrintDebugLogAndOnScreen("OnTestPrepareHandler"); | ||
|
||
StartTest(); | ||
} | ||
|
||
void AOpenAIFunctionalTestBase::BeginPlay() | ||
{ | ||
Super::BeginPlay(); | ||
|
||
PrintDebugLogAndOnScreen("BeginPlay"); | ||
|
||
OnTestPrepare.AddDynamic(this, &AOpenAIFunctionalTestBase::OnTestPrepareHandler); | ||
|
||
OnTestStart.AddDynamic(this, &AOpenAIFunctionalTestBase::OnTestStartHandler); | ||
} | ||
|
||
void AOpenAIFunctionalTestBase::OnTestStartHandler() | ||
{ | ||
PrintDebugLogAndOnScreen("Test started"); | ||
} | ||
|
||
void AOpenAIFunctionalTestBase::PrepareTest() | ||
{ | ||
Super::PrepareTest(); | ||
|
||
PrintDebugLogAndOnScreen("PrepareTest"); | ||
} | ||
|
||
bool AOpenAIFunctionalTestBase::IsReady_Implementation() | ||
{ | ||
return true; | ||
} | ||
|
||
void AOpenAIFunctionalTestBase::StartTest() | ||
{ | ||
Super::StartTest(); | ||
|
||
PrintDebugLogAndOnScreen("StartTest"); | ||
} | ||
|
||
void AOpenAIFunctionalTestBase::FailTest(FString Message) | ||
{ | ||
FinishTest(EFunctionalTestResult::Failed, Message); | ||
|
||
UKismetSystemLibrary::QuitGame(GetWorld(), UGameplayStatics::GetPlayerController(GetWorld(), 0), EQuitPreference::Quit, false); | ||
} | ||
|
||
void AOpenAIFunctionalTestBase::PassTest(FString Message) | ||
{ | ||
FinishTest(EFunctionalTestResult::Succeeded, Message); | ||
|
||
UKismetSystemLibrary::QuitGame(GetWorld(), UGameplayStatics::GetPlayerController(GetWorld(), 0), EQuitPreference::Quit, false); | ||
} | ||
|
||
|
Oops, something went wrong.