Skip to content

Commit

Permalink
[DOCS] OV GenAI Python API for master (openvinotoolkit#27028)
Browse files Browse the repository at this point in the history
### Details:
 - *item1*
 - *...*

### Tickets:
 - *ticket-id*
  • Loading branch information
tadamczx authored Oct 14, 2024
1 parent 9c432a3 commit 6581fee
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 32 deletions.
6 changes: 4 additions & 2 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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()

Expand Down
58 changes: 29 additions & 29 deletions docs/scripts/install_appropriate_openvino_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@
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__":
Expand Down
1 change: 1 addition & 0 deletions docs/scripts/tests/suppress_warnings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docs/sphinx_setup/api/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>



Expand Down
12 changes: 12 additions & 0 deletions docs/sphinx_setup/api/genai_api/api.rst
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion docs/sphinx_setup/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@
'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/"
}
Expand Down

0 comments on commit 6581fee

Please sign in to comment.