Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve update_docs for openapi schema #2169

Merged
merged 13 commits into from
Jul 3, 2024

Conversation

drbh
Copy link
Collaborator

@drbh drbh commented Jul 2, 2024

This PR aims to help sync the openapi schema via a combination of pre-commit hooks and a new cli arg to dump the spec file

This PR now updates update_doc.py to have two commands allowing callers to update the launcher docs and or the openapi spec

python update_doc.py -h
usage: update_doc.py [-h] {openapi,md} ...

Update documentation for text-generation-launcher

positional arguments:
  {openapi,md}
    openapi     Update OpenAPI documentation
    md          Update launcher and supported models

options:
  -h, --help    show this help message and exit

@drbh drbh changed the title feat: add pre commit step to force schema update when router changes feat: improve update_docs for openapi schema Jul 2, 2024
Comment on lines 23 to 28
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Clean unused files
run: |
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is that coming from ?Feels very random I don't think it' anywhere in our current CI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea it is strange but was in tests.yml here

- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Clean unused files
run: |
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET

In general I'd love to avoid rebuilding the server in this workflow, but it may be needed for this check

@@ -192,7 +190,6 @@
"Text Generation Inference"
],
"summary": "Generate a stream of token using Server-Sent Events",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the descriptions gone ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is related to an upstream change where utopia added support for a custom description instead of using the same value for both description and summary (related PRs juhaku/utoipa#781 and juhaku/utoipa#948).

"example": "user"
"oneOf": [
{
"$ref": "#/components/schemas/TextMessage"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels the cleaner types also help here, no ?

update_doc.py Outdated


if __name__ == "__main__":
main()
parser = argparse.ArgumentParser(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the simpler version that just checks everything by default ?
instead just add check_openapi function ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that makes sense, updated in the latest commits

update_doc.py Outdated

args = parser.parse_args()
process = subprocess.Popen(
["text-generation-launcher"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use an extremely small model ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to simplify we could add a flag in router in order to print the openapi directly ?
Would remove the necessity to compile things (except the router).

I know I said internally I didn't like that option, but I also said after that you were right since I didn't have a better idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated and added a text-generation-router print-schema command that prints the api docs as JSON and exits, if no command is passed it goes through the normal flow

update_doc.py Outdated
json.dump(new_data, f, indent=2)


def compare_openapi(old_data, new_data):
Copy link
Collaborator

@Narsil Narsil Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I wouldn't even ever parse the files and simply reuse some simple diffing.

diff = subprocess.run(
                    ["diff", tmp, filename], capture_output=True
                ).stdout.decode("utf-8")
print(diff)

Not strong opinion, your code seems to provide cleaner output, but given the unreadableness of the original JSON file, I'm not sure it's worth potentially making mistakes in that diff algorithm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good points! I think diff is a better long term solution and the pr has been updated to use diff

@drbh drbh marked this pull request as ready for review July 2, 2024 20:41
@drbh drbh mentioned this pull request Jul 2, 2024
@Narsil Narsil merged commit 571530d into main Jul 3, 2024
8 of 9 checks passed
@Narsil Narsil deleted the add-pre-commit-for-openapi-schema branch July 3, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants