OpenAI
An OpenAI library for Winglang.
This is an initial version of this library which currently exposes a very small subset of the OpenAI API.
Prerequisites
Installation
npm i @winglibs/openai
Example
bring cloud;
bring openai;
let key = new cloud.Secret(name: "OAIApiKey");
let oai = new openai.OpenAI(apiKeySecret: key);
new cloud.Function(inflight () => {
  let joke = oai.createCompletion("tell me a short joke", model: "gpt-3.5-turbo", max_tokens: 2048);
  log(joke);
});
When running in a test context, the createCompletion method will return a JSON object which
echos the request under the mock key:
bring expect;
test "create completion test" {
  let r = oai.createCompletion("tell me a short joke");
  expect.equal(r, Json.stringify({
    mock: {
      prompt:"tell me a short joke",
      params:{"model":"gpt-3.5-turbo","max_tokens":2048}
    }
  }));
}
Usage
new openai.OpenAI();
apiKeySecret- acloud.Secretwith the OpenAI API key (required).orgSecret- acloud.Secretwith the OpenAI organization ID (not required).
You can also specify clear text values through apiKey and org, but make sure not to commit these
values to a repository ⚠️.
Methods:
inflight createCompletion()- requests a completion from a model. Options aremodel(defaults togpt-3.5.turbo) andmax_tokens(defaults to 2048).
Roadmap
- Support the rest of the OpenAI API
 - Add more examples
 - Add more tests
 
Maintainers
License
Licensed under the MIT License.
API Reference
Table of Contents
- Classes
 - Structs
 
OpenAI (preflight class) 
No description
Constructor
new(props: OpenAIProps?): OpenAI
Properties
No properties
Methods
| Signature | Description | 
|---|---|
inflight createCompletion(prompt: str, params: CompletionParams?): str | No description | 
static inflight createNewInflightClient(apiKey: str, org: str?): IClient | No description | 
CompletionParams (struct) 
No description
Properties
| Name | Type | Description | 
|---|---|---|
maxTokens | num? | No description | 
model | str? | No description | 
OpenAIProps (struct) 
No description
Properties
| Name | Type | Description | 
|---|---|---|
apiKey | str? | No description | 
apiKeySecret | Secret? | No description | 
org | str? | No description | 
orgSecret | Secret? | No description |