-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(llm): autopull ollama models (#2019)
* chore: update ollama (llm) * feat: allow to autopull ollama models * fix: mypy * chore: install always ollama client * refactor: check connection and pull ollama method to utils * docs: update ollama config with autopulling info
- Loading branch information
Showing
8 changed files
with
129 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,32 @@ | ||
import logging | ||
|
||
try: | ||
from ollama import Client # type: ignore | ||
except ImportError as e: | ||
raise ImportError( | ||
"Ollama dependencies not found, install with `poetry install --extras llms-ollama or embeddings-ollama`" | ||
) from e | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def check_connection(client: Client) -> bool: | ||
try: | ||
client.list() | ||
return True | ||
except Exception as e: | ||
logger.error(f"Failed to connect to Ollama: {e!s}") | ||
return False | ||
|
||
|
||
def pull_model(client: Client, model_name: str, raise_error: bool = True) -> None: | ||
try: | ||
installed_models = [model["name"] for model in client.list().get("models", {})] | ||
if model_name not in installed_models: | ||
logger.info(f"Pulling model {model_name}. Please wait...") | ||
client.pull(model_name) | ||
logger.info(f"Model {model_name} pulled successfully") | ||
except Exception as e: | ||
logger.error(f"Failed to pull model {model_name}: {e!s}") | ||
if raise_error: | ||
raise e |
This file contains 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 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