Unreal OpenAI API 1.0.0
WeatherService.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 "WeatherService.generated.h"
9
10USTRUCT()
12{
13 GENERATED_BODY()
14
15 UPROPERTY()
16 FString Name; // city
17
18 UPROPERTY()
19 FString Country;
20};
21
22USTRUCT()
24{
25 GENERATED_BODY()
26
27 UPROPERTY()
28 FString Name;
29
30 UPROPERTY()
31 double Temperature{0.0};
32
33 UPROPERTY()
34 TArray<FString> Weather_Descriptions;
35};
36
37USTRUCT()
39{
40 GENERATED_BODY()
41
42 UPROPERTY()
43 FWeatherLocation Location;
44
45 UPROPERTY()
46 FCurrentWeather Current;
47
48 // @todo: more fields can be added
49 // https://weatherstack.com/documentation
50};
51
52UCLASS()
53class OPENAI_API UWeatherService : public UBaseService
54{
55 GENERATED_BODY()
56
57public:
58 virtual bool Init(const OpenAI::ServiceSecrets& Secrets) override;
59 virtual FString Name() const override { return "Weather"; }
60 virtual FString TooltipDescription() const override { return "Weather from https://weatherstack.com"; }
61 virtual FString Description() const override;
62 virtual FString FunctionName() const override;
63 virtual void Call(const TSharedPtr<FJsonObject>& Args, const FString& ToolID) override;
64
65protected:
66 virtual FString MakeFunction() const;
67
68private:
69 FString API_KEY{};
70
71 bool MakeRequestURL(const TSharedPtr<FJsonObject>& ArgsJson, FString& WeatherRequestURL) const;
72 void OnRequestCompleted(FHttpRequestPtr Request, FHttpResponsePtr Response, bool WasSuccessful);
73 void SendError(const FString& ErrorMessage);
74};
Definition: BaseService.h:16
Definition: WeatherService.h:54
Definition: WeatherService.h:24
Definition: WeatherService.h:39
Definition: WeatherService.h:12