Introducing Y-Chat: Simplifying the Integration of OpenAI’s Language Models with Kotlin Multiplatform
ChatGPT, the advanced language model developed by OpenAI, is already significantly impacting the real world.
Let us see an example:
- Imagine developing an advanced fitness application that takes into account users’ differing objectives such as losing weight or gaining muscle.
- By asking ChatGPT how to achieve these goals and integrating new information over time, the app’s responses can become increasingly accurate and tailored to individual users.
Indeed, the potential applications for ChatGPT are limitless.
As a precise and knowledgeable resource, it has enormous potential in areas such as customer service, enabling businesses to provide more accurate and effective assistance to their customers.
In order to facilitate the development of those applications we have developed the Y-Chat.
Simplifying the Integration of OpenAI APIs with Y-Chat and Kotlin Multiplatform
Before we dive into the details of the Y-Chat, let’s take a moment to introduce OpenAI’s APIs.
OpenAI offers a variety of powerful AI models, such as GPT-3, that can be accessed through a set of APIs. These APIs enable developers to integrate OpenAI’s state-of-the-art language models into their applications easily. However, the implementation details of working with these APIs can be complex and may require significant time and effort to get up and running.
In response, our team has developed the Y-Chat, which simplifies the process of making API calls to OpenAI’s models using Kotlin Multiplatform. By abstracting away the implementation details, developers can save time and effort when integrating OpenAI’s capabilities into their applications.
Kotlin Multiplatform support
Kotlin Multiplatform (KMP) is a technology that enables developers to write code that can run on multiple platforms, including Android, iOS, and the web. This approach can significantly reduce development time and make it easier to maintain and update apps across different platforms. At YML, we recognize the importance of supporting KMP in our SDK, which is why we’ve designed Y-Chat to be compatible with KMP. With Y-Chat, we can write once and deploy on multiple platforms, saving time and effort when developing cross-platform SDKs.
To add KMP support to our Y-Chat project, we created a shared module that contains the common code that will be shared across all platforms. This shared module includes interfaces, data models, business logic, and more.
Here is what the Y-Chat project structure looks like:
YChat.kt is a common code contained in the ychat module that serves as the entry point for our SDK, which can be consumed across multiple platforms. To demonstrate the practical usage of our SDK, we have also created iOS and Android samples.
To enable Kotlin Multiplatform (KMP) support in our ychat module, we have updated our build.gradle file with the following plugins and configurations:
We are using the Ktor library to make HTTP requests and consume OpenAI APIs, and Koin, a lightweight dependency injection framework for Kotlin, to decouple the internal components of our SDK and make them more modular, testable, and maintainable.
The decision to use Kotlin Multiplatform was driven by its ability to support multiple operating systems. Our initial release targets Android and iOS, and we’re excited to share the benefits of our SDK with developers on these platforms.
How does Y-Chat work?
To start using Y-Chat, you’ll need to obtain an API key from your OpenAI platform account. This key will enable you to authenticate and make API calls to OpenAI’s services. Once you have the API key, you can easily initialize the SDK and start generating text completions with just a few lines of code. We’ve designed the SDK to be as straightforward as possible, so you can focus on building the features you want.
iOS Setup
First, you will need to add the package to your project via SPM.
Go to your project’s file settings and click “Add Package”.
To add a new package, search for https://github.com/yml-org/ychat.git in the top right corner.
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.
Android Setup
Add Y-Chat to the dependencies of the build.gradle
Sync it and you are good to go to start using it in your Android project!
See the code snippet below on how to initialize and use it.
Conclusion
Overall, the Y-Chat is a valuable tool for developers looking to integrate OpenAI’s powerful AI models into their mobile applications. The SDK has been designed to be as straightforward as possible, allowing developers to focus on building the features they want.
We’re continually developing and adding new features, so stay tuned to the Y-Chat repository for updates. If you have any suggestions or feedback, we’d love to hear from you! Please feel free to reach out to us with any thoughts you have.
Take a look at our open-source organization for other useful tools as well. We love trying new things and experimenting with the latest tech at YML, so we’re always refining our offerings.
This joint article has been written by
A huge shoutout to Enrique Lopez (@eenriquelopez) and Mark Pospesel (@mpospese) for taking the time to review the article! Make sure to follow them on social media for some seriously insightful content.