Skip to content

Dynamically fetch available LLM models from providers - #60

Open
mingweiliao wants to merge 1 commit into
android:mainfrom
mingweiliao:update-gemini-llm-model-config
Open

mingweiliao wants to merge 1 commit into
android:mainfrom
mingweiliao:update-gemini-llm-model-config

Conversation

@mingweiliao

Copy link
Copy Markdown
Contributor

Summary

Replaces the hardcoded LlmModel enum in the sample agent with dynamic model discovery from configured LLM providers, so newly released models are available automatically without requiring code changes.

Key Changes

  • Dynamic LlmModel representation:
    • Converted LlmModel from a hardcoded enum class to a @Serializable data class LlmModel(val providerName: LlmProviderName, val modelName: String).
  • Provider model discovery (LlmProvider.getAvailableModels):
    • Added suspend fun getAvailableModels(apiKey: String?): List<LlmModel> to LlmProvider.
    • Implemented GeminiProviderImpl.getAvailableModels to query GET https://generativelanguage.googleapis.com/v1beta/models?pageSize=100 and filter for gemini-* models supporting generateContent.
  • UI & ViewModel updates:
    • Updated AgentDemoViewModel to fetch available models across providers when API keys change and automatically create an initial thread once models are available.
    • Made AgentUiState.Loaded.currentThread nullable so the app loads cleanly instead of staying on the loading spinner when no API key or thread exists yet.
    • Updated ModelDropdown in AgentDemoScreen to group models by LlmProviderName and handle empty model/thread states gracefully.
  • Screenshot & unit/integration tests:
    • Fixed screenshot test reference directory paths (com/example/appfunctionsstudio -> com/example/appfunctions/agent) and added/updated previews for loading and no-thread states.
    • Added unit and integration tests for getAvailableModels and updated existing test suites.

Test

  • ./gradlew spotlessCheck test validateScreenshotTest
  • ./gradlew connectedStandardDebugAndroidTest

@mingweiliao
mingweiliao requested a review from a team as a code owner October 23, 2026 13:53
- Replace hardcoded LlmModel enum with a serializable data class and Room TypeConverter
- Query the Gemini models API for gemini-* models supporting generateContent
- Group models by provider in the UI dropdown and handle empty model/thread states when no API key is configured
- Fix screenshot test reference image paths and update previews for the no-thread state
@mingweiliao
mingweiliao force-pushed the update-gemini-llm-model-config branch from ae4fe83 to bd4f213 Compare October 23, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant