Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
3d925165
Unverified
Commit
3d925165
authored
Apr 22, 2024
by
Harry Mellor
Committed by
GitHub
Apr 22, 2024
Browse files
Add example scripts to documentation (#4225)
Co-authored-by:
Harry Mellor
<
hmellor@oxts.com
>
parent
15436806
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
1 deletion
+80
-1
.gitignore
.gitignore
+2
-0
docs/source/conf.py
docs/source/conf.py
+8
-1
docs/source/generate_examples.py
docs/source/generate_examples.py
+61
-0
docs/source/getting_started/examples/examples_index.template.rst
...urce/getting_started/examples/examples_index.template.rst
+8
-0
docs/source/index.rst
docs/source/index.rst
+1
-0
examples/openai_chat_completion_client.py
examples/openai_chat_completion_client.py
+0
-0
No files found.
.gitignore
View file @
3d925165
...
@@ -70,6 +70,8 @@ instance/
...
@@ -70,6 +70,8 @@ instance/
# Sphinx documentation
# Sphinx documentation
docs/_build/
docs/_build/
docs/source/getting_started/examples/*.rst
!**/*.template.rst
# PyBuilder
# PyBuilder
.pybuilder/
.pybuilder/
...
...
docs/source/conf.py
View file @
3d925165
...
@@ -48,7 +48,7 @@ templates_path = ['_templates']
...
@@ -48,7 +48,7 @@ templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns
:
List
[
str
]
=
[]
exclude_patterns
:
List
[
str
]
=
[
"**/*.template.rst"
]
# Exclude the prompt "$" when copying code
# Exclude the prompt "$" when copying code
copybutton_prompt_text
=
r
"\$ "
copybutton_prompt_text
=
r
"\$ "
...
@@ -73,6 +73,13 @@ html_theme_options = {
...
@@ -73,6 +73,13 @@ html_theme_options = {
# so a file named "default.css" will overwrite the builtin "default.css".
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
# html_static_path = ['_static']
# Generate additional rst documentation here.
def
setup
(
app
):
from
docs.source.generate_examples
import
generate_examples
generate_examples
()
# Mock out external dependencies here.
# Mock out external dependencies here.
autodoc_mock_imports
=
[
autodoc_mock_imports
=
[
"cpuinfo"
,
"cpuinfo"
,
...
...
docs/source/generate_examples.py
0 → 100644
View file @
3d925165
import
re
from
pathlib
import
Path
def
fix_case
(
text
:
str
)
->
str
:
subs
=
[
(
"api"
,
"API"
),
(
"llm"
,
"LLM"
),
(
"vllm"
,
"vLLM"
),
(
"openai"
,
"OpenAI"
),
(
"multilora"
,
"MultiLoRA"
),
]
for
sub
in
subs
:
text
=
re
.
sub
(
*
sub
,
text
,
flags
=
re
.
IGNORECASE
)
return
text
def
underline
(
title
:
str
,
character
:
str
=
"="
)
->
str
:
return
f
"
{
title
}
\n
{
character
*
len
(
title
)
}
"
def
generate_title
(
filename
:
str
)
->
str
:
# Turn filename into a title
title
=
filename
.
replace
(
"_"
,
" "
).
title
()
# Handle acronyms and names
title
=
fix_case
(
title
)
# Underline title
title
=
underline
(
title
)
return
title
def
generate_examples
():
root_dir
=
Path
(
__file__
).
parent
.
parent
.
parent
.
resolve
()
# Source paths
script_dir
=
root_dir
/
"examples"
script_paths
=
sorted
(
script_dir
.
glob
(
"*.py"
))
# Destination paths
doc_dir
=
root_dir
/
"docs/source/getting_started/examples"
doc_paths
=
[
doc_dir
/
f
"
{
path
.
stem
}
.rst"
for
path
in
script_paths
]
# Generate the example docs for each example script
for
script_path
,
doc_path
in
zip
(
script_paths
,
doc_paths
):
script_url
=
f
"https://github.com/vllm-project/vllm/blob/main/examples/
{
script_path
.
name
}
"
# Make script_path relative to doc_path and call it include_path
include_path
=
'../../../..'
/
script_path
.
relative_to
(
root_dir
)
content
=
(
f
"
{
generate_title
(
doc_path
.
stem
)
}
\n\n
"
f
"Source
{
script_url
}
.
\n\n
"
f
".. literalinclude::
{
include_path
}
\n
"
" :language: python
\n
"
" :linenos:
\n
"
)
with
open
(
doc_path
,
"w+"
)
as
f
:
f
.
write
(
content
)
# Generate the toctree for the example scripts
with
open
(
doc_dir
/
"examples_index.template.rst"
)
as
f
:
examples_index
=
f
.
read
()
with
open
(
doc_dir
/
"examples_index.rst"
,
"w+"
)
as
f
:
example_docs
=
"
\n
"
.
join
(
path
.
stem
for
path
in
script_paths
)
f
.
write
(
examples_index
.
replace
(
r
"%EXAMPLE_DOCS%"
,
example_docs
))
docs/source/getting_started/examples/examples_index.template.rst
0 → 100644
View file @
3d925165
Examples
=================================
.. toctree::
:maxdepth: 1
:caption: Scripts
%EXAMPLE_DOCS%
docs/source/index.rst
View file @
3d925165
...
@@ -65,6 +65,7 @@ Documentation
...
@@ -65,6 +65,7 @@ Documentation
getting_started/neuron-installation
getting_started/neuron-installation
getting_started/cpu-installation
getting_started/cpu-installation
getting_started/quickstart
getting_started/quickstart
getting_started/examples/examples_index
.. toctree::
.. toctree::
:maxdepth: 1
:maxdepth: 1
...
...
examples/openai_chatcompletion_client.py
→
examples/openai_chat
_
completion_client.py
View file @
3d925165
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment