-
-
Notifications
You must be signed in to change notification settings - Fork 7
Home
OpenAI is an AI research and deployment company. Xojo-OpenAI is a Xojo and RealStudio wrapper for the OpenAI public API.
This example asks the AI to correct a sentence for English spelling and grammar More examples.
OpenAI.APIKey = "YOUR API KEY"
Dim instruction As String = "Correct this to standard English" ' natural language instructions to AI
Dim prompt As String = "This ez uh test uv teh OpenAI AIP"
Dim reply As OpenAI.Response = OpenAI.Completion.Edit(prompt, instruction)
Dim correction As String = reply.GetResult(0)
This screenshot depicts the Xojo-OpenAI demo window running on Windows 10
- Issue natural-language instructions to the AI
- Generate images based on a description
- Modify, analyze, and parse text or source code according to instructions
- Analyze text for hate, threats, self-harm, sexual content, child abuse, and violence
- Can use the RB-libcURL wrapper, the MonkeyBread curl plugin, the Xojo URLConnection, or the Xojo HTTPSecureSocket to make API requests.
OpenAI API endpoints are exposed through several object classes:
Endpoint | Object Class | Comment |
---|---|---|
/v1/chat/completions |
ChatCompletion |
An AI response to a chat conversation prompt. |
/v1/completions and /v1/edits
|
Completion |
A text or code completion or edit. |
/v1/images/generations and /v1/images/edits
|
Image |
An image that was generated or modified. |
/v1/audio/transcriptions |
AudioTranscription |
A transcript of an English language audio file. |
/v1/audio/translations |
AudioTranslation |
An English translation of an audio file. |
/v1/moderations |
Moderation |
An analysis of offensive content in a given text. (i.e. "content moderation") |
/v1/models |
Model |
List and select from the available AI models |
/v1/fine-tunes |
FineTune |
A base Model that has been, is being, or will be fine-tuned using a previously uploaded File . |
/v1/files |
File |
A fine-tuning file that has been, is being, or will be uploaded. |
To make a request of the API, call the appropriate factory method on the corresponding object class. For example, to make a request of the /v1/completions
endpoint you would use the OpenAI.Completion.Create factory method, whereas the /v1/edits
endpoint is accessed using the OpenAI.Completion.Edit factory method. Factory methods perform the request and return a OpenAI.Response object (or one of its subclasses) containing the response.
Responses may have zero, one, or several choices, depending on the number of results you asked for. You can see how many choices are available by reading the Response.ResultCount property, and retrieve each result by calling the Response.GetResult method.
Factory methods generally come in two flavors: basic and advanced. The basic versions accept a few common parameters as direct arguments while the advanced versions accept a OpenAI.Request object with the correct properties set.
OpenAI.APIKey = "YOUR API KEY"
Dim request As New OpenAI.Request
request.Model = "text-davinci-003"
request.MaxTokens = 2048
request.NumberOfResults = 5
request.BestOf = 10
request.Prompt = "What is the airspeed velocity of an unladen European swallow?"
Dim reply As OpenAI.Response = OpenAI.Completion.Create(request)
Dim choices() As String
For i As Integer = 0 To reply.ResultCount - 1
choices.Append(reply.GetResult(i))
Next
- Download the Xojo-OpenAI project either in ZIP archive format or by cloning the repository with your Git client.
- Open the Xojo-OpenAI project in REALstudio or Xojo. Open your project in a separate window.
- Copy the Xojo-OpenAI module into your project and save. Do not use the "Import" feature of the Xojo IDE.
The OpenAI module may optionally use my open source RB-libcURL wrapper or the commercial MBS libcurl plugin. These should be preferred in order to take advantage of HTTP/2. If neither of these are available, the built-in URLConnection
class is used if it is available. In versions of Xojo that do not have the URLConnection class (<=2018r2) the built-in HTTPSecureSocket
class is used unless it's too old (<=2014r2), in which case you will need to use one of the curl options.
To enable RB-libcURL, copy (not Import) the libcURL
module from the RB-libcURL project into your project and set the OpenAI.USE_RBLIBCURL
constant to True
.
To enable the MBS plugin, ensure the plugin is installed and then set OpenAI.USE_MBS
constant to True
.
If both USE_RBLIBCURL
and USE_MBS
are True
then USE_RBLIBCURL
takes precedence.
If you are using neither RB-libcURL nor MBS then set both USE_RBLIBCURL
and USE_MBS
to False
to avoid compiler errors.
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2023-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.