Git Product home page Git Product logo

hexascribe / vertexai-kt Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 1.0 7.52 MB

VertexAI-KT is a Kotlin multiplatform library that simplifies integration with Google Cloud's Vertex AI PaLM API for generative model creation and training.

License: Apache License 2.0

Kotlin 46.14% Swift 0.61% Objective-C 53.25%
android artificial-intelligence chatgpt ios kotlin kotlin-library kotlin-multiplatform-mobile openai-api vertex vertex-ai

vertexai-kt's Introduction

badge badge badge Maven Central License: Apache VertexAI-KT

VertexAI-KT

VertexAI-KT is a Kotlin multiplatform library designed to simplify the integration with the Vertex AI PaLM API, a powerful service provided by Google Cloud for creating and training generative models. This library provides an abstraction layer on top of the VertexAI API, enabling seamless integration with Android and iOS platforms.

⭐ Highlights

  • Simplified Integration: VertexAI-KT simplifies the process of integrating your Kotlin-based mobile applications with the Vertex AI PaLM API;
  • Cross-Platform Support: The library supports both Android and iOS platforms, allowing you to leverage the power of Vertex AI PaLM in your mobile apps;
  • Abstraction Layer: VertexAI-KT creates an abstraction layer on top of the VertexAI API, providing an intuitive and easy-to-use interface for creating and training generative models.

⚡️ Getting Started

To get started with the SDK, you'll need the following information for initialization:

  • Project ID: The Project ID refers to your Google Cloud Project ID.
  • Access Token: You'll need an access token for authentication. For more details, please refer to the Google Cloud Platform Authentication documentation.

It's important to have these details ready before proceeding with the SDK setup.

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("com.hexascribe:vertexai-kt-jvm:LATEST-VERSION")

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

VertexAI vertexAI = new VertexAI.Builder()
        .setAccessToken("YOUR_ACCESS_TOKEN")
        .setProjectId("YOUR_GOOGLE_CLOUD_PROJECT_ID")
        .build();
TextRequest textRequest = vertexAI.textRequest()
        .setModel("some-model")
        .setTemperature(0.8)
        .setMaxTokens(256)
        .setTopK(40)
        .setTopP(0.8);
textRequest.execute("Say this is a test", new VertexAI.Callback<String>() {
    @Override
    public void onSuccess(@NotNull String result) {
        // handle success
    }

    @Override
    public void onError(@NotNull Throwable throwable) {
        // handle error
    }
});

Android 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("com.hexascribe:vertexai-kt:LATEST-VERSION")

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

val vertexAI by lazy {
    VertexAI.Builder()
        .setAccessToken("YOUR_ACCESS_TOKEN")
        .setProjectId("YOUR_GOOGLE_CLOUD_PROJECT_ID")
        .build()
}
val textRequest by lazy {
    vertexAI.textRequest()
        .setModel("some-model")
        .setTemperature(0.8)
        .setMaxTokens(256)
        .setTopK(40)
        .setTopP(0.8)
}
viewModelScope.launch {
    val result = textRequest.execute("Say this is a test")
    print(result.getOrThrow())
}

iOS setup

To use this library in your iOS project, follow these steps:

  1. Go to your project’s file settings and click "Add Package".
  2. In the search bar at the top right, enter https://github.com/hexascribe/vertexai-kt.git
  3. Once you have found the package, click the "Add Package" button.

You can now start using the VertexAI-KT in your iOS project!

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

var vertexAI: VertexAI {
    VertexAI.Builder()
        .setAccessToken(accessToken: "YOUR_ACCESS_TOKEN")
        .setProjectId(projectId: "YOUR_GOOGLE_CLOUD_PROJECT_ID")
        .build()
}
var textRequest: TextRequest {
    vertexAI.textRequest()
        .setModel(model: "some-model")
        .setTemperature(temperature: 0.2)
        .setMaxTokens(maxTokens: 256)
        .setTopK(topK: 40)
        .setTopP(topP: 0.8)
}
Task.init {
    let result = try await textRequest.execute(prompt: "Say this is a test")
    print(result.getOrThrow())
}

ℹ️ 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 Hexa Scribe

    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.

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.