Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
0489240
update chat
hoangchungk53qx1 Jan 14, 2024
f1b6acb
update deps
hoangchungk53qx1 Jan 14, 2024
a7a3d8c
rename param match overriding method
hoangchungk53qx1 Jan 14, 2024
28a07a0
enable ComposeCompilerMetric
hoangchungk53qx1 Jan 14, 2024
1cf1870
update input mode
hoangchungk53qx1 Jan 14, 2024
06fd93e
Merge branch 'main' into main
hoangchungk53qx1 Jan 18, 2024
27aff1d
Merge branch 'main' into main
hoangchungk53qx1 Jan 31, 2024
d8ab47f
Update build_release.yml
hoangchungk53qx1 Jan 31, 2024
781855a
Update check-code-format.yml
hoangchungk53qx1 Jan 31, 2024
6357400
Update check-licensing.yml
hoangchungk53qx1 Jan 31, 2024
3fa89cb
Update check_for_api_changes.yml
hoangchungk53qx1 Jan 31, 2024
d62cb0f
Update generate_docs.yml
hoangchungk53qx1 Jan 31, 2024
6eb2731
Update generate_docs.yml
hoangchungk53qx1 Jan 31, 2024
a5ba042
Update unit-tests.yml
hoangchungk53qx1 Jan 31, 2024
17e1fa1
Merge branch 'main' into main
hoangchungk53qx1 Feb 24, 2024
5bb04e4
[#75] Fix: set default value for `role` in public Content class and b…
PatilShreyas Mar 8, 2024
2cecdba
Release 0.2.2 (#81)
rlazo Mar 14, 2024
87469b6
Encode default value for content (#82)
rlazo Mar 14, 2024
bd5f554
Update sample app to use v0.2.2 (#83)
rlazo Mar 14, 2024
39396f0
Common & genai sdk split (#88)
rlazo Mar 20, 2024
4638406
Expand RequestOptions class in common (#89)
rlazo Mar 20, 2024
b2afc55
Add support for usage metadata (#91)
rlazo Mar 22, 2024
672f0a4
Add support for FileData (#92)
daymxn Mar 22, 2024
47135cf
added quota exceeded exception (#93)
davidmotson Mar 25, 2024
849f432
Depend on right mockk version (#94)
rlazo Mar 25, 2024
a2b71df
Function calling (common only) (#97)
rlazo Mar 26, 2024
ab722b6
Bump futures dependency (#98)
rlazo Mar 27, 2024
40f496e
Don't encode the model name in the outgoing request (#101)
rlazo Mar 28, 2024
f22a52f
split the auto function calling changes between common and generative…
davidmotson Apr 2, 2024
00101fd
Merge branch 'main' into main
hoangchungk53qx1 Apr 3, 2024
f14808f
Add constrained decoding support (#103)
emilypgoogle Apr 3, 2024
91d69a9
Make candidateTokenCount optional for cases with no candidate (#104)
davidmotson Apr 3, 2024
6bc885f
Add clientId parameter in common (#107)
rlazo Apr 3, 2024
77483c3
Use a consistent naming for apiClient (#108)
rlazo Apr 3, 2024
30050e4
Add `totalBillableCharacters` to `CountTokensResponse` (#106)
rlazo Apr 3, 2024
4179344
Support releasing multiple SDKs (#109)
daymxn Apr 4, 2024
b65c155
Add support for header provider (#110)
rlazo Apr 4, 2024
1fddbab
Fix API job for new locations of api (#113)
davidmotson Apr 5, 2024
69b5610
add SystemInstruction as a param to GenerativeModel and wire it throu…
davidmotson Apr 9, 2024
753cb33
keep GenerativeModel's original parameter positions (#115)
thatfiredev Apr 9, 2024
56cf778
Bump release versions (#117)
rlazo Apr 10, 2024
287e9bb
update sample app to use v0.3.0 (#118)
thatfiredev Apr 11, 2024
2d9f5db
Make license optional and default start index to 0 for citations (#120)
rlazo Apr 18, 2024
9476b4f
Make v1beta the default api version (#123)
rlazo Apr 19, 2024
c8a0a37
Add support for FileDataPart in the request (#121)
rlazo Apr 19, 2024
910252b
Add support for SafetyRating.HarmSeverity in common (#122)
rlazo Apr 19, 2024
3f253ab
Bump generative ai sdk to 0.4.0 (#124)
rlazo Apr 19, 2024
28877bc
Update README.md (#125)
rlazo Apr 24, 2024
dd2bcaf
Fix release plugin (#126)
daymxn Apr 24, 2024
a081fb3
Remove usages of Beta flag (#127)
daymxn Apr 25, 2024
146c4d6
Correctly handle UsageMetadata (#135)
rlazo May 3, 2024
1d12b81
Bump release to 0.5.0 (genai) 0.4.0 (common) (#136)
rlazo May 3, 2024
fcb2f99
Fix API warning task (#138)
daymxn May 6, 2024
c2512bc
Add common proguard rules (#141)
emilypgoogle May 6, 2024
21be798
replaced functionCall with functionCalls (#137)
davidmotson May 6, 2024
14c0ba6
Add responseMimeType support (#133)
daymxn May 7, 2024
3e9727b
Add allstar configuration for binary artifacts
rlazo May 7, 2024
3c6c73c
fix typo for deprecation of functionCall (#142)
davidmotson May 8, 2024
c746583
add tests for generative content response and change #text to return …
davidmotson May 9, 2024
0dc70bf
Bump versions to 0.6.0 (generativeai) and 0.5.0 (common) (#145)
rlazo May 13, 2024
440e6b1
Bump dependency version on the SDK (#146)
rlazo May 13, 2024
2d33569
Add responseMimeType to helper builder for GenerationConfig (#151)
emilypgoogle May 17, 2024
35ee750
Add missing serialization definitions for common (#150)
emilypgoogle May 17, 2024
8868baa
add new error for disabled service, with test (#148)
davidmotson May 22, 2024
77501f5
Update ktfmt (#156)
daymxn May 28, 2024
8ba2c7d
Update sample app to use model 1.5-flash (#157)
tanzimfh May 28, 2024
3eca96a
Support for json schema (#155)
rlazo May 29, 2024
826ff67
Bump version to 0.7.0 (#161)
rlazo May 30, 2024
5f02a32
Bump version to latest SDK release (#163)
rlazo May 30, 2024
b1803c4
make args nullable in parsing and add test, also specify that we expe…
davidmotson May 31, 2024
28016d1
add optional param for Schema.arr to specify objects in array (#159)
davidmotson Jun 4, 2024
9c4aaf0
Make CountTokenRequest contain the full request (#152)
davidmotson Jun 10, 2024
ad4e12b
Version 0.8.0 (#177)
emilypgoogle Jun 10, 2024
6b406cf
Add changelog requirement action for major/minor bumps (#174)
emilypgoogle Jun 10, 2024
f161052
Make common parse lenient (#179)
daymxn Jun 12, 2024
d8139ed
Common 0.7.1 release (#180)
daymxn Jun 12, 2024
12274f4
Simplify function calling (#176)
daymxn Jun 17, 2024
bc9778c
fix int type, add long type, rename double type (#184)
davidmotson Jun 17, 2024
6c5550f
Aligning the README with the Python one. (#185)
Giom-V Jun 27, 2024
69329f7
Davidmotson.code execution (#186)
davidmotson Jun 28, 2024
e4b9381
GenAI 0.9.0 + Common 0.8.0 release (#188)
daymxn Jul 2, 2024
13b4d44
Fix unknown enum test (#190)
rlazo Jul 3, 2024
f0559c8
Bump sample app for 0.9.0 (#191)
daymxn Jul 3, 2024
dcd713e
Merge branch 'main' into main
hoangchungk53qx1 Jul 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .allstar/binary_artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignorePaths:
- generativeai-android-sample/gradle/wrapper/gradle-wrapper.jar
- gradle/wrapper/gradle-wrapper.jar
26 changes: 22 additions & 4 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,35 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: gradle
- name: Perform a Gradle build
- name: Build the generativeai release artifacts
run: ./gradlew generativeai:publishAllPublicationsToMavenRepository

- name: Upload generated artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4

with:
name: generative-ai-android
path: generativeai/m2
retention-days: 5
- name: Build the common release artifacts
run: ./gradlew common:publishAllPublicationsToMavenRepository
- name: Upload the common artifacts
uses: actions/upload-artifact@v2
with:
name: common-artifacts
path: common/m2
retention-days: 5
- name: Build the release artifacts for all sdks
run: ./gradlew publishAllPublicationsToMavenRepository
- name: Upload the generated artifacts
uses: actions/upload-artifact@v2
with:
name: release-artifacts
path: m2
retention-days: 5
4 changes: 2 additions & 2 deletions .github/workflows/check-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check-licensing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
Expand Down
22 changes: 14 additions & 8 deletions .github/workflows/check_for_api_changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,46 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: gradle

- name: Generate the api file
run: |
./gradlew generativeai:exportApi --no-daemon
./gradlew exportApi --no-daemon

- name: Save public.api from master
run: mv generativeai/public.api ~/public.api
run: |
mkdir ~/common/ && \
mkdir ~/generativeai/ && \
mv generativeai/public.api ~/generativeai/public.api && \
mv common/public.api ~/common/public.api

- name: Checkout branch
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: gradle

- name: Copy saved api to branch
run: mv ~/public.api generativeai/public.api
run: |
mv ~/generativeai/public.api generativeai/public.api && \
mv ~/common/public.api common/public.api

- name: Run api warning task
run: |
./gradlew generativeai:warnAboutApiChanges --no-daemon
./gradlew warnAboutApiChanges --no-daemon

- name: Add PR Comment
if: ${{ hashFiles('api_changes.md') != '' }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/generate_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: gradle
- name: Run dokka
run: ./gradlew generativeai:dokkaHtml
- name: Upload generated docs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: google-ai-android
path: generativeai/build/dokka/html
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/warn-version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Warn Version Bump

on: pull_request

jobs:
warn-version-bump:
runs-on: ubuntu-latest
steps:
- name: Checkout target branch
uses: actions/[email protected]
with:
ref: ${{ github.base_ref }}

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: gradle

- name: Generate the api file
run: |
./gradlew exportApi --no-daemon

- name: Save public.api from target branch
run: |
mkdir ~/common/ && \
mkdir ~/generativeai/ && \
mv generativeai/public.api ~/generativeai/public.api && \
mv common/public.api ~/common/public.api

- name: Checkout branch
uses: actions/[email protected]

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: gradle

- name: Copy saved api to branch
run: |
mv ~/generativeai/public.api generativeai/public.api && \
mv ~/common/public.api common/public.api
- name: Run API versioning check
run: |
if ! test -d .changes || git diff --quiet ${{ github.event.pull_request.base.sha }}..HEAD .changes ; then ./gradlew warnVersionBump ; else exit 0 ; fi
24 changes: 19 additions & 5 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ hooks, run the following command at the root of your repo directory:

To locally publish the m2 repo:

`./gradlew generativeai:publishToMavenLocal`
`./gradlew publishToMavenLocal`

To generate a releasable m2 repo:

`./gradlew generativeai:publishAllPublicationsToMavenRepository`
`./gradlew publishAllPublicationsToMavenRepository`

The m2 repo will be in `generativeai/m2`.
The m2 repo will be in `/m2`.

To generate Dokka:
To generate Dokka for the generativeai project:

`./gradlew generativeai:dokkaHtml`

Expand Down Expand Up @@ -60,6 +60,20 @@ change
Both of these commands should generate a new file under the `.changes` directory with your message
and impact.

Note though, that this will naturally create release notes for *all* projects. If you only want
to generate a change for the `generativeai` project, then prefix your message with the project name:

To learn more, read the section on our changelog plugin in our [plugin readme](./plugins/README.md).
```bash
change generativeai "hello world!"
```

You can also do it for other projects as well, just supply the project name:

```bash
change common "hello world!"
```

Although, this does *not* support creating empty changes. You'll have to make that change manually,
if that's what you want.

To learn more, read the section on our changelog plugin in our [plugin readme](./plugins/README.md).
70 changes: 38 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,66 @@
# 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:
- Generate text from text-only input
- Generate text from text-and-images input (multimodal)
- Build multi-turn conversations (chat)
The Google AI Android SDK is the easiest way for Android developers to build with the Gemini API. The Gemini API gives you access to Gemini [models](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). Gemini models are built from the ground up to be multimodal, so you can reason seamlessly across text, images, and code.

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(
modelName = "gemini-1.0-pro-vision-latest",
apiKey = BuildConfig.apiKey
)

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

val response = generativeModel.generateContent(inputContent)
print(response.text)
```
> [!CAUTION]
> **The Google AI SDK for Android is recommended for prototyping only.** If you plan to enable billing, we strongly recommend that you use a backend SDK to access the Google AI Gemini API. You risk
> potentially exposing your API key to malicious actors if you embed your API key directly in your Android app or fetch it remotely at runtime.

> [!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.

## Try out the sample Android app
## Get started with the Gemini API

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
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.\
1. Go to [Google AI Studio](https://aistudio.google.com/).
2. Login with your Google account.
3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available.
4. Check out this repository.\
`git clone https://github.com/google/generative-ai-android`
5. Open and build the sample app in the `generativeai-android-sample` folder of this repo.
6. Paste your API key into the `apiKey` property in the `local.properties` file.
7. Run the app
5. For detailed instructions, try the
[Android SDK tutorial](https://ai.google.dev/tutorials/android_quickstart) on [ai.google.dev](https://ai.google.dev).

## Usage example

1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs.
1. Add the dependency `implementation("com.google.ai.client.generativeai:generativeai:<version>"`) to your Android project.

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

1. Paste your API key into the `apiKey` property in the `local.properties` file.
```kotlin
val generativeModel = GenerativeModel(
modelName = "gemini-1.5-pro-latest",
apiKey = BuildConfig.apiKey
)
```

1. Run the app.
3. Run a prompt.

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

Add the dependency `implementation("com.google.ai.client.generativeai:generativeai:<version>"`) to your Android project.
val response = generativeModel.generateContent(inputContent)
print(response.text)
```

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.

## Documentation

Find complete documentation for the Google AI SDKs and the Gemini model in the Google documentation:\
https://ai.google.dev/docs
See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation.

## 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.
Expand Down
Loading