Unreal OpenAI API 1.0.0
ChatCompletionAction.h
1// OpenAI, Copyright LifeEXE. All Rights Reserved.
2
3#pragma once
4
5#include "Kismet/BlueprintAsyncActionBase.h"
6#include "Provider/Types/Chat/ChatCompletionTypes.h"
7#include "Provider/Types/Chat/ChatCompletionChunkTypes.h"
8#include "Provider/Types/CommonTypes.h"
9#include "ChatCompletionAction.generated.h"
10
11USTRUCT(BlueprintType)
13{
14 GENERATED_BODY()
15
16
17 UPROPERTY(BlueprintReadOnly, Category = "OpenAI")
19
21 UPROPERTY(BlueprintReadOnly, Category = "OpenAI")
22 TArray<FChatCompletionStreamResponse> StreamResponse;
23
25 UPROPERTY(BlueprintReadOnly, Category = "OpenAI")
26 FString StreamResponseString{};
27
28 UPROPERTY(BlueprintReadOnly, Category = "OpenAI")
29 bool bStream{};
30
31 UPROPERTY(BlueprintReadOnly, Category = "OpenAI")
32 bool bCompleted{};
33};
34
35DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnChatCompletion, const FChatCompletionPayload&, Payload, const FOpenAIResponseMetadata&,
36 ResponseMetadata, const FOpenAIError&, RawError);
37
38class UOpenAIProvider;
39
40UCLASS()
41class UChatCompletionAction : public UBlueprintAsyncActionBase
42{
43 GENERATED_BODY()
44
45public:
46 UPROPERTY(BlueprintAssignable)
47 FOnChatCompletion OnUpdate;
48
49 virtual void Activate() override;
50
51private:
56 UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true"), Category = "OpenAI | Chat")
58 const FChatCompletion& ChatCompletion, const FOpenAIAuth& Auth, const FString& URLOverride);
59
60 void TryToOverrideURL(UOpenAIProvider* Provider);
61
62 void OnCreateChatCompletionCompleted(const FChatCompletionResponse& Response, const FOpenAIResponseMetadata& ResponseMetadata);
63 void OnCreateChatCompletionStreamProgresses(
64 const TArray<FChatCompletionStreamResponse>& Responses, const FOpenAIResponseMetadata& ResponseMetadata);
65 void OnCreateChatCompletionStreamCompleted(
66 const TArray<FChatCompletionStreamResponse>& Responses, const FOpenAIResponseMetadata& ResponseMetadata);
67 void OnRequestError(const FString& URL, const FString& Content);
68
69private:
70 FChatCompletion ChatCompletion;
71 FOpenAIAuth Auth;
72 FString URLOverride{};
73};
Definition: OpenAI.Build.cs:6
Definition: ChatCompletionAction.h:42
Definition: OpenAIProvider.h:45
void CreateChatCompletion(const FChatCompletion &Completion, const FOpenAIAuth &Auth)
Definition: OpenAIProvider.cpp:74
Definition: ChatCommonTypes.h:159
Definition: ChatCompletionAction.h:13
Definition: ChatCompletionTypes.h:104
Definition: ChatCompletionChunkTypes.h:77
Definition: CommonTypes.h:11
Definition: CommonTypes.h:28
Definition: CommonTypes.h:49