|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +cd $(dirname "$0")/../ |
| 5 | + |
| 6 | +CLIENT_PACKAGE_NAME=llama_cpp.client |
| 7 | +CLIENT_TMP_DIR=.tmp/llama-cpp-openapi-client |
| 8 | +CLIENT_FINAL_DIR=llama_cpp/client |
| 9 | + |
| 10 | +# Ensure we're starting from a clean slate |
| 11 | +rm -rf .tmp $CLIENT_TMP_DIR $CLIENT_FINAL_DIR |
| 12 | + |
| 13 | +# Pull the latest version of the API's OpenAPI spec |
| 14 | +./bin/save-openapi-json |
| 15 | +OPENAPI_JSON_PATH=.tmp/llama_server_openapi.json |
| 16 | + |
| 17 | +# Generate the client |
| 18 | + |
| 19 | +# Version tolerant: this is apparently their newer, more pythonic generator that is more tolerant to changes in the API |
| 20 | +VERSION_TOLERANT=true |
| 21 | + |
| 22 | +# Python3 only: we don't need to support python2 |
| 23 | +PYTHON3_ONLY=true |
| 24 | + |
| 25 | +# Low level client: I think this is yet another client generator (???) - turn it off for now |
| 26 | +LOW_LEVEL_CLIENT=false |
| 27 | + |
| 28 | +# Models: IMO the client it totally pointless without generating models (which is disabled by default) - so enable it |
| 29 | +# The only models that are supported are for msrest |
| 30 | +MODELS_MODE=msrest |
| 31 | + |
| 32 | +# Client-side validation: also something disabled by default - i'm going to turn this off for now because i think there might be some problems with return types in the API |
| 33 | +CLIENT_SIDE_VALIDATION=false |
| 34 | + |
| 35 | +# Setup.py: the client lives in llama_cpp/client, don't generate a setup.py or anything else to support a standalone package |
| 36 | +BASIC_SETUP_PY=false |
| 37 | + |
| 38 | +# RXun autorest |
| 39 | +docker run --rm \ |
| 40 | + -v $PWD:/local \ |
| 41 | + -w /local \ |
| 42 | + azsdkengsys.azurecr.io/azuresdk/autorest-python \ |
| 43 | + autorest \ |
| 44 | + --python \ |
| 45 | + --namespace=$CLIENT_PACKAGE_NAME \ |
| 46 | + --package-name=llama-cpp-api-client \ |
| 47 | + --package-version=0.0.1 \ |
| 48 | + --basic-setup-py=$BASIC_SETUP_PY \ |
| 49 | + --version-tolerant=$VERSION_TOLERANT \ |
| 50 | + --python3-only=$PYTHON3_ONLY \ |
| 51 | + --low-level-client=$LOW_LEVEL_CLIENT \ |
| 52 | + --models-mode=$MODELS_MODE \ |
| 53 | + --client-side-validation=$CLIENT_SIDE_VALIDATION \ |
| 54 | + --combine-operation-files=false \ |
| 55 | + --clear-output-folder=true \ |
| 56 | + --no-namespace-folders=true \ |
| 57 | + --input-file=/local/$OPENAPI_JSON_PATH \ |
| 58 | + --output-folder=/local/$CLIENT_TMP_DIR |
| 59 | + |
| 60 | +# Move the client to the final location |
| 61 | +cp -r $CLIENT_TMP_DIR $CLIENT_FINAL_DIR |
| 62 | + |
| 63 | +# Do some cleanup with black, isort and autoflake |
| 64 | +black $CLIENT_FINAL_DIR |
| 65 | +isort $CLIENT_FINAL_DIR |
| 66 | +autoflake -r --in-place --remove-all-unused-imports --remove-unused-variables $CLIENT_FINAL_DIR |
0 commit comments