Repository navigation
LCORE-4711: Added model resolution logic #3037
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
Merged
Merged
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,60 @@ | ||
| """Soft-fallback helpers for request-path model resolution.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from configuration import configuration | ||
| from log import get_logger | ||
| from providers.inference.types import ProviderId | ||
| from utils.endpoints import retrieve_conversation | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def conversation_last_used( | ||
| conversation_id: Optional[str], | ||
| ) -> Optional[tuple[ProviderId, str]]: | ||
| """Load last-used provider/model ids from a conversation when present. | ||
|
|
||
| Args: | ||
| conversation_id: Conversation id to look up, or None to skip. | ||
|
|
||
| Returns: | ||
| ``(provider_id, model_id)`` from the conversation, or None when the | ||
| conversation id is omitted or not found. | ||
|
|
||
| """ | ||
| if conversation_id is None: | ||
| return None | ||
|
|
||
| conversation = retrieve_conversation(conversation_id) | ||
|
asimurka marked this conversation as resolved.
Resolved
asimurka marked this conversation as resolved.
Resolved
|
||
| if conversation is None: | ||
| logger.warning( | ||
| "Conversation %r not found while resolving llm; soft-skipping " | ||
| "last-used fallback", | ||
| conversation_id, | ||
| ) | ||
| return None | ||
|
|
||
| return conversation.last_used_provider, conversation.last_used_model | ||
|
|
||
|
|
||
| def configured_defaults() -> Optional[tuple[ProviderId, str]]: | ||
| """Return configured default provider/model ids when both are set. | ||
|
|
||
| Returns: | ||
| ``(provider_id, model_id)`` from inference configuration, or None | ||
| when either default is unset. | ||
|
|
||
| """ | ||
| inference = configuration.inference | ||
| provider_id = inference.default_provider | ||
| model_id = inference.default_model | ||
| if not provider_id or not model_id: | ||
| logger.warning( | ||
| "Inference default provider/model unset; soft-skipping configured " | ||
| "default fallback" | ||
| ) | ||
| return None | ||
| return provider_id, model_id | ||
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
Oops, something went wrong.
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.