refactor(llm): add AI SDK, reroute Gemini calls to it

🟢 open · #165 · Open-Legal-Products/mike ← LoneRifle/mike · opened 2mo ago by LoneRifle · +306-5,540 across 4 files · ↗ on GitHub

From the PR description

Motivation

Provide the plumbing needed to interact with providers through Vercel's AI SDK. Use it to direct Gemini-driven completeText() calls (mostly invoked for titles and summaries)

Provide an implementation for stream chat with tools using AI SDK, wiring Gemini calls to this. Take reference from the other LLM integrations and faithfully reproduce impl as close as possible.

  • Define MODEL_PROVIDER_CONFIGS, each Provider mapping to:

    • a AI SDK ProviderV3 factory function
    • the Provider default API key, or an empty str if not set
    • the env var name for the key, for error messages
  • Implement resolveModel(), using the above

  • Replace the gemini branch of completeText() with the fallthrough to resolveModel() and generateText()

  • Map streamChatWithTools() to streamText()

    • Wire all relevant events from the stream to callbacks
    • Collate full text response as well as all tool calls
    • Append assistant and tool messages at the end

Part 1/3 for #160

Our analysis

Wire Gemini through the Vercel AI SDK — read the full analysis →

Think the analysis missed something the PR description covers?

Capture this PR into my fork

Download a Markdown prompt that tells Claude how to port every commit in this PR into your working tree. Run it via claude -p < capture-pull-165.md from inside the repo you want the changes in.

⬇ Download capture-pull-165.md