feat: Add OpenAI-compatible embedding API support#39
Open
CZH-THU wants to merge 1 commit into
Open
Conversation
- Implement EmbeddingAPIClient for OpenAI-compatible APIs (Jina, Azure OpenAI, Ollama, etc.) - Add embedding API configuration to SkillClawConfig - Extend SkillManager to support both local and API-based embeddings - Update launcher to pass embedding API configuration - Add comprehensive test suite for embedding API client - Add demo script for embedding API usage - Update dependencies: add requests, responses for testing
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.
Add OpenAI-Compatible Embedding API Support
Overview
This PR introduces support for OpenAI-compatible embedding APIs to SkillClaw, enabling users to leverage external embedding services (Jina, Azure OpenAI, Ollama, LocalAI, etc.) alongside the existing local embedding model support.
Motivation
The current SkillClaw implementation only supports local embedding models (SentenceTransformer). This PR adds flexibility by:
Changes
New Files
skillclaw/embedding_api_client.py- Complete OpenAI-compatible embedding API clienttests/test_embedding_api.py- Comprehensive test suite (9 tests + 1 integration test)scripts/demo_embedding_api.py- Usage demo and examplesModified Files
skillclaw/config.py- Added embedding API configuration fieldsembedding_type: "local" or "api"embedding_api_url: API endpoint URLembedding_api_model: Model nameembedding_api_key: Optional API keyskillclaw/skill_manager.py- Extended to support both embedding modesskillclaw/launcher.py- Passes embedding API configuration to SkillManagerpyproject.toml- Updated dependenciesrequestsfor API callsresponsesfor testingrequirements.txt- Updated with new dependenciesFeatures
1. Flexible Configuration
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_encode_basic PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_encode_with_normalization PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_encode_empty_input PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_encode_with_authorization PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_encode_without_api_key PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_encode_out_of_order_responses PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_api_error_handling PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_invalid_response_format PASSED
tests/test_embedding_api.py::TestEmbeddingAPIClient::test_large_batch PASSED
Usage Example
Basic Usage with Jina API
Configuration File
Benefits
API Compatibility Notes
The implementation follows the OpenAI embedding API specification:
{"model": "...", "input": [...]}{"data": [{"embedding": [...], "index": 0}, ...]}Breaking Changes
None - fully backward compatible with existing code.
Related Issues
Addresses the need for flexible embedding model support.
Checklist