diff --git a/python/flink_agents/integrations/chat_models/tests/start_ollama_server.sh b/python/flink_agents/integrations/chat_models/tests/start_ollama_server.sh deleted file mode 100644 index bf7a50a0a..000000000 --- a/python/flink_agents/integrations/chat_models/tests/start_ollama_server.sh +++ /dev/null @@ -1,40 +0,0 @@ -################################################################################ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -################################################################################# - -# only works on linux -os=$(uname -s) -echo $os -if [[ $os == "Linux" ]]; then - curl -fsSL https://ollama.com/install.sh | sh - ret=$? - if [ "$ret" != "0" ] - then - exit $ret - fi - - if curl -f http://localhost:11434/api/tags >/dev/null 2>&1; then - echo "Ollama is already running" - else - echo "Starting Ollama server" - ollama serve & - sleep 10 # wait for ollama to start - fi - - echo "ollama pull $1" - ollama pull $1 -fi \ No newline at end of file diff --git a/python/flink_agents/integrations/chat_models/tests/test_ollama_chat_model.py b/python/flink_agents/integrations/chat_models/tests/test_ollama_chat_model.py index 27f07f340..1f3fd2614 100644 --- a/python/flink_agents/integrations/chat_models/tests/test_ollama_chat_model.py +++ b/python/flink_agents/integrations/chat_models/tests/test_ollama_chat_model.py @@ -16,17 +16,14 @@ # limitations under the License. ################################################################################# import os -import subprocess -import sys -from pathlib import Path from unittest.mock import MagicMock import pytest -from ollama import Client from flink_agents.api.chat_message import ChatMessage, MessageRole from flink_agents.api.resource import Resource, ResourceType from flink_agents.api.resource_context import ResourceContext +from flink_agents.e2e_tests.test_utils import pull_model from flink_agents.integrations.chat_models.ollama_chat_model import ( OllamaChatModelConnection, OllamaChatModelSetup, @@ -37,29 +34,8 @@ pytestmark = pytest.mark.integration test_model = os.environ.get("OLLAMA_CHAT_MODEL", "qwen3:1.7b") -current_dir = Path(__file__).parent - -try: - # only auto setup ollama in ci with python 3.10 to reduce ci cost. - if "3.10" in sys.version: - subprocess.run( - ["bash", f"{current_dir}/start_ollama_server.sh", test_model], - timeout=300, - check=True, - ) - client = Client() - models = client.list() - - model_found = False - for model in models["models"]: - if model.model == test_model: - model_found = True - break - - if not model_found: - client = None # type: ignore -except Exception: - client = None # type: ignore + +client = pull_model(test_model) @pytest.mark.skipif( diff --git a/python/flink_agents/integrations/embedding_models/local/tests/start_ollama_server.sh b/python/flink_agents/integrations/embedding_models/local/tests/start_ollama_server.sh deleted file mode 100755 index 92da52d79..000000000 --- a/python/flink_agents/integrations/embedding_models/local/tests/start_ollama_server.sh +++ /dev/null @@ -1,39 +0,0 @@ -################################################################################ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -################################################################################ - -# only works on linux -os=$(uname -s) -echo $os -if [[ $os == "Linux" ]]; then - curl -fsSL https://ollama.com/install.sh | sh - ret=$? - if [ "$ret" != "0" ] - then - exit $ret - fi - - if curl -f http://localhost:11434/api/tags >/dev/null 2>&1; then - echo "Ollama is already running" - else - echo "Starting Ollama server" - ollama serve & - sleep 10 # wait for ollama to start - fi - - ollama pull all-minilm:22m -fi \ No newline at end of file diff --git a/python/flink_agents/integrations/embedding_models/local/tests/test_ollama_embedding_model.py b/python/flink_agents/integrations/embedding_models/local/tests/test_ollama_embedding_model.py index dd71c14ca..bcf77f18f 100644 --- a/python/flink_agents/integrations/embedding_models/local/tests/test_ollama_embedding_model.py +++ b/python/flink_agents/integrations/embedding_models/local/tests/test_ollama_embedding_model.py @@ -16,16 +16,13 @@ # limitations under the License. ################################################################################ import os -import subprocess -import sys -from pathlib import Path from unittest.mock import MagicMock import pytest -from ollama import Client from flink_agents.api.resource import Resource, ResourceType from flink_agents.api.resource_context import ResourceContext +from flink_agents.e2e_tests.test_utils import pull_model from flink_agents.integrations.embedding_models.local.ollama_embedding_model import ( OllamaEmbeddingModelConnection, OllamaEmbeddingModelSetup, @@ -34,27 +31,8 @@ pytestmark = pytest.mark.integration test_model = os.environ.get("OLLAMA_EMBEDDING_MODEL", "all-minilm:22m") -current_dir = Path(__file__).parent -try: - # only auto setup ollama in ci with python 3.10 to reduce ci cost. - if "3.10" in sys.version: - subprocess.run( - ["bash", f"{current_dir}/start_ollama_server.sh"], timeout=300, check=True - ) - client = Client() - models = client.list() - - model_found = False - for model in models["models"]: - if model.model == test_model: - model_found = True - break - - if not model_found: - client = None # type: ignore -except Exception: - client = None # type: ignore +client = pull_model(test_model) @pytest.mark.skipif(