OpenAI is a Vapor helper to use OpenAIKit
In your Package.swift
file, add the following
.package(url: "https://github.com/vapor-community/openai.git", from: "1.0.0")
To use OpenAI in your Vapor application, set the environment variable for you OpenAI API key and optional Organization
export OPENAI_API_KEY="YOUR-KEY"
export OPENAI_ORGANIZATION="YOUR-ORGANIZATION"
Now you can access a OpenAI.Client
via Request
.
func generatePoem(req: Request) async throws -> HTTPStatus {
let completion = try await req.openai.completions.create(
model: Model.GPT3.davinci,
prompts: ["Write a haiku about dogs."]
)
...
}
OpenAI is available under the MIT license. See the LICENSE file for more info.
Feel free to submit a pull request whether it's a clean up, a new approach to handling things, adding a new part of the API, or even if it's just a typo. All help is welcomed! 😀