Skip to content

Replace Vercel AI SDK with LangChain.js + LangSmith + Gemini 3 Flash #1009

@jeromehardaway

Description

@jeromehardaway

Context

The resume translator and career guides currently use the Vercel AI SDK (ai package) with gemini-2.0-flash — a speed-optimized model that hallucinates more than reasoning-class models. There is zero observability into LLM calls (no tracing, no token tracking, no latency metrics).

What

Replace the Vercel AI SDK with LangChain.js to get LangSmith observability out of the box, and upgrade to gemini-3-flash-preview for better reasoning and lower hallucination.

Tasks

Install dependencies

npm install langchain @langchain/google-genai @langchain/core langsmith @langchain/langgraph

Add LangSmith env vars to .env.example

LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=
LANGCHAIN_PROJECT=vwc-resume-translator
LANGSMITH_ENDPOINT=https://api.smith.langchain.com

Rewrite src/lib/ai-provider.ts

  • Replace Vercel AI SDK provider classes with LangChain equivalents
  • Use ChatGoogleGenerativeAI from @langchain/google-genai with model gemini-3-flash-preview
  • Keep fallback chain: Gemini → Azure → OpenAI
  • LangSmith tracing activates automatically when LANGCHAIN_TRACING_V2=true

Update src/pages/api/military-resume/translate.ts

  • Replace generateText() with LangChain .withStructuredOutput() using Zod schema
  • Eliminates fragile regex JSON parsing (text.match(/\{[\s\S]*\}/) at line 472)
  • Lower temperature from 0.70.3

Update src/pages/api/ai/chat.ts

  • Replace streamText() with LangChain streaming equivalent

Update 5 generation scripts

  • scripts/generate-career-pathways.ts
  • scripts/generate-cert-equivalencies.ts
  • scripts/generate-cognitive-skills.ts
  • scripts/generate-military-systems.ts
  • scripts/generate-training-pipeline.ts
  • Replace google("gemini-2.0-flash") with ChatGoogleGenerativeAI({ model: "gemini-3-flash-preview" })

Remove old dependencies from package.json

  • ai, @ai-sdk/azure, @ai-sdk/google, @ai-sdk/openai

Verification

  • npm run build passes
  • Submit a translation for MOS 11B → verify trace appears in LangSmith dashboard
  • Confirm fallback works: disable Gemini key → Azure/OpenAI picks up

Files

  • package.json
  • .env.example
  • src/lib/ai-provider.ts
  • src/pages/api/military-resume/translate.ts
  • src/pages/api/ai/chat.ts
  • scripts/generate-career-pathways.ts
  • scripts/generate-cert-equivalencies.ts
  • scripts/generate-cognitive-skills.ts
  • scripts/generate-military-systems.ts
  • scripts/generate-training-pipeline.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions