Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
m-asadullah committed Mar 25, 2024
1 parent 4d59a24 commit 407953c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
55 changes: 36 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Google AI SDK for Android

The Google AI client SDK for Android enables developers to use Google's state-of-the-art generative AI models (like Gemini) to build AI-powered features and applications. This SDK supports use cases like:
The Google AI client SDK for Android enables developers to use Google's state-of-the-art generative
AI models (like Gemini) to build AI-powered features and applications. This SDK supports use cases
like:

- Generate text from text-only input
- Generate text from text-and-images input (multimodal)
- Build multi-turn conversations (chat)

For example, with just a few lines of code, you can access Gemini's multimodal capabilities to generate text from text-and-image input:
For example, with just a few lines of code, you can access Gemini's multimodal capabilities to
generate text from text-and-image input:

```kotlin
val generativeModel = GenerativeModel(
Expand All @@ -15,49 +19,62 @@ val generativeModel = GenerativeModel(

val cookieImage: Bitmap = // ...
val inputContent = content() {
image(cookieImage)
text("Does this look store-bought or homemade?")
image(cookieImage)
text("Does this look store-bought or homemade?")
}

val response = generativeModel.generateContent(inputContent)
print(response.text)
```

> [!NOTE]
> If you want to access Gemini on-device (Gemini Nano), check out the [Google AI Edge SDK for Android](https://ai.google.dev/tutorials/android_aicore), which is enabled via Android AICore.
> If you want to access Gemini on-device (Gemini Nano), check out
> the [Google AI Edge SDK for Android](https://ai.google.dev/tutorials/android_aicore), which is
> enabled via Android AICore.
## Try out the sample Android app

This repository contains a sample app demonstrating how the SDK can access and utilize the Gemini model for various use cases.
This repository contains a sample app demonstrating how the SDK can access and utilize the Gemini
model for various use cases.

To try out the sample app you can directly import the project from Android Studio
via **File > New > Import Sample** and searching for *Generative AI Sample* or follow these steps below:
To try out the sample app you can directly import the project from Android Studio
via **File > New > Import Sample** and searching for *Generative AI Sample* or follow these steps
below:

1. Check out this repository.\
`git clone https://github.com/google/generative-ai-android`
1. Check out this repository.\
`git clone https://github.com/google/generative-ai-android`

1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs.
1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs.

1. Open and build the sample app in the `generativeai-android-sample` folder of this repo.
1. Open and build the sample app in the `generativeai-android-sample` folder of this repo.

1. Paste your API key into the `apiKey` property in the `local.properties` file.
1. Paste your API key into the `apiKey` property in the `local.properties` file.

1. Run the app.
1. Run the app.

## Installation and usage

Add the dependency `implementation("com.google.ai.client.generativeai:generativeai:<version>"`) to your Android project.
Add the dependency `implementation("com.google.ai.client.generativeai:generativeai:<version>"`) to
your Android project.

For detailed instructions, you can find
a [quickstart](https://ai.google.dev/tutorials/android_quickstart) for the Google AI client SDK for
Android in the Google documentation.

For detailed instructions, you can find a [quickstart](https://ai.google.dev/tutorials/android_quickstart) for the Google AI client SDK for Android in the Google documentation.
This quickstart describes how to add your API key and the SDK's dependency to your app, initialize
the model, and then call the API to access the model. It also describes some additional use cases
and features, like streaming, counting tokens, and controlling responses.

This quickstart describes how to add your API key and the SDK's dependency to your app, initialize the model, and then call the API to access the model. It also describes some additional use cases and features, like streaming, counting tokens, and controlling responses.
## Documentation

Find complete documentation for the Google AI SDKs and the Gemini model in the Google documentation:\
Find complete documentation for the Google AI SDKs and the Gemini model in the Google
documentation:\
https://ai.google.dev/docs

## Contributing

See [Contributing](https://github.com/google/generative-ai-android/blob/main/CONTRIBUTING.md) for more information on contributing to the Google AI client SDK for Android.
See [Contributing](https://github.com/google/generative-ai-android/blob/main/CONTRIBUTING.md) for
more information on contributing to the Google AI client SDK for Android.

## License

Expand Down
2 changes: 1 addition & 1 deletion generativeai-android-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ buildscript {
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.1.3" apply false
id("com.android.application") version "8.3.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version "2.0.1" apply false
}
18 changes: 9 additions & 9 deletions generativeai/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,32 @@ android {
}

dependencies {
val ktorVersion = "2.3.2"
val ktorVersion = "2.3.9"

implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("androidx.core:core-ktx:1.12.0")
implementation("org.slf4j:slf4j-android:1.7.36")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.7.3")
implementation("org.reactivestreams:reactive-streams:1.0.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.8.0")
implementation("org.reactivestreams:reactive-streams:1.0.4")

implementation("com.google.guava:listenablefuture:1.0")
implementation("androidx.concurrent:concurrent-futures:1.2.0-alpha02")
implementation("androidx.concurrent:concurrent-futures-ktx:1.2.0-alpha02")
implementation("androidx.concurrent:concurrent-futures:1.2.0-alpha03")
implementation("androidx.concurrent:concurrent-futures-ktx:1.2.0-alpha03")
testImplementation("junit:junit:4.13.2")
testImplementation("io.kotest:kotest-assertions-core:4.0.7")
testImplementation("io.kotest:kotest-assertions-core:5.8.1")
testImplementation("io.kotest:kotest-assertions-jvm:4.0.7")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

dokkaPlugin("org.jetbrains.dokka:android-documentation-plugin:1.8.20")
dokkaPlugin("org.jetbrains.dokka:android-documentation-plugin:1.9.20")
}

publishing {
Expand Down
2 changes: 1 addition & 1 deletion plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ gradlePlugin {
dependencies {
implementation("com.android.tools.build:gradle:8.1.3")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("org.jetbrains.kotlinx.binary-compatibility-validator:org.jetbrains.kotlinx.binary-compatibility-validator.gradle.plugin:0.13.2")
}

0 comments on commit 407953c

Please sign in to comment.