3

GitHub - yml-org/ychat: A Kotlin Multiplatform library that provides access to C...

 1 year ago
source link: https://github.com/yml-org/ychat
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Y-Chat

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, 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.

zap 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
                    .execute()
} 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 {
    mavenCentral()
    // ...
}

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

implementation("co.yml:ychat:1.3.0")

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 {
  YChat.create("your-api-key")
}

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

Features

information_source 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

handshake 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.

page_facing_up 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

        http://www.apache.org/licenses/LICENSE-2.0

    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.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK