Skip to content

cwiftdev/openai

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI

Swift Vapor

OpenAI is a Vapor helper to use OpenAIKit

Usage guide

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."]
        )
        ...
    }

License

OpenAI is available under the MIT license. See the LICENSE file for more info.

Want to help?

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! 😀

About

A Swift package for interacting with the OpenAI API using Vapor

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%