Skip to content

feat(ai): add GLM Interactions API prototype - #16637

Draft
andrewheard wants to merge 4 commits into
mainfrom
ah/ai-glm-interactions-api-prototype
Draft

feat(ai): add GLM Interactions API prototype#16637
andrewheard wants to merge 4 commits into
mainfrom
ah/ai-glm-interactions-api-prototype

Conversation

@andrewheard

@andrewheard andrewheard commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Added prototype Interactions API support to GeminiLanguageModel and added a gfm CLI sample tool for manual testing and experimentation.

  • Extracted shared models into GeminiSharedDataModels and added InteractionsDataModels generated from the Gemini Interactions OpenAPI spec.
  • Added Interactions URL routing (/interactions) and SSE streaming to GeminiAPIClient.
  • Added GeminiLanguageModel.APIVariant (.generateContent and .interactions) and implemented bidirectional translation between Foundation Models transcripts and Interactions requests.
  • Parameterized integration tests across API variants, gracefully cancelling on backends where Interactions proxying is not yet supported.

gfm CLI Sample Tool

  • Created a command-line utility in GeminiLanguageModel/Samples/gfm supporting single prompts (respond), interactive multi-turn chat (chat), model availability checks (available), and schema inspection (schema object).
  • Added --api-variant (alias --api) to select between generate-content and interactions.
  • Added session persistence and resumption under ~/.fm/sessions/.
gfm CLI Overview & Usage Guide

Overview

gfm is a command-line utility modeled after Apple's fm (Foundation Models) CLI. It provides an interface to test prompt generation, multi-turn streaming chat, model availability, and structured JSON schemas using Google Gemini (GeminiLanguageModel) and Apple System models (SystemLanguageModel).

Requirements & Setup

  • Platforms: macOS 26.0+ (macOS 27.0+ for SystemLanguageModel), or iOS 27.0+ Simulator
  • Toolchain: Swift 6.0+ / Xcode 26.2+
  • Authentication: Export your Gemini API key in your shell:
    export GOOGLE_API_KEY="your-gemini-api-key" # or GEMINI_API_KEY

Quickstart

# Run directly with SwiftPM
swift run --package-path GeminiLanguageModel/Samples/gfm gfm available
swift run --package-path GeminiLanguageModel/Samples/gfm gfm respond "Explain Swift concurrency."
swift run --package-path GeminiLanguageModel/Samples/gfm gfm chat

# Or compile a release binary
swift build --package-path GeminiLanguageModel/Samples/gfm -c release
./GeminiLanguageModel/Samples/gfm/.build/release/gfm --help

Commands

  • gfm available: Evaluates model availability on the system (-m gemini, -m system).
  • gfm respond: Single prompt response with real-time streaming:
    # Standard prompt
    gfm respond "Write a haiku about Swift."
    
    # Select API variant (Generate Content vs. Interactions API)
    gfm respond --api interactions "Explain quantum computing."
    
    # Pipe standard input
    cat article.txt | gfm respond "Summarize the key takeaways."
    
    # Structured JSON output & system instructions
    gfm respond -i "You are a code reviewer." "Review this function."
    gfm respond --schema schema.json "Generate mock user data."
  • gfm chat: Interactive multi-turn chat session with session persistence:
    gfm chat
    gfm chat --api interactions
    gfm chat -r "previous-session"   # Resume a saved session
    gfm chat -c                      # Continue the most recent session
    In-chat commands: /help, /clear, /sessions, /exit.
  • gfm schema object: Previews and validates structured JSON schema definitions.

Running on iOS 27 Simulator via Xcode

For testing on machines running macOS 26:

  1. Open GeminiLanguageModel/Samples/gfm/Package.swift in Xcode.
  2. Select the gfm executable scheme and choose an iOS 27 Simulator destination (e.g. iPhone 17 Pro).
  3. Open Product > Scheme > Edit Scheme... (⌘<):
    • Arguments: Add arguments under Arguments Passed On Launch (e.g. respond "Hello" or chat).
    • Environment Variables: Add GOOGLE_API_KEY with your API key value.
    • (Optional): Under Options, set Console to Use standard console for interactive sessions.
  4. Press ⌘R to run and view streaming output in Xcode's console.

#no-changelog

Add support for the Gemini Interactions API alongside the existing
Generate Content API in GeminiLanguageModel.

* Extract shared data models (`JSONValue` and `GoogleCloudAPIError`)
  into `GeminiSharedDataModels`.
* Add `InteractionsDataModels` containing Swift types generated from
  the Gemini Interactions OpenAPI specification.
* Implement Interactions URL routing and SSE streaming in
  `GeminiAPIClient`.
* Introduce `GeminiLanguageModel.APIVariant` to toggle between
  Generate Content and Interactions API backends.
* Implement transcript and request translators for the Interactions
  API and branch executor execution accordingly.
* Parameterize all integration tests across supported backends and
  API variants, gracefully cancelling Interactions tests for
  Firebase AI Logic until proxy support is available.
Synchronize the root Package.swift with the target configuration from
GeminiLanguageModel/Package.swift to support the new Interactions API.

* Add `GeminiSharedDataModels` and `InteractionsDataModels` targets.
* Update `GeminiLanguageModel`, `GeminiAPIClient`, and
  `GeminiAPIDataModels` target dependencies to include the shared and
  interactions data model targets.
* Add missing dependency on `GeminiAPIClient` and exclude `README.md`
  in `GeminiTestUtilities`.
* Exclude `README.md` and `IntegrationTests/README.md` in
  `GeminiLanguageModelTests`.
Add the `gfm` CLI sample tool along with package trait support for
direct Gemini Developer API authentication via environment variables.

* Add `gfm` CLI tool in `GeminiLanguageModel/Samples/gfm` supporting
  content generation, streaming, multi-turn chat, model availability
  evaluations, and JSON schema inspection.
* Add `GeminiDeveloperAPIEnvironmentAuth` package trait to conditionally
  expose standalone `GeminiLanguageModel` initialization.
* Implement environment API key resolution in `GeminiLanguageModel`,
  preferring `GOOGLE_API_KEY` over `GEMINI_API_KEY`.
* Add `GeminiLanguageModel.Error.missingAPIKey` when required
  credentials are not found in the environment.
* Expose standard `EndpointConfiguration.geminiDeveloperAPI` static
  endpoint property.
* Add unit test coverage for trait-gated initializers and key resolution
  precedence without mutating process environment state.
Add support for selecting the Gemini Interactions API variant from the
CLI in the `gfm` utility, and enable building and testing for iOS 27
Simulator environments.

* Add `--api-variant` and `--api` options to `respond`, `chat`, and
  `available` commands in `gfm`.
* Define `APIVariantChoice` in `GFMCore` conforming to
  `ExpressibleByArgument` to cleanly parse API variants without
  retroactive conformance warnings.
* Forward configured API variants through `ModelResolver` to
  `GeminiLanguageModel`.
* Expose public `apiVariant` property on `GeminiLanguageModel`.
* Add `.iOS(.v18)` to `gfm/Package.swift` and update `main.swift` and
  `SessionManager` to build cleanly for iOS Simulator.
* Add unit tests for argument parsing, command defaults, and model
  variant configuration.
* Update `gfm` documentation with Xcode iOS Simulator execution steps.
@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant