|
| 1 | +/* |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.firebase.ai |
| 17 | + |
| 18 | +import androidx.test.platform.app.InstrumentationRegistry |
| 19 | +import com.google.firebase.FirebaseApp |
| 20 | +import com.google.firebase.FirebaseOptions |
| 21 | +import com.google.firebase.ai.type.GenerativeBackend |
| 22 | + |
| 23 | +class AIModels { |
| 24 | + |
| 25 | + companion object { |
| 26 | + private val API_KEY: String = "" |
| 27 | + private val APP_ID: String = "" |
| 28 | + private val PROJECT_ID: String = "fireescape-integ-tests" |
| 29 | + // General purpose models |
| 30 | + var app: FirebaseApp? = null |
| 31 | + var flash2Model: GenerativeModel? = null |
| 32 | + var flash2LiteModel: GenerativeModel? = null |
| 33 | + |
| 34 | + /** Returns a list of general purpose models to test */ |
| 35 | + fun getModels(): List<GenerativeModel> { |
| 36 | + if (flash2Model == null) { |
| 37 | + setup() |
| 38 | + } |
| 39 | + return listOf(flash2Model!!, flash2LiteModel!!) |
| 40 | + } |
| 41 | + |
| 42 | + fun app(): FirebaseApp { |
| 43 | + if (app == null) { |
| 44 | + setup() |
| 45 | + } |
| 46 | + return app!! |
| 47 | + } |
| 48 | + |
| 49 | + fun setup() { |
| 50 | + val context = InstrumentationRegistry.getInstrumentation().context |
| 51 | + app = |
| 52 | + FirebaseApp.initializeApp( |
| 53 | + context, |
| 54 | + FirebaseOptions.Builder() |
| 55 | + .setApiKey(API_KEY) |
| 56 | + .setApplicationId(APP_ID) |
| 57 | + .setProjectId(PROJECT_ID) |
| 58 | + .build() |
| 59 | + ) |
| 60 | + flash2Model = |
| 61 | + FirebaseAI.getInstance(app!!, GenerativeBackend.vertexAI()) |
| 62 | + .generativeModel( |
| 63 | + modelName = "gemini-2.0-flash", |
| 64 | + ) |
| 65 | + flash2LiteModel = |
| 66 | + FirebaseAI.getInstance(app!!, GenerativeBackend.vertexAI()) |
| 67 | + .generativeModel( |
| 68 | + modelName = "gemini-2.0-flash-lite", |
| 69 | + ) |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments