Unreal OpenAI API 1.0.0
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
10USTRUCT()
12{
13 GENERATED_BODY()
14
15 UPROPERTY()
16 FString Title;
17
18 UPROPERTY()
19 FString Description;
20
21 UPROPERTY()
22 FString Content;
23};
24
25USTRUCT()
26struct 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
40UCLASS()
41class OPENAI_API UNewsService : public UBaseService
42{
43 GENERATED_BODY()
44
45public:
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
53protected:
54 virtual FString MakeFunction() const;
55
56private:
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};
Definition: BaseService.h:16
Definition: NewsService.h:42
Definition: NewsService.h:12
Definition: NewsService.h:27