Skip to content

Commit 3ee9e35

Browse files
authored
Update README.md
1 parent 226700f commit 3ee9e35

File tree

1 file changed

+106
-31
lines changed

1 file changed

+106
-31
lines changed

README.md

Lines changed: 106 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
# Delphi OpenAI API
2+
3+
![logo](https://github.com/HemulGM/DelphiOpenAI/blob/main/openai+delphi.png?raw=true)
4+
5+
___
26
![GitHub](https://img.shields.io/github/license/hemulgm/DelphiOpenAI)
37
![GitHub](https://img.shields.io/github/last-commit/hemulgm/DelphiOpenAI)
48
![GitHub](https://img.shields.io/badge/coverage-100%25-green)
59
![GitHub](https://img.shields.io/badge/IDE%20Version-Delphi%2010.3+-yellow)
610
![GitHub](https://img.shields.io/badge/platform-all%20platforms-green)
711

8-
The library provides access to the API of the [OpenAI service](https://openai.com/api/), on the basis of which [ChatGPT](https://openai.com/blog/chatgpt) works and, for example, the generation of images from text using `DALL-E`.
9-
`Delphi 10.3+` is required to work with the library.
10-
This library is a `TOpenAI` class for the main TComponent for more convenient work.
12+
This repositorty contains Swift implementation over [OpenAI](https://beta.openai.com/docs/api-reference/) public API.
1113

1214
*This is an unofficial library. OpenAI does not provide any official library for Delphi.*
1315

16+
- [What is OpenAI](#what-is-openai)
17+
- [Installation](#installation)
18+
- [Usage](#usage)
19+
- [Initialization](#initialization)
20+
- [Models](#models)
21+
- [Completions](#completions)
22+
- [Chats](#chats)
23+
- [Images](#images)
24+
- [Errors](#errors)
25+
- [Exceptions](#exceptions)
26+
- [Usage proxy](#proxy)
27+
- [Examples](#examples)
28+
- [Requirements](#requirements)
29+
- [Links](#links)
30+
- [License](#license)
31+
1432
**Coverage**
1533

1634
<img src="https://github.com/HemulGM/ChatGPT.API/blob/main/OpenAL-GPT3.png?raw=true" height="150" align="right">
@@ -29,17 +47,27 @@ This library is a `TOpenAI` class for the main TComponent for more convenient wo
2947
|Moderations|🟢 Done|
3048
|Engines (Depricated)|🟢 Done|
3149

32-
# ⚒️ Installation
50+
## What is OpenAI
51+
52+
OpenAI is a non-profit artificial intelligence research organization founded in San Francisco, California in 2015. It was created with the purpose of advancing digital intelligence in ways that benefit humanity as a whole and promote societal progress. The organization strives to develop AI (Artificial Intelligence) programs and systems that can think, act and adapt quickly on their own – autonomously. OpenAI's mission is to ensure safe and responsible use of AI for civic good, economic growth and other public benefits; this includes cutting-edge research into important topics such as general AI safety, natural language processing, applied reinforcement learning methods, machine vision algorithms etc.
53+
54+
>The OpenAI API can be applied to virtually any task that involves understanding or generating natural language or code. We offer a spectrum of models with different levels of power suitable for different tasks, as well as the ability to fine-tune your own custom models. These models can be used for everything from content generation to semantic search and classification.
55+
56+
This library provides access to the API of the [OpenAI service](https://openai.com/api/), on the basis of which [ChatGPT](https://openai.com/blog/chatgpt) works and, for example, the generation of images from text using `DALL-E`.
57+
58+
## Installation
3359

3460
You can install the package from `GetIt` [directly](https://getitnow.embarcadero.com/openai-for-delphi) in the IDE. Or, to use the library, just add the `root` folder to the IDE library path, or your project source path.
3561

36-
# 🌳 Usage
62+
## Usage
3763

38-
The library needs to be configured with your account's secret key which is available on the [website](https://beta.openai.com/account/api-keys).
64+
### Initialization
3965

40-
Due to the fact that there can be many parameters and not all of them are required, they are configured using an anonymous function.
66+
To initialize API instance you need to [obtain](https://beta.openai.com/account/api-keys) API token from your Open AI organization.
67+
68+
Once you have a token, you can initialize `TOpenAI` class, which is an entry point to the API.
4169

42-
**Initialization**
70+
Due to the fact that there can be many parameters and not all of them are required, they are configured using an anonymous function.
4371

4472
```Pascal
4573
uses OpenAI;
@@ -55,7 +83,10 @@ uses OpenAI;
5583
var OpenAI: IOpenAI := TOpenAI.Create(API_TOKEN);
5684
```
5785

58-
**Models**
86+
Once token you posses the token, and the instance is initialized you are ready to make requests.
87+
88+
### Models
89+
5990
```Pascal
6091
var Models := OpenAI.Model.List();
6192
try
@@ -66,23 +97,8 @@ finally
6697
end;
6798
```
6899

69-
**Chat**
70-
```Pascal
71-
var Chat := OpenAI.Chat.Create(
72-
procedure(Params: TChatParams)
73-
begin
74-
Params.Messages([TChatMessageBuild.Create(TMessageRole.User, Text)]);
75-
Params.MaxTokens(1024);
76-
end);
77-
try
78-
for var Choice in Chat.Choices do
79-
MemoChat.Lines.Add(Choice.Message.Content);
80-
finally
81-
Chat.Free;
82-
end;
83-
```
100+
### Completions
84101

85-
**Completions**
86102
```Pascal
87103
var Completions := OpenAI.Completion.Create(
88104
procedure(Params: TCompletionParams)
@@ -98,7 +114,28 @@ finally
98114
end;
99115
```
100116

101-
**Images Generations**
117+
Review [Completions Documentation](https://beta.openai.com/docs/api-reference/completions) for more info.
118+
119+
### Chats
120+
121+
```Pascal
122+
var Chat := OpenAI.Chat.Create(
123+
procedure(Params: TChatParams)
124+
begin
125+
Params.Messages([TChatMessageBuild.Create(TMessageRole.User, Text)]);
126+
Params.MaxTokens(1024);
127+
end);
128+
try
129+
for var Choice in Chat.Choices do
130+
MemoChat.Lines.Add(Choice.Message.Content);
131+
finally
132+
Chat.Free;
133+
end;
134+
```
135+
136+
Review [Chat Documentation](https://platform.openai.com/docs/guides/chat) for more info.
137+
138+
### Images
102139
```Pascal
103140
var Images := OpenAI.Image.Create(
104141
procedure(Params: TImageGenParams)
@@ -114,7 +151,10 @@ finally
114151
end;
115152
```
116153

117-
*Error handling*
154+
Review [Images Documentation](https://beta.openai.com/docs/api-reference/images) for more info.
155+
156+
### Errors
157+
118158
```Pascal
119159
try
120160
var Images := OpenAI.Image.Create(...);
@@ -126,7 +166,8 @@ except
126166
end;
127167
```
128168

129-
Exceptions:
169+
#### Exceptions
170+
130171
* OpenAIExceptionAPI - errors of wrapper
131172
* OpenAIException - base exception
132173
* OpenAIExceptionInvalidRequestError
@@ -136,18 +177,52 @@ Exceptions:
136177
* OpenAIExceptionTryAgain
137178
* OpenAIExceptionInvalidResponse - parse error
138179

139-
*Usage proxy*
180+
### Proxy
181+
140182
```Pascal
141183
OpenAI.API.Client.ProxySettings := TProxySettings.Create(ProxyHost, ProxyPort, ProxyUserName, ProxyPassword);
142184
```
143185

144-
# Examples
186+
## Examples
145187
|Source|Preview|Source|Preview|
146188
|---|---|---|---|
147189
|[Playground (FMX)](https://github.com/HemulGM/DelphiOpenAIPlayground)|<img src="https://github.com/HemulGM/DelphiOpenAIPlayground/blob/main/preview.png?raw=true" height="150" align="right">|[ChatGPT (FMX)](https://github.com/HemulGM/ChatGPT)|<img src="https://github.com/HemulGM/ChatGPT/raw/main/preview.png?raw=true" height="150" align="right">|
148190
|[DALL-E (FMX)](https://github.com/HemulGM/DALL-E)|<img src="https://github.com/HemulGM/DALL-E/raw/main/Res/preview.jpg?raw=true" height="150" align="right">|||
149191

150-
# 🚳 Requirements
192+
## Requirements
151193
This library does not require any 3rd party library. It works on recent Delphi versions (10.3+). Althought not fully tested, it should also work on all supported platforms (Windows, Linux, macOS, Android, iOS).
152194

153195
Since the library requires your secret API key, it's not recommended you use it on client applications, as your secret key will be exposed, unless you are sure about the security risks.
196+
197+
## Links
198+
199+
- [OpenAI Documentation](https://beta.openai.com/docs/introduction)
200+
- [OpenAI Playground](https://beta.openai.com/playground)
201+
- [OpenAI Examples](https://beta.openai.com/examples)
202+
- [Dall-E](https://labs.openai.com/)
203+
204+
## License
205+
206+
```
207+
MIT License
208+
209+
Copyright (c) 2023 HemulGM
210+
211+
Permission is hereby granted, free of charge, to any person obtaining a copy
212+
of this software and associated documentation files (the "Software"), to deal
213+
in the Software without restriction, including without limitation the rights
214+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
215+
copies of the Software, and to permit persons to whom the Software is
216+
furnished to do so, subject to the following conditions:
217+
218+
The above copyright notice and this permission notice shall be included in all
219+
copies or substantial portions of the Software.
220+
221+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
222+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
223+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
224+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
225+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
226+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
227+
SOFTWARE.
228+
```

0 commit comments

Comments
 (0)