Skip to content

Refactor model detection to use modelPricing.json data#151

Merged
rajbos merged 3 commits intomainfrom
copilot/refactor-hardcoded-model-names
Jan 30, 2026
Merged

Refactor model detection to use modelPricing.json data#151
rajbos merged 3 commits intomainfrom
copilot/refactor-hardcoded-model-names

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Hard-coded model name mappings in getModelFromRequest made adding new models require code changes. This refactors model detection to be data-driven using modelPricing.json.

Changes

  • Added displayNames field to modelPricing.json: Maps display names found in session logs to model IDs for 13 models
  • Updated ModelPricing interface: Added optional displayNames?: string[] field
  • Refactored getModelFromRequest method: Replaced 13 hard-coded conditionals with dynamic lookup from modelPricing.json

Before

if (request.result.details.includes('Claude Sonnet 3.5')) { return 'claude-sonnet-3.5'; }
if (request.result.details.includes('Claude Sonnet 3.7')) { return 'claude-sonnet-3.7'; }
if (request.result.details.includes('GPT-4.1')) { return 'gpt-4.1'; }
// ... 10 more hard-coded checks

After

// Build reverse lookup: displayName -> modelId
const displayNameToModelId: { [displayName: string]: string } = {};
for (const [modelId, pricing] of Object.entries(this.modelPricing)) {
  if (pricing.displayNames) {
    for (const displayName of pricing.displayNames) {
      displayNameToModelId[displayName] = modelId;
    }
  }
}

// Match longest names first to handle overlaps (e.g., "Gemini 3 Pro (Preview)" vs "Gemini 3 Pro")
const sortedDisplayNames = Object.keys(displayNameToModelId).sort((a, b) => b.length - a.length);
for (const displayName of sortedDisplayNames) {
  if (request.result.details.includes(displayName)) {
    return displayNameToModelId[displayName];
  }
}

New models now require only JSON updates, no code changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>[REFACTOR] Don't hard code model names</issue_title>
<issue_description>Ensure these data are removed here and retrieved from their primary store (whichever that is):

private getModelFromRequest(request: any): string {
// Try to determine model from request metadata
if (request.result && request.result.metadata && request.result.metadata.modelId) {
return request.result.metadata.modelId;
}
if (request.result && request.result.details) {
if (request.result.details.includes('Claude Sonnet 3.5')) { return 'claude-sonnet-3.5'; }
if (request.result.details.includes('Claude Sonnet 3.7')) { return 'claude-sonnet-3.7'; }
if (request.result.details.includes('Claude Sonnet 4')) { return 'claude-sonnet-4'; }
if (request.result.details.includes('Gemini 2.5 Pro')) { return 'gemini-2.5-pro'; }
if (request.result.details.includes('Gemini 3 Pro (Preview)')) { return 'gemini-3-pro-preview'; }
if (request.result.details.includes('Gemini 3 Pro')) { return 'gemini-3-pro'; }
if (request.result.details.includes('GPT-4.1')) { return 'gpt-4.1'; }
if (request.result.details.includes('GPT-4o-mini')) { return 'gpt-4o-mini'; }
if (request.result.details.includes('GPT-4o')) { return 'gpt-4o'; }
if (request.result.details.includes('GPT-4')) { return 'gpt-4'; }
if (request.result.details.includes('GPT-5')) { return 'gpt-5'; }
if (request.result.details.includes('GPT-3.5-Turbo')) { return 'gpt-3.5-turbo'; }
if (request.result.details.includes('o3-mini')) { return 'o3-mini'; }
if (request.result.details.includes('o4-mini')) { return 'o4-mini'; }
}
return 'gpt-4'; // default
}

If the data are stored, it would be here: https://github.com/rajbos/github-copilot-token-usage/blob/main/src/modelPricing.json

I prefer to store the model ID and not the name.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: rajbos <6085745+rajbos@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor hard coded model names to use primary store Refactor model detection to use modelPricing.json data Jan 30, 2026
Copilot AI requested a review from rajbos January 30, 2026 12:44
@rajbos rajbos marked this pull request as ready for review January 30, 2026 13:15
@rajbos rajbos enabled auto-merge January 30, 2026 13:15
@rajbos rajbos merged commit dcc09dc into main Jan 30, 2026
12 checks passed
@rajbos rajbos deleted the copilot/refactor-hardcoded-model-names branch January 30, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REFACTOR] Don't hard code model names

2 participants

Comments