-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: update deprecated NVIDIA retrieval models #9750
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
Open
C10H14N2O5
wants to merge
1
commit into
AstrBotDevs:master
Choose a base branch
from
C10H14N2O5:fix/9729-nvidia-models
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from astrbot.core.config.default import CONFIG_METADATA_2 | ||
| from astrbot.core.provider.sources.nvidia_embedding_source import ( | ||
| NvidiaEmbeddingProvider, | ||
| ) | ||
|
|
||
| NEW_MODEL = "nvidia/nemotron-3-embed-1b" | ||
| OLD_MODEL = "nvidia/llama-nemotron-embed-1b-v2" | ||
|
|
||
|
|
||
| def test_nvidia_embedding_config_template_uses_new_model_and_dimension(): | ||
| templates = CONFIG_METADATA_2["provider_group"]["metadata"]["provider"][ | ||
| "config_template" | ||
| ] | ||
|
|
||
| assert templates["NVIDIA Embedding"]["embedding_model"] == NEW_MODEL | ||
| assert templates["NVIDIA Embedding"]["embedding_dimensions"] == 2048 | ||
|
|
||
|
|
||
| def test_nvidia_embedding_provider_uses_new_fallback_model(): | ||
| provider = NvidiaEmbeddingProvider({}, {}) | ||
|
|
||
| assert provider.model == NEW_MODEL | ||
| assert provider.get_model() == NEW_MODEL | ||
|
|
||
|
|
||
| def test_nvidia_embedding_provider_preserves_explicit_old_model(): | ||
| provider = NvidiaEmbeddingProvider( | ||
| { | ||
| "embedding_model": OLD_MODEL, | ||
| "embedding_dimensions": 1024, | ||
| }, | ||
| {}, | ||
| ) | ||
|
|
||
| assert provider.model == OLD_MODEL | ||
| assert provider.get_dim() == 1024 | ||
|
|
||
|
|
||
| def test_nvidia_embedding_new_model_uses_existing_api_contract(): | ||
| provider = NvidiaEmbeddingProvider( | ||
| { | ||
| "embedding_model": NEW_MODEL, | ||
| "input_type": "passage", | ||
| }, | ||
| {}, | ||
| ) | ||
|
|
||
| assert provider._build_payload(["first", "second"]) == { | ||
| "input": ["first", "second"], | ||
| "model": NEW_MODEL, | ||
| "input_type": "passage", | ||
| "encoding_format": "float", | ||
| } | ||
| assert provider._parse_response( | ||
| { | ||
| "data": [ | ||
| {"index": 0, "embedding": [0.1, 0.2]}, | ||
| {"index": 1, "embedding": [0.3, 0.4]}, | ||
| ] | ||
| } | ||
| ) == [[0.1, 0.2], [0.3, 0.4]] | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from astrbot.core.config.default import CONFIG_METADATA_2 | ||
| from astrbot.core.provider.sources.nvidia_rerank_source import NvidiaRerankProvider | ||
|
|
||
| NEW_MODEL = "nvidia/llama-nemotron-rerank-vl-1b-v2" | ||
| OLD_MODEL = "nv-rerank-qa-mistral-4b:1" | ||
|
|
||
|
|
||
| def test_nvidia_rerank_config_template_uses_new_model(): | ||
| templates = CONFIG_METADATA_2["provider_group"]["metadata"]["provider"][ | ||
| "config_template" | ||
| ] | ||
|
|
||
| assert templates["NVIDIA Rerank"]["nvidia_rerank_model"] == NEW_MODEL | ||
|
|
||
|
|
||
| def test_nvidia_rerank_provider_uses_new_fallback_model(): | ||
| provider = NvidiaRerankProvider({}, {}) | ||
|
|
||
| assert provider.model == NEW_MODEL | ||
| assert provider.get_model() == NEW_MODEL | ||
|
|
||
|
|
||
| def test_nvidia_rerank_provider_preserves_explicit_old_model(): | ||
| provider = NvidiaRerankProvider({"nvidia_rerank_model": OLD_MODEL}, {}) | ||
|
|
||
| assert provider.model == OLD_MODEL | ||
| assert provider._get_endpoint() == ( | ||
| "https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking" | ||
| ) | ||
|
|
||
|
|
||
| def test_nvidia_rerank_new_model_uses_existing_api_contract(): | ||
| provider = NvidiaRerankProvider( | ||
| { | ||
| "nvidia_rerank_model": NEW_MODEL, | ||
| "nvidia_rerank_truncate": "END", | ||
| }, | ||
| {}, | ||
| ) | ||
|
|
||
| assert provider._get_endpoint() == ( | ||
| "https://ai.api.nvidia.com/v1/retrieval/nvidia/" | ||
| "llama-nemotron-rerank-vl-1b-v2/reranking" | ||
| ) | ||
| assert provider._build_payload("query", ["first", "second"]) == { | ||
| "model": NEW_MODEL, | ||
| "query": {"text": "query"}, | ||
| "passages": [{"text": "first"}, {"text": "second"}], | ||
| "truncate": "END", | ||
| } | ||
|
|
||
|
|
||
| def test_nvidia_rerank_parses_official_rankings_response(): | ||
| provider = NvidiaRerankProvider({}, {}) | ||
|
|
||
| results = provider._parse_results( | ||
| { | ||
| "rankings": [ | ||
| {"index": 1, "logit": -0.25}, | ||
| {"index": 0, "logit": 0.75}, | ||
| ] | ||
| }, | ||
| top_n=None, | ||
| ) | ||
|
|
||
| assert [(result.index, result.relevance_score) for result in results] == [ | ||
| (0, 0.75), | ||
| (1, -0.25), | ||
| ] |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.