Skip to content

Commit

Permalink
Chore/ltm (#12)
Browse files Browse the repository at this point in the history
* chore(LTM) : Remove LoadSpeakerID function

* chore(LTM) : Move speaker id to player component
  • Loading branch information
ar-convai authored Dec 10, 2024
1 parent cab79a0 commit 93df707
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
Binary file modified Content/Core/ConvaiBaseCharacter.uasset
Binary file not shown.
3 changes: 2 additions & 1 deletion Source/Convai/Private/ConvaiChatbotComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ bool UConvaiChatbotComponent::PlayRecordedVoice(USoundWave* RecordedVoice)
return true;
}

void UConvaiChatbotComponent::StartGetResponseStream(UConvaiPlayerComponent* InConvaiPlayerComponent, FString InputText, UConvaiEnvironment* InEnvironment, bool InGenerateActions, bool InVoiceResponse, bool RunOnServer, bool UseOverrideAuthKey, FString OverrideAuthKey, FString OverrideAuthHeader, uint32 InToken)
void UConvaiChatbotComponent::StartGetResponseStream(UConvaiPlayerComponent* InConvaiPlayerComponent, FString InputText, UConvaiEnvironment* InEnvironment, bool InGenerateActions, bool InVoiceResponse, bool RunOnServer, bool UseOverrideAuthKey, FString OverrideAuthKey, FString OverrideAuthHeader, uint32 InToken, FString InSpeakerID)
{
if (!IsValid(InConvaiPlayerComponent))
{
Expand Down Expand Up @@ -395,6 +395,7 @@ void UConvaiChatbotComponent::StartGetResponseStream(UConvaiPlayerComponent* InC
Token = InToken;
CurrentConvaiPlayerComponent = InConvaiPlayerComponent;
LastPlayerName = CurrentConvaiPlayerComponent->PlayerName;
SpeakerID = InSpeakerID;

if (!TextInput)
{
Expand Down
23 changes: 19 additions & 4 deletions Source/Convai/Private/ConvaiPlayerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ void UConvaiPlayerComponent::SetPlayerNameServer_Implementation(const FString& N
PlayerName = NewPlayerName;
}

void UConvaiPlayerComponent::SetSpeakerID(FString NewSpeakerID)
{
SpeakerID = NewSpeakerID;

if (GetIsReplicated())
{
SetSpeakerIDServer(SpeakerID);
}
}

void UConvaiPlayerComponent::SetSpeakerIDServer_Implementation(const FString& NewSpeakerID)
{
SpeakerID = NewSpeakerID;
}

bool UConvaiPlayerComponent::GetDefaultCaptureDeviceInfo(FCaptureDeviceInfoBP& OutInfo)
{
if (!IsValid(AudioCaptureComponent))
Expand Down Expand Up @@ -658,7 +673,7 @@ void UConvaiPlayerComponent::StartTalking(
else
{
bool UseOverrideAuthKey = false;
ConvaiChatbotComponent->StartGetResponseStream(this, FString(""), Environment, GenerateActions, VoiceResponse, false, UseOverrideAuthKey, FString(""), FString(""), Token);
ConvaiChatbotComponent->StartGetResponseStream(this, FString(""), Environment, GenerateActions, VoiceResponse, false, UseOverrideAuthKey, FString(""), FString(""), Token, SpeakerID);
CurrentConvaiChatbotComponent = ConvaiChatbotComponent;
}
}
Expand Down Expand Up @@ -738,7 +753,7 @@ void UConvaiPlayerComponent::StartTalkingServer_Implementation(
Environment->MainCharacter = MainCharacter;
}
bool UseOverrideAuthKey = !UseServerAPI_Key;
ConvaiChatbotComponent->StartGetResponseStream(this, FString(""), Environment, GenerateActions, VoiceResponse, true, UseOverrideAuthKey, ClientAuthKey, AuthHeader, Token);
ConvaiChatbotComponent->StartGetResponseStream(this, FString(""), Environment, GenerateActions, VoiceResponse, true, UseOverrideAuthKey, ClientAuthKey, AuthHeader, Token, SpeakerID);
CurrentConvaiChatbotComponent = ConvaiChatbotComponent;
}
}
Expand Down Expand Up @@ -804,7 +819,7 @@ void UConvaiPlayerComponent::SendText(UConvaiChatbotComponent* ConvaiChatbotComp
else
{
bool UseOverrideAuthKey = false;
ConvaiChatbotComponent->StartGetResponseStream(this, Text, Environment, GenerateActions, VoiceResponse, false, UseOverrideAuthKey, FString(""), FString(""), Token);
ConvaiChatbotComponent->StartGetResponseStream(this, Text, Environment, GenerateActions, VoiceResponse, false, UseOverrideAuthKey, FString(""), FString(""), Token, SpeakerID);

// Invalidate the token by generating a new one
GenerateNewToken();
Expand Down Expand Up @@ -847,7 +862,7 @@ void UConvaiPlayerComponent::SendTextServer_Implementation(
Environment->MainCharacter = MainCharacter;

bool UseOverrideAuthKey = !UseServerAPI_Key;
ConvaiChatbotComponent->StartGetResponseStream(this, Text, Environment, GenerateActions, VoiceResponse, true, UseOverrideAuthKey, ClientAuthKey, AuthHeader, Token);
ConvaiChatbotComponent->StartGetResponseStream(this, Text, Environment, GenerateActions, VoiceResponse, true, UseOverrideAuthKey, ClientAuthKey, AuthHeader, Token, SpeakerID);

// Invalidate the token by generating a new one
GenerateNewToken();
Expand Down
4 changes: 2 additions & 2 deletions Source/Convai/Public/ConvaiChatbotComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class CONVAI_API UConvaiChatbotComponent : public UConvaiAudioStreamer
/**
* Speaker ID used for long term memory (LTM)
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Convai")
UPROPERTY(BlueprintReadOnly, Category = "Convai")
FString SpeakerID;

/**
Expand Down Expand Up @@ -317,7 +317,7 @@ class CONVAI_API UConvaiChatbotComponent : public UConvaiAudioStreamer

public:
//UFUNCTION(BlueprintCallable, DisplayName = "Begin Transmission")
void StartGetResponseStream(UConvaiPlayerComponent* InConvaiPlayerComponent, FString InputText, UConvaiEnvironment* InEnvironment, bool InGenerateActions, bool InVoiceResponse, bool ReplicateVoiceToNetwork, bool UseOverrideAuthKey, FString OverrideAuthKey, FString OverrideAuthHeader, uint32 InToken);
void StartGetResponseStream(UConvaiPlayerComponent* InConvaiPlayerComponent, FString InputText, UConvaiEnvironment* InEnvironment, bool InGenerateActions, bool InVoiceResponse, bool ReplicateVoiceToNetwork, bool UseOverrideAuthKey, FString OverrideAuthKey, FString OverrideAuthHeader, uint32 InToken, FString InSpeakerID);

void FinishGetResponseStream(UConvaiPlayerComponent* InConvaiPlayerComponent);

Expand Down
15 changes: 15 additions & 0 deletions Source/Convai/Public/ConvaiPlayerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ class CONVAI_API UConvaiPlayerComponent : public UConvaiAudioStreamer
UFUNCTION(Server, Reliable, Category = "Convai|Network")
void SetPlayerNameServer(const FString& NewPlayerName);

/**
* Speaker ID used for long term memory (LTM)
*/
UPROPERTY(EditAnywhere, Category = "Convai", Replicated, BlueprintSetter = SetSpeakerID)
FString SpeakerID;

/**
* Sets a new Speaker ID
*/
UFUNCTION(BlueprintCallable, BlueprintInternalUseOnly, Category = "Convai")
void SetSpeakerID(FString NewSpeakerID);

UFUNCTION(Server, Reliable, Category = "Convai|Network")
void SetSpeakerIDServer(const FString& NewSpeakerID);

UFUNCTION(BlueprintCallable, Category = "Convai|Microphone")
bool GetDefaultCaptureDeviceInfo(FCaptureDeviceInfoBP& OutInfo);

Expand Down

0 comments on commit 93df707

Please sign in to comment.