1
0

args.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. """
  2. This file contains the command line arguments for the Aphrodite's
  3. OpenAI-compatible server. It is kept in a separate file for documentation
  4. purposes.
  5. """
  6. import argparse
  7. import json
  8. import ssl
  9. from aphrodite.common.utils import FlexibleArgumentParser
  10. from aphrodite.endpoints.openai.serving_engine import (LoRAModulePath,
  11. PromptAdapterPath)
  12. from aphrodite.engine.args_tools import AsyncEngineArgs
  13. class LoRAParserAction(argparse.Action):
  14. def __call__(self, parser, namespace, values, option_string=None):
  15. lora_list = []
  16. for item in values:
  17. name, path = item.split('=')
  18. lora_list.append(LoRAModulePath(name, path))
  19. setattr(namespace, self.dest, lora_list)
  20. class PromptAdapterParserAction(argparse.Action):
  21. def __call__(self, parser, namespace, values, option_string=None):
  22. adapter_list = []
  23. for item in values:
  24. name, path = item.split('=')
  25. adapter_list.append(PromptAdapterPath(name, path))
  26. setattr(namespace, self.dest, adapter_list)
  27. def make_arg_parser(parser: FlexibleArgumentParser) -> FlexibleArgumentParser:
  28. parser.add_argument("--host", type=str, default=None, help="host name")
  29. parser.add_argument("--port", type=int, default=2242, help="port number")
  30. parser.add_argument(
  31. "--uvicorn-log-level",
  32. type=str,
  33. default="info",
  34. choices=['debug', 'info', 'warning', 'error', 'critical', 'trace'],
  35. help="log level for uvicorn")
  36. parser.add_argument("--allow-credentials",
  37. action="store_true",
  38. help="allow credentials")
  39. parser.add_argument("--allowed-origins",
  40. type=json.loads,
  41. default=["*"],
  42. help="allowed origins")
  43. parser.add_argument("--allowed-methods",
  44. type=json.loads,
  45. default=["*"],
  46. help="allowed methods")
  47. parser.add_argument("--allowed-headers",
  48. type=json.loads,
  49. default=["*"],
  50. help="allowed headers")
  51. parser.add_argument("--api-keys",
  52. type=str,
  53. default=None,
  54. help="If provided, the server will require this key "
  55. "to be presented in the header.")
  56. parser.add_argument("--admin-key",
  57. type=str,
  58. default=None,
  59. help="If provided, the server will require this key "
  60. "to be presented in the header for admin operations.")
  61. parser.add_argument(
  62. "--lora-modules",
  63. type=str,
  64. default=None,
  65. nargs='+',
  66. action=LoRAParserAction,
  67. help="LoRA module configurations in the format name=path. "
  68. "Multiple modules can be specified.")
  69. parser.add_argument(
  70. "--prompt-adapters",
  71. type=str,
  72. default=None,
  73. nargs='+',
  74. action=PromptAdapterParserAction,
  75. help="Prompt adapter configurations in the format name=path. "
  76. "Multiple adapters can be specified.")
  77. parser.add_argument("--chat-template",
  78. type=str,
  79. default=None,
  80. help="The file path to the chat template, "
  81. "or the template in single-line form "
  82. "for the specified model")
  83. parser.add_argument("--response-role",
  84. type=str,
  85. default="assistant",
  86. help="The role name to return if "
  87. "`request.add_generation_prompt=true`.")
  88. parser.add_argument("--ssl-keyfile",
  89. type=str,
  90. default=None,
  91. help="The file path to the SSL key file")
  92. parser.add_argument("--ssl-certfile",
  93. type=str,
  94. default=None,
  95. help="The file path to the SSL cert file")
  96. parser.add_argument("--ssl-ca-certs",
  97. type=str,
  98. default=None,
  99. help="The CA certificates file")
  100. parser.add_argument(
  101. "--ssl-cert-reqs",
  102. type=int,
  103. default=int(ssl.CERT_NONE),
  104. help="Whether client certificate is required (see stdlib ssl module's)"
  105. )
  106. parser.add_argument(
  107. "--root-path",
  108. type=str,
  109. default=None,
  110. help="FastAPI root_path when app is behind a path based routing proxy")
  111. parser.add_argument(
  112. "--middleware",
  113. type=str,
  114. action="append",
  115. default=[],
  116. help="Additional ASGI middleware to apply to the app. "
  117. "We accept multiple --middleware arguments. "
  118. "The value should be an import path. "
  119. "If a function is provided, Aphrodite will add it to the server "
  120. "using @app.middleware('http'). "
  121. "If a class is provided, Aphrodite will add it to the server "
  122. "using app.add_middleware(). ")
  123. parser.add_argument(
  124. "--launch-kobold-api",
  125. action="store_true",
  126. help="Launch the Kobold API server alongside the OpenAI server")
  127. parser.add_argument("--max-log-len",
  128. type=int,
  129. default=0,
  130. help="Max number of prompt characters or prompt "
  131. "ID numbers being printed in log."
  132. "\n\nDefault: 0")
  133. parser.add_argument(
  134. "--return-tokens-as-token-ids",
  135. action="store_true",
  136. help="When --max-logprobs is specified, represents single tokens as"
  137. "strings of the form 'token_id:{token_id}' so that tokens that"
  138. "are not JSON-encodable can be identified.")
  139. parser.add_argument(
  140. "--disable-frontend-multiprocessing",
  141. action="store_true",
  142. help="If specified, will run the OpenAI frontend server in the same "
  143. "process as the model serving engine.")
  144. parser = AsyncEngineArgs.add_cli_args(parser)
  145. return parser
  146. def create_parser_for_docs() -> FlexibleArgumentParser:
  147. parser_for_docs = FlexibleArgumentParser(
  148. prog="-m aphrodite.endpoints.openai.api_server")
  149. return make_arg_parser(parser_for_docs)