Skip to content

refactor: Always return ModelInfo instance#1

Merged
tymondesigns merged 1 commit intomainfrom
refactor/always-return-model-info
May 21, 2025
Merged

refactor: Always return ModelInfo instance#1
tymondesigns merged 1 commit intomainfrom
refactor/always-return-model-info

Conversation

@tymondesigns
Copy link
Contributor

This pull request introduces significant updates to the Cortex\ModelInfo library, focusing on improving type safety, adding metadata support, and enhancing provider implementations. Key changes include replacing string-based model representations with a ModelInfo class, introducing metadata for models, and updating multiple providers to use the new structure.

Enhancements to Model Representation:

  • Updated ModelInfo class to include an optional metadata field and corresponding getMetadata method for retrieving metadata by key. Adjusted constructor to allow nullable cost fields (inputCostPerToken and outputCostPerToken). [1] [2]
  • Refactored ModelInfoProvider interface and related implementations (LiteLLMModelInfoProvider, LMStudioModelInfoProvider, OllamaModelInfoProvider) to return ModelInfo objects instead of strings, ensuring type safety. [1] [2] [3] [4]

Provider-Specific Improvements:

  • Added a new LMStudioModelInfoProvider to the default providers in ModelInfoFactory.
  • Enhanced OllamaModelInfoProvider and LiteLLMModelInfoProvider to map responses into ModelInfo objects, improving consistency and extensibility. [1] [2]
  • Updated LMStudioModelInfoProvider and OllamaModelInfoProvider to handle new metadata and improve response handling. [1] [2]

Enum and Type Updates:

  • Renamed the ModelType::Other enum case to ModelType::Unknown for clarity.
  • Adjusted ModelProvider methods to return ModelInfo objects instead of strings, aligning with the updated interface. [1] [2]

Documentation and Tests:

  • Updated PHPStan type definitions across the codebase to reflect the new ModelInfo structure and metadata support. [1] [2]
  • Added test coverage for metadata handling in ModelInfoFactoryTest.

These changes collectively improve the library's type safety, extensibility, and ability to handle richer model metadata.

@tymondesigns tymondesigns marked this pull request as ready for review May 21, 2025 08:03
@tymondesigns tymondesigns merged commit 8585916 into main May 21, 2025
12 checks passed
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.

1 participant