Swiftpack.co - codeandtheory/ychat as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by codeandtheory.
codeandtheory/ychat 1.4.1
A Kotlin Multiplatform library that provides access to ChatGPT and Open AI APIs
⭐️ 137
🕓 8 weeks ago
iOS macOS
.package(url: "https://github.com/codeandtheory/ychat.git", from: "1.4.1")

Maven Central Apache-2.0 Build Status Y-Chat


Y—Chat is a Kotlin Multiplatform (KMP) project that provides a simple API for integrating the powerful ChatGPT language model developed by OpenAI into mobile applications running on multi platforms. The goal of this project is to abstract all the API call logic from ChatGPT, allowing developers to easily leverage the capabilities of the language model in their mobile applications.

The repository contains the source code for the Y—Chat library, along with examples and documentation for getting started with the library. The Y—Chat library provides a consistent interface for interacting with ChatGPT, regardless of the platform, and makes it easy to generate human-like text based on a given prompt or context.

The library uses Kotlin Multiplatform to generate artifacts for both iOS, macOS, Android and JVM, allowing developers to write code once and use it on multiple platforms. The project is open source and actively maintained, with contributions from the community encouraged. Overall, Y—Chat provides a convenient and powerful way for mobile developers to incorporate the advanced natural language processing capabilities of ChatGPT into their applications.

⚡️ Getting Started

iOS setup

  • Go to your project’s file settings and click "Add Package":

Y-ChatGPT iOS first screenshot

Y-ChatGPT iOS second screenshot

Once you have found the package click the "Add Package" button to add it to your project. Now you can start using the SDK in your iOS project!

See the code snippet below on how to initialize and use it one of the supported feature:

var yChat: YChat {
    YChatCompanion.shared.create(apiKey: "your-api-key") 

do {
  let result = try await chatGpt.completion()
                    .setInput(input: "Say this is a test.")
                    .setMaxTokens(tokens: 1024)
                    .saveHistory(isSaveHistory: false)
                    .set... // you can set more parameters
} catch {
  // catch any error that may occurs on api call.  

Android/JVM setup

Add the following line to import the library via Gradle. First, make sure Maven Central has been added:

repositories {
    // ...

Then, simply import the dependency to your build.gradle dependencies:


Take a look at the Kotlin code snippet below for an example of how to initialize and use one of the supported features:

val yChat by lazy {

try {
  val result = yChat.completion()
     .setInput("Say this is a test.")
     .set... // you can set more parameters
} catch (e: exception) {
  // catch any error that may occurs on api call.  


ℹ️ Sample apps

Take a look at our sample apps to learn how to use the SDK on different platforms:

Android Sample
iOS Sample
JVM Sample

🤝 Contributions

Feel free to make a suggestion or if you find any error in this project, please open an issue. Make sure to read our contribution guidelines before.

📄 License

    Copyright 2023 YML

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at


    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


Stars: 137
Last commit: Yesterday
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Related Packages

Release Notes

26 weeks ago

What's Changed

Full Changelog: https://github.com/yml-org/ychat/compare/1.4.0...1.4.1

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics