Unreal OpenAI API
1.0.0
Source
OpenAI
Public
ChatGPT
Services
News
NewsService.h
1
// OpenAI, Copyright LifeEXE. All Rights Reserved.
2
3
#pragma once
4
5
#include "CoreMinimal.h"
6
#include "ChatGPT/BaseService.h"
7
#include "HTTP.h"
8
#include "NewsService.generated.h"
9
10
USTRUCT()
11
struct
FArticle
12
{
13
GENERATED_BODY()
14
15
UPROPERTY()
16
FString Title;
17
18
UPROPERTY()
19
FString Description;
20
21
UPROPERTY()
22
FString Content;
23
};
24
25
USTRUCT()
26
struct
FNews
27
{
28
GENERATED_BODY()
29
30
UPROPERTY()
31
FString Status;
32
33
UPROPERTY()
34
TArray<FArticle> Articles;
35
36
// @todo: more fields can be added
37
// https://newsapi.org/docs/endpoints/top-headlines
38
};
39
40
UCLASS()
41
class OPENAI_API
UNewsService
: public
UBaseService
42
{
43
GENERATED_BODY()
44
45
public
:
46
virtual
bool
Init(
const
OpenAI::ServiceSecrets& Secrets)
override
;
47
virtual
FString Name()
const override
{
return
"News"
; }
48
virtual
FString TooltipDescription()
const override
{
return
"News headlines from https://newsapi.org"
; }
49
virtual
FString Description()
const override
;
50
virtual
FString FunctionName()
const override
;
51
virtual
void
Call(
const
TSharedPtr<FJsonObject>& Args,
const
FString& ToolID)
override
;
52
53
protected
:
54
virtual
FString MakeFunction()
const
;
55
56
private
:
57
FString API_KEY{};
58
59
FString MakeRequestURL(
const
TSharedPtr<FJsonObject>& ArgsJson)
const
;
60
void
OnRequestCompleted(FHttpRequestPtr Request, FHttpResponsePtr Response,
bool
WasSuccessful);
61
void
SendError(
const
FString& ErrorMessage);
62
};
UBaseService
Definition:
BaseService.h:16
UNewsService
Definition:
NewsService.h:42
FArticle
Definition:
NewsService.h:12
FNews
Definition:
NewsService.h:27