Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 25, 2025

Summary

This PR refactors the HuggingFace provider implementation to match the established pattern used by other providers that fetch models via network calls (e.g., OpenRouter, Glama, Ollama).

Changes

  • Moved fetcher to correct location: Moved huggingface-models.ts from src/services/ to src/api/providers/fetchers/huggingface.ts
  • Updated fetcher to return ModelInfo: The fetcher now returns Record<string, ModelInfo> instead of raw HuggingFace model data, consistent with other providers
  • Integrated with model cache: Added HuggingFace to RouterName type and integrated it with the modelCache.ts system for memory and file caching
  • Updated provider to extend RouterProvider: The HuggingFace provider now extends the RouterProvider base class and uses the fetchModel() pattern
  • Removed unnecessary wrapper: Deleted src/api/huggingface-models.ts as it's no longer needed
  • Updated webview integration: Modified webviewMessageHandler.ts to use the new pattern with getModels() while maintaining backward compatibility

Benefits

  1. Consistency: HuggingFace now follows the same pattern as other providers
  2. Caching: Model lists are now cached in memory and on disk
  3. Maintainability: Easier to understand and modify when all providers follow the same pattern
  4. Type safety: Better integration with TypeScript types

Testing

  • ✅ All existing tests pass
  • ✅ TypeScript compilation successful
  • ✅ Linting checks pass
  • ✅ Added HuggingFace to RouterModels mock in webview tests

Important

Refactor HuggingFace provider to align with other providers, improving consistency, caching, and maintainability.

  • Behavior:
    • Refactor HuggingFace provider to align with other providers like OpenRouter and Glama.
    • huggingface-models.ts moved to src/api/providers/fetchers/huggingface.ts.
    • Fetcher now returns Record<string, ModelInfo> instead of raw data.
    • Integrated HuggingFace with modelCache.ts for caching.
    • Updated webviewMessageHandler.ts to use getModels() for HuggingFace.
  • Classes & Functions:
    • HuggingFaceHandler now extends RouterProvider and uses fetchModel().
    • Removed src/api/huggingface-models.ts as it's redundant.
  • Misc:
    • Added HuggingFace to RouterName type in api.ts.
    • Updated ExtensionMessage.ts and WebviewMessage.ts to reflect changes.
    • Updated HuggingFace.tsx to handle new model fetching logic.

This description was created by Ellipsis for 86e05ab. You can customize this summary. It will automatically update as commits are pushed.

roomote added 3 commits July 25, 2025 07:27
- Move huggingface-models.ts from src/services/ to src/api/providers/fetchers/huggingface.ts
- Update fetcher to return ModelInfo records instead of raw HuggingFace models
- Add HuggingFace to RouterName type and integrate with modelCache.ts
- Update HuggingFace provider to extend RouterProvider base class
- Remove unnecessary src/api/huggingface-models.ts wrapper
- Update webviewMessageHandler to use the new pattern with getModels()
- Maintain backward compatibility with webview by transforming ModelInfo to expected format
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 25, 2025 07:32
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 25, 2025
@cte
Copy link
Collaborator

cte commented Jul 25, 2025

@roomote-agent Can we get rid of the requestHuggingFaceModels message and just use requestRouterModels? That seems cleaner.

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@roomote
Copy link
Contributor Author

roomote bot commented Jul 25, 2025

Hi @cte! I see your suggestion about removing requestHuggingFaceModels and using requestRouterModels instead. That makes sense for consistency. Let me implement this change for you.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 25, 2025
… instead

- Removed requestHuggingFaceModels message type from WebviewMessage.ts
- Removed requestHuggingFaceModels handler from webviewMessageHandler.ts
- Removed huggingFaceModels from ExtensionMessage.ts
- Updated HuggingFace.tsx component to use requestRouterModels and extract HuggingFace models from the routerModels response

This simplifies the codebase by using a single unified message type for all router-based model providers.
setModels(message.huggingFaceModels || [])
case "routerModels":
// Extract HuggingFace models from routerModels
if (message.routerModels?.huggingface) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting the conversion logic (lines 75–108) into a separate helper for improved readability and maintainability.

This comment was generated because it violated a code review rule: irule_tTqpIuNs8DV0QFGj.

@roomote
Copy link
Contributor Author

roomote bot commented Jul 25, 2025

Done! I've successfully removed requestHuggingFaceModels and updated the code to use requestRouterModels instead.

Here's what I changed:

  • Removed requestHuggingFaceModels message type from WebviewMessage.ts
  • Removed the requestHuggingFaceModels handler from webviewMessageHandler.ts
  • Removed huggingFaceModels from ExtensionMessage.ts
  • Updated the HuggingFace.tsx component to use requestRouterModels and extract HuggingFace models from the routerModels response

This simplifies the codebase by using a single unified message type for all router-based model providers. All tests are passing and CI checks have completed successfully.

@daniel-lxs
Copy link
Member

Done by #6228

@daniel-lxs daniel-lxs closed this Jul 26, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 26, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 26, 2025
@cte cte deleted the feature/refactor-huggingface-provider branch July 31, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants