refactor(ai-provider): Replace any with explicit model types (#879) - #1242
Open
DAmensah27 wants to merge 1 commit into
Open
refactor(ai-provider): Replace any with explicit model types (#879)#1242DAmensah27 wants to merge 1 commit into
DAmensah27 wants to merge 1 commit into
Conversation
…o-Code#879) Replace the three `any` types in src/lib/ai-provider.ts with the `LanguageModel` type from the `ai` package (AI SDK v5), restoring type safety on the provider instance and the two fallback helpers: - ProviderConfig.instance - getAIModelWithFallback() return model - tryProvidersWithFallback() operation callback parameter `LanguageModel` is the idiomatic public type exported by `ai` (a direct dependency) and is what the openai()/google()/azure() model instances resolve to. tsc -p tsconfig.json passes with no errors.
Contributor
|
@DAmensah27 is attempting to deploy a commit to the vetswhocode-web-app Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace
anywithLanguageModelin the AI provider utilityCloses #879.
What & why.
src/lib/ai-provider.tsusedanyin three places that all describe the same thing — the AI SDK model instance returned byopenai()/google()/azure(). This PR types them withLanguageModelfrom theaipackage (AI SDK v5), restoring compile-time safety and editor autocomplete with no runtime change.Changes.
+ import type { LanguageModel } from "ai";ProviderConfig.instance: any→LanguageModelgetAIModelWithFallback()returnmodel: any→LanguageModeltryProvidersWithFallback()operation: (model: any) => …→(model: LanguageModel) => …Note on the type. The issue suggested
LanguageModelfrom@ai-sdk/provider, but in the installed v5 that package exportsLanguageModelV2and is only a transitive dependency.ai(a direct dependency) exportsLanguageModel = string | LanguageModelV2, which the concrete model instances satisfy and which is the type the SDK's own APIs (e.g.generateText) consume — so I imported fromai.Testing. Type-only change (annotation erased at compile time).
npm run typecheckpasses with no errors;biome lintis clean on the file.