Unreal OpenAI API 1.0.0
API.h
1// OpenAI, Copyright LifeEXE. All Rights Reserved.
2
3/*
4 ___ ___ ________ _______
5|\ \ |\ \|\ _____\\ ___ \
6\ \ \ \ \ \ \ \__/\ \ __/|
7 \ \ \ \ \ \ \ __\\ \ \_|/__
8 \ \ \____\ \ \ \ \_| \ \ \_|\ \
9 \ \_______\ \__\ \__\ \ \_______\
10 \|_______|\|__|\|__| \|_______|
11
12
13
14 _______ ___ ___ _______
15|\ ___ \ |\ \ / /|\ ___ \
16\ \ __/| \ \ \/ / | \ __/|
17 \ \ \_|/__ \ \ / / \ \ \_|/__
18 \ \ \_|\ \ / \/ \ \ \_|\ \
19 \ \_______\/ /\ \ \ \_______\
20 \|_______/__/ /\ __\ \|_______|
21 |__|/ \|__|
22*/
23
24#pragma once
25
26// https://platform.openai.com/docs/api-reference
27
28namespace OpenAI
29{
30
31class IAPI
32{
33public:
34 virtual ~IAPI() = default;
35 virtual FString BaseURL() const = 0;
36
37 virtual FString Models() const = 0;
38 virtual FString Completion() const = 0;
39 virtual FString ChatCompletion() const = 0;
40 virtual FString ImageGenerations() const = 0;
41 virtual FString ImageEdits() const = 0;
42 virtual FString ImageVariations() const = 0;
43 virtual FString Embeddings() const = 0;
44 virtual FString Speech() const = 0;
45 virtual FString AudioTranscriptions() const = 0;
46 virtual FString AudioTranslations() const = 0;
47 virtual FString Files() const = 0;
48 virtual FString FineTuningJobs() const = 0;
49 virtual FString Moderations() const = 0;
50 virtual FString Batches() const = 0;
51 virtual FString Uploads() const = 0;
52 virtual FString Assistants() const = 0;
53};
54
55namespace V1
56{
57class OpenAIAPI : public IAPI
58{
59public:
60 OpenAIAPI(const FString& BaseURL = "https://api.openai.com") : API_URL(BaseURL) {}
61 virtual FString BaseURL() const override { return API_URL; }
62
63 virtual FString Models() const override { return API_URL + "/v1/models"; }
64 virtual FString Completion() const override { return API_URL + "/v1/completions"; }
65 virtual FString ChatCompletion() const override { return API_URL + "/v1/chat/completions"; }
66 virtual FString ImageGenerations() const override { return API_URL + "/v1/images/generations"; }
67 virtual FString ImageEdits() const override { return API_URL + "/v1/images/edits"; }
68 virtual FString ImageVariations() const override { return API_URL + "/v1/images/variations"; }
69 virtual FString Embeddings() const override { return API_URL + "/v1/embeddings"; }
70 virtual FString Speech() const override { return API_URL + "/v1/audio/speech"; }
71 virtual FString AudioTranscriptions() const override { return API_URL + "/v1/audio/transcriptions"; }
72 virtual FString AudioTranslations() const override { return API_URL + "/v1/audio/translations"; }
73 virtual FString Files() const override { return API_URL + "/v1/files"; }
74 virtual FString FineTuningJobs() const override { return API_URL + "/v1/fine_tuning/jobs"; }
75 virtual FString Moderations() const override { return API_URL + "/v1/moderations"; }
76 virtual FString Batches() const override { return API_URL + "/v1/batches"; }
77 virtual FString Uploads() const override { return API_URL + "/v1/uploads"; }
78 virtual FString Assistants() const override { return API_URL + "/v1/assistants"; }
79
80private:
81 const FString API_URL;
82};
83
84//
86{
87 FString Models;
88 FString Completions;
89 FString ChatCompletions;
90 FString ImageGenerations;
91 FString ImageEdits;
92 FString ImageVariations;
93 FString Embeddings;
94 FString Speech;
95 FString AudioTranscriptions;
96 FString AudioTranslations;
97 FString Files;
98 FString FineTuningJobs;
99 FString Moderations;
100 FString Batches;
101 FString Uploads;
102 FString Assistants;
103};
104
106{
107public:
108 GenericAPI(const FOpenAIEndpoints& Endpoints) : OpenAIEndpoints(Endpoints) {}
109
110 virtual FString Models() const override { return OpenAIEndpoints.Models; }
111 virtual FString Completion() const override { return OpenAIEndpoints.Completions; }
112 virtual FString ChatCompletion() const override { return OpenAIEndpoints.ChatCompletions; }
113 virtual FString ImageGenerations() const override { return OpenAIEndpoints.ImageGenerations; }
114 virtual FString ImageEdits() const override { return OpenAIEndpoints.ImageEdits; }
115 virtual FString ImageVariations() const override { return OpenAIEndpoints.ImageVariations; }
116 virtual FString Embeddings() const override { return OpenAIEndpoints.Embeddings; }
117 virtual FString Speech() const override { return OpenAIEndpoints.Speech; }
118 virtual FString AudioTranscriptions() const override { return OpenAIEndpoints.AudioTranscriptions; }
119 virtual FString AudioTranslations() const override { return OpenAIEndpoints.AudioTranslations; }
120 virtual FString Files() const override { return OpenAIEndpoints.Files; }
121 virtual FString FineTuningJobs() const override { return OpenAIEndpoints.FineTuningJobs; }
122 virtual FString Moderations() const override { return OpenAIEndpoints.Moderations; }
123 virtual FString Batches() const override { return OpenAIEndpoints.Batches; }
124 virtual FString Uploads() const override { return OpenAIEndpoints.Uploads; }
125 virtual FString Assistants() const override { return OpenAIEndpoints.Assistants; }
126
127private:
128 const FOpenAIEndpoints OpenAIEndpoints;
129 const FString API_URL;
130
131 virtual FString BaseURL() const override { return {}; }
132};
133
134} // namespace V1
135} // namespace OpenAI
Definition: API.h:32
Definition: API.h:106
Definition: API.h:58
Definition: OpenAI.Build.cs:6
Definition: API.h:86