Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[DOCS] OV GenAI Python API for master (#27028)

tadamczx6581feeeb075
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
index 797c95ef7d9..dfb98af33c8 100644
--- a/docs/CMakeLists.txt
+++ b/docs/CMakeLists.txt
@@ -6,6 +6,7 @@ add_subdirectory(snippets)
set(ENABLE_CPP_API OFF CACHE BOOL "Build with C/C++ API.")
set(ENABLE_PYTHON_API OFF CACHE BOOL "Build with Python API.")
+set(ENABLE_GENAI_API OFF CACHE BOOL "Build with GenAI API.")
set(ENABLE_NOTEBOOKS OFF CACHE BOOL "Build with openvino notebooks.")
set(ENABLE_OMZ OFF CACHE BOOL "Build with open_model_zoo.")
set(ENABLE_OVMS OFF CACHE BOOL "Build with ovms.")
@@ -61,11 +62,12 @@ function(build_docs)
list(APPEND commands COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "FINISHED preprocessing OpenVINO C/C++ API reference")
endif()
- if(${ENABLE_PYTHON_API})
+ if(${ENABLE_PYTHON_API} OR ${ENABLE_GENAI_API})
list(APPEND commands COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "STARTED preprocessing OpenVINO Python API")
list(APPEND commands COMMAND ${Python3_EXECUTABLE} ${OV_INSTALLATION_SCRIPT}
--ov_dir=${SPHINX_SETUP_DIR}
- --python=${Python3_EXECUTABLE})
+ --python=${Python3_EXECUTABLE}
+ --enable_genai=${ENABLE_GENAI_API})
list(APPEND commands COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "FINISHED preprocessing OpenVINO Python API")
endif()
diff --git a/docs/scripts/install_appropriate_openvino_version.py b/docs/scripts/install_appropriate_openvino_version.py
index d9cbb6a9ddb..262fd13d771 100644
--- a/docs/scripts/install_appropriate_openvino_version.py
+++ b/docs/scripts/install_appropriate_openvino_version.py
@@ -2,64 +2,64 @@ import re
import argparse
import subprocess
import requests
-import pkg_resources
from packaging import version
from pathlib import Path
def determine_openvino_version(file_path):
pattern = r"version_name\s*=\s*['\"]([^'\"]+)['\"]"
-
with open(file_path, 'r') as file:
content = file.read()
-
match = re.search(pattern, content)
-
- if match:
- return match.group(1)
- else:
- return None
+ return match.group(1) if match else None
-def get_latest_version(major_version):
- url = f"https://pypi.org/pypi/openvino/json"
+def get_latest_version(package, major_version):
+ url = f"https://pypi.org/pypi/{package}/json"
response = requests.get(url)
-
if response.status_code == 200:
data = response.json()
versions = data['releases'].keys()
-
- # Filter versions by the major version prefix
matching_versions = [v for v in versions if v.startswith(major_version)]
-
- # Sort the matching versions and return the latest one
if matching_versions:
matching_versions.sort(key=version.parse)
return matching_versions[-1]
-
return None
+def install_package(python_executable, package):
+ subprocess.check_call([f'{python_executable}', '-m', 'pip', 'install', '-U', package, '--no-cache-dir'])
+
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--ov_dir', type=Path, help='OpenVINO docs directory')
parser.add_argument('--python', type=Path, help='Python executable')
+ parser.add_argument('--enable_genai', type=str, choices=['ON', 'OFF'], default='OFF', help='Enable GenAI API installation')
args = parser.parse_args()
- ov_dir = args.ov_dir
- python_executable = args.python
- version_name = determine_openvino_version(ov_dir.joinpath("conf.py"))
-
- if version_name is None:
- ov_version = "openvino"
- elif version_name == "nightly":
- ov_version = "openvino-nightly"
+
+ version_name = determine_openvino_version(args.ov_dir.joinpath("conf.py"))
+
+ if version_name == "nightly":
+ install_package(args.python, "openvino-nightly")
+ print("OpenVINO nightly version installed. OpenVINO GenAI nightly version is not available.")
+ elif version_name is None or version_name == "latest":
+ install_package(args.python, "openvino")
+ if args.enable_genai == 'ON':
+ install_package(args.python, "openvino-genai")
else:
- latest_version = get_latest_version(version_name)
- if latest_version:
- ov_version = f"openvino=={latest_version}"
+ ov_version = get_latest_version("openvino", version_name)
+ if ov_version:
+ install_package(args.python, f"openvino=={ov_version}")
else:
- ov_version = f"openvino=={version_name}"
- subprocess.check_call([f'{python_executable}', '-m', 'pip', 'install', '-U', ov_version, '--no-cache-dir'])
+ print(f"No matching OpenVINO version found for {version_name}")
+
+ if args.enable_genai == 'ON':
+ ov_genai_version = get_latest_version("openvino-genai", version_name)
+ if ov_genai_version:
+ install_package(args.python, f"openvino-genai=={ov_genai_version}")
+ else:
+ print(f"No matching OpenVINO GenAI version found for {version_name}")
if __name__ == "__main__":
diff --git a/docs/scripts/tests/suppress_warnings.txt b/docs/scripts/tests/suppress_warnings.txt
index b9942f28dc0..993a290c6d7 100644
--- a/docs/scripts/tests/suppress_warnings.txt
+++ b/docs/scripts/tests/suppress_warnings.txt
@@ -61,3 +61,4 @@ toctree contains reference to nonexisting document
pygments lexer name
non-consecutive header level increase
document headings start at
+inline strong start-string without end-string
diff --git a/docs/sphinx_setup/api/api_reference.rst b/docs/sphinx_setup/api/api_reference.rst
index acf816364ca..9f60573707f 100644
--- a/docs/sphinx_setup/api/api_reference.rst
+++ b/docs/sphinx_setup/api/api_reference.rst
@@ -15,6 +15,7 @@ API Reference
OpenVINO Runtime C++ API <c_cpp_api/group__ov__cpp__api>
OpenVINO Runtime C API <c_cpp_api/group__ov__c__api>
OpenVINO Node.js API <nodejs_api/nodejs_api>
+ GenAI Python API <genai_api/api>
diff --git a/docs/sphinx_setup/api/genai_api/api.rst b/docs/sphinx_setup/api/genai_api/api.rst
new file mode 100644
index 00000000000..fc5151d7781
--- /dev/null
+++ b/docs/sphinx_setup/api/genai_api/api.rst
@@ -0,0 +1,12 @@
+OpenVINO GenAI API
+===================
+
+.. meta::
+ :description: Explore OpenVINO GenAI Python API and implementation of its features in Intel® Distribution of OpenVINO™ GenAI.
+
+
+.. autosummary::
+ :toctree: _autosummary
+ :template: custom-module-template.rst
+
+ openvino_genai
\ No newline at end of file
diff --git a/docs/sphinx_setup/conf.py b/docs/sphinx_setup/conf.py
index 351a6d6c5ea..148309ccbaf 100644
--- a/docs/sphinx_setup/conf.py
+++ b/docs/sphinx_setup/conf.py
@@ -34,11 +34,21 @@ extensions = [
'breathe'
]
+autodoc_mock_imports = []
+
try:
import openvino
except ImportError:
- autodoc_mock_imports = ["openvino"]
+ autodoc_mock_imports.append("openvino")
+ autodoc_mock_imports.append("openvino_genai") # Mock openvino_genai too, as it depends on openvino
+
+if "openvino" not in autodoc_mock_imports:
+ try:
+ import openvino_genai
+ except ImportError:
+ autodoc_mock_imports.append("openvino_genai")
+
breathe_projects = {
"openvino": "../xml/"
}