A seguir

How to integrate Google's Gemini AI APIs in Kotlin code of your Android App?

0 Visualizações· 03/09/24
wisdom
wisdom
4,134 Assinantes
4,134
Dentro

This video shows quick steps to integrate the Gemini's, Google's AI tool, API in your Android App.

It refers to the below page for the steps to do this code:
https://ai.google.dev/tutorials/android_quickstart

Below link can be used to generate apikey required for the project:
https://aistudio.google.com/app/apikey?pli=1

I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com

Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/and....roid/how-to-integrat


However, the main Java code is copied below also for reference:

package com.programmerworld.geminiaiandroidapp

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.google.ai.client.generativeai.GenerativeModel
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}

public fun buttonGeminiAPI(view: View){
var textView = findViewById-TextView-(R.id.textView)
val generativeModel = GenerativeModel(
// For text-only input, use the gemini-pro model
modelName = "gemini-pro",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
apiKey = "AIzaSyAzkp__VSgSjb8jadu4hS87J_weHud6IY"
)
val prompt = "Write a story about a magic backpack."
MainScope().launch {
val response = generativeModel.generateContent(prompt)
textView.setText(response.text)
}
}
}

--

Mostre mais

 0 Comentários sort   Ordenar por


Comentários do Facebook

A seguir