Git Product home page Git Product logo

gemini-pro-api-android-sample's Introduction

This codebase serves as a demonstration of the implementation of Gemini Pro Gen-AI using the "Google AI client SDK".

Demo

Gemini-Pro-Android-Sample.mp4

Implementation details

This sample code repository utilizes Gemini Pro APIs with clean architecture principles, Examine the code to gain insights into the implementation details.

If you want to get started quickly follow the below steps:

Add SDK dependency: Add the following in module-level (app) build.gradle.kts file

implementation("com.google.ai.client.generativeai:generativeai:0.1.1")

Generate your API Key
You need to generate an API Key from Google AI Studio. Follow this steps to generate your key.

Create your model
Create your GenAI Model object, pass the API key generated in above step here.

val geminiProModel = GenerativeModel(
    modelName = "gemini-pro",
    apiKey = <YOUR_API_KEY>
)

Browse through the sample code to:

  • Secure your API key with gradle-secrets-plugin, this way the apiKey would reside in your local.properties file and won't be included in your Version Control System.
  • See how to implemented this as a datasource in data layer.

Input the prompt to the model
Single prompt with no context:

val prompt = "Write a story about a magic backpack."
val response = geminiProModel.generateContent(prompt)
print(response.text)

Starting a conversion:

val chat = geminiProModel.startChat()
val response = chat.sendMessage(message)
print(response.text)

Note: If you intend to clone and experiment with the provided sample code, it is necessary to generate an API key in "Google AI Studio." Subsequently, place this key in the local.properties file under the variable name "apiKey".

Contact me ๐Ÿ“ง

gemini-pro-api-android-sample's People

Contributors

harshnandwani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.