-
Notifications
You must be signed in to change notification settings - Fork 614
fix: provider db parse image type #1113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds model type normalization and inference throughout the data pipeline. The provider database fetch script normalizes model types by lowercasing and standardizing format. A new schema field and type helper support model type metadata. A new inference method enables dynamic type determination based on explicit values or inferred modalities. Changes
Sequence Diagram(s)sequenceDiagram
participant DB as Provider DB
participant Fetch as fetch-provider-db.mjs
participant Schema as model-db.ts
participant Config as modelConfig.ts
DB->>Fetch: Raw model data
Fetch->>Fetch: Normalize type field<br/>(lowercase, remove _, -)
Fetch->>Schema: Sanitized model with type
Schema->>Schema: Apply getModelTypeValue()<br/>parse & validate type
Schema->>Schema: Populate ModelSchema.type
Config->>Config: inferModelType() priority:<br/>1) explicit type<br/>2) modalities inference<br/>3) default Chat
Config->>Config: buildConfigFromProviderModel<br/>uses inferred type
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/main/presenter/configPresenter/modelConfig.ts (1)
54-83: Type inference logic is sound; consider optional richer heuristics for non-image modelsThe new
inferModelTypecorrectly:
- Respects normalized
model.typefrom the provider DB (chat,embedding,rerank,imageGeneration).- Falls back to
ImageGenerationwhenmodalities.outputincludes'image'.- Defaults to
Chatwhen nothing is specified, preserving previous behavior for unknown models.This should fix the image-type parsing issue for provider DB entries.
If you later see providers that omit
typefor embeddings or rerankers, you might consider extending the modalities-based inference (e.g., output containing'embedding'or some rerank-specific marker) before defaulting to chat. Not required for this bugfix, but worth keeping in mind.Also applies to: 93-93
src/shared/types/model-db.ts (1)
56-57: Schema + normalization pipeline for model.type/cost is coherent; just note coupling with the fetch scriptThe additions here are internally consistent:
ModelSchema.costasz.record(z.union([z.string(), z.number()])).optional()matchesgetStringNumberRecord, ensuringcostis a flat map of primitive values.ModelSchema.typeplusModelTypeValue('chat' | 'embedding' | 'rerank' | 'imageGeneration') lines up withModelConfigHelper.inferModelTypeand the values used in the UI.getModelTypeValuecorrectly:
- Accepts exact standard values including
'imageGeneration'.- Normalizes variants like
image_generation,image-generation,image-gen, and differing case to'imageGeneration'.- Returns
undefinedfor unknowns sotyperemains optional.
sanitizeAggregatethen uses bothgetStringNumberRecordandgetModelTypeValue, so runtime data passed around asProviderModelshould always matchModelSchema.The only thing to keep an eye on is the duplication of this normalization with
sanitizeAggregateJsoninscripts/fetch-provider-db.mjs. If a new model type or alias is introduced, both places will need to be updated together.Also applies to: 134-134, 161-188, 301-302
scripts/fetch-provider-db.mjs (1)
103-119: Model type normalization is correct but duplicated; document coupling or consider centralizingThe type normalization from
m.typeto'chat' | 'embedding' | 'rerank' | 'imageGeneration'(includingimage_generation/image-generationvariants) is working correctly, as confirmed by the generatedproviders.jsonoutput showing normalized types. However, this logic is duplicated in two places—here and ingetModelTypeValuefromsrc/shared/types/model-db.ts—which increases drift risk if new types are added later.Additionally,
costis passed through as any object without type validation, while the shared sanitizer expectsRecord<string, string | number>. This creates a potential type-shape mismatch.Suggested actions:
- Add a comment referencing
getModelTypeValueto document the coupling and warn future maintainers to keep both branches in sync.- After running the fetch script, verify that
costvalues inproviders.jsonconform to the expected shape or align validation here with the shared schema.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
scripts/fetch-provider-db.mjs(2 hunks)src/main/presenter/configPresenter/modelConfig.ts(2 hunks)src/shared/types/model-db.ts(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/main/presenter/configPresenter/modelConfig.ts (1)
src/shared/types/model-db.ts (1)
ProviderModel(60-60)
src/shared/types/model-db.ts (1)
scripts/fetch-provider-db.mjs (1)
normalized(108-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build-check (x64)
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.