Skip to content

Commit

Permalink
Http API Referene Docs (#945)
Browse files Browse the repository at this point in the history
* remove old openapi.json spec

* add autogenerated file to gitignore

* script to generate openai.json spec

* add HTTP API sub section in reference section
  • Loading branch information
hansent authored Jan 14, 2025
1 parent 5ebf63a commit 95a7604
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ jobs:
run: python -m development.docs.write_cli_docs
working-directory: ./inference_repo

- name: Write OpenAPI spec
run: python -m development.docs.write_openapi_spec
working-directory: ./inference_repo


- name: Deploy docs
# Only deploy if release event OR if deploy input was set to true
if: ${{ github.event_name == 'release' || github.event.inputs.deploy == 'true' }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ docs/workflows/blocks/*
docs/workflows/kinds/*
docs/workflows/gallery/*
docs/inference_helpers/cli_commands/reference.md
docs/openapi.json
!tests/workflows/integration_tests/execution/assets/*.jpg
!tests/workflows/integration_tests/execution/assets/rock_paper_scissors/*.jpg
!tests/workflows/unit_tests/core_steps/models/third_party/assets/*.png
Expand Down
61 changes: 61 additions & 0 deletions development/docs/write_openapi_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@



from functools import partial
from multiprocessing import Process

from inference.core.cache import cache
from inference.core.interfaces.http.http_api import HttpInterface
from inference.core.interfaces.stream_manager.manager_app.app import start
from inference.core.managers.active_learning import (
ActiveLearningManager,
BackgroundTaskActiveLearningManager,
)
from inference.core.managers.base import ModelManager
from inference.core.managers.decorators.fixed_size_cache import WithFixedSizeCache
from inference.core.registries.roboflow import (
RoboflowModelRegistry,
)


from inference.models.utils import ROBOFLOW_MODEL_TYPES



model_registry = RoboflowModelRegistry(ROBOFLOW_MODEL_TYPES)


model_manager = ModelManager(model_registry=model_registry)

model_manager = WithFixedSizeCache(model_manager, max_size=1)
model_manager.init_pingback()
interface = HttpInterface(model_manager)
app = interface.app




from fastapi.openapi.utils import get_openapi
import json
import os

DOCS_ROOT_DIR = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"docs",
)
)

filename = os.path.join(DOCS_ROOT_DIR, "openapi.json")

with open(filename, 'w') as f:
json.dump(get_openapi(
title=app.title,
version=app.version,
openapi_version=app.openapi_version,
description=app.description,
routes=app.routes,

), f)
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The Roboflow Inference Server provides OpenAPI documentation at the `/docs` endpoint for use in development.
When the Inference Server is running, it provides OpenAPI documentation at the `/docs` endpoint for use in development.

Below is the OpenAPI specification for the Inference Server, rendered with Swagger.
Below is the OpenAPI specification for the Inference Server for the current release version.

<swagger-ui src="./openapi.json"/>
1 change: 0 additions & 1 deletion docs/openapi.json

This file was deleted.

2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ nav:
- Make Predictions: inference_helpers/cli_commands/infer.md
- Deploy To Cloud: inference_helpers/cli_commands/cloud.md
- Reference: inference_helpers/cli_commands/reference.md
- HTTP API:
- OpenAPI Spec: api.md
- inference Python Package: reference/inference/
- Active Learning:
- Use Active Learning: enterprise/active-learning/active_learning.md
Expand Down

0 comments on commit 95a7604

Please sign in to comment.