Coder Social home page Coder Social logo

openai-kotlin's Introduction

OpenAI API client for Kotlin

Maven Central License Documentation

Kotlin client for OpenAI's API with multiplatform and coroutines capabilities.

๐Ÿ“ฆ Setup

  1. Install OpenAI API Kotlin client by adding the following dependency to your build.gradle file:
repositories {
    mavenCentral()
}

dependencies {
    implementation "com.aallam.openai:openai-client:3.5.1"
}
  1. Choose and add to your dependencies one of Ktor's engines.

BOM

Alternatively, you can use openai-client-bom by adding the following dependency to your build.gradle file

dependencies {
    // import Kotlin API client BOM
    implementation platform('com.aallam.openai:openai-client-bom:3.5.1')

    // define dependencies without versions
    implementation 'com.aallam.openai:openai-client'
    runtimeOnly 'io.ktor:ktor-client-okhttp'
}

Multiplaform

In multiplatform projects, add openai client dependency to commonMain, and choose an engine for each target.

โšก๏ธ Getting Started

Note: OpenAI encourages using environment variables for the API key. Read more.

Create an instance of OpenAI client:

val openai = OpenAI(
    token = "your-api-key",
    timeout = Timeout(socket = 60.seconds),
    // additional configurations...
)

Or you can create an instance of OpenAI using a pre-configured OpenAIConfig:

val config = OpenAIConfig(
    token = apiKey,
    timeout = Timeout(socket = 60.seconds),
    // additional configurations...
)

val openAI = OpenAI(config)

Use your OpenAI instance to make API requests. Learn more.

Supported features

Legacy

Deprecated

Looking for a tokenizer? Try ktoken, a Kotlin library for tokenizing text.

๐Ÿ“š Guides

Get started and understand more about how to use OpenAI API client for Kotlin with these guides:

โ„น๏ธ Sample apps

Sample apps are available under sample, please check the README for running instructions.

๐Ÿ”’ ProGuard / R8

The specific rules are already bundled into the Jar which can be interpreted by R8 automatically.

๐Ÿ“ธ Snapshots

Snapshot

Learn how to import snapshot version

To import snapshot versions into your project, add the following code snippet to your gradle file:

repositories {
   //...
   maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

๐Ÿ› ๏ธ Throubleshooting

For common issues and their solutions, check the Troubleshooting Guide.

โญ๏ธ Support

Appreciate the project? Here's how you can help:

  1. Star: Give it a star at the top right. It means a lot!
  2. Contribute: Found an issue or have a feature idea? Submit a PR.
  3. Feedback: Have suggestions? Open an issue or start a discussion.

๐Ÿ“„ License

OpenAI Kotlin API Client is an open-sourced software licensed under the MIT license. This is an unofficial library, it is not affiliated with nor endorsed by OpenAI. Contributions are welcome.

openai-kotlin's People

Contributors

aallam avatar renovate[bot] avatar goooler avatar charlee-dev avatar andraxdev avatar filipobornik avatar hamen avatar jochengucksnk avatar matusekma avatar patricklaflamme avatar rasharab avatar aqua-ix avatar stuie avatar emeasure-github-private avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.