args.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. """
  2. This file contains the command line arguments for 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. from aphrodite.engine.args_tools import AsyncEngineArgs
  9. from aphrodite.endpoints.openai.serving_engine import LoRA
  10. class LoRAParserAction(argparse.Action):
  11. def __call__(self, parser, namespace, values, option_string=None):
  12. lora_list = []
  13. for item in values:
  14. name, path = item.split('=')
  15. lora_list.append(LoRA(name, path))
  16. setattr(namespace, self.dest, lora_list)
  17. def make_arg_parser(parser=None):
  18. if parser is None:
  19. parser = argparse.ArgumentParser(
  20. description="Aphrodite OpenAI-Compatible RESTful API server.")
  21. parser.add_argument("--host", type=str, default=None, help="host name")
  22. parser.add_argument("--port", type=int, default=2242, help="port number")
  23. parser.add_argument("--allow-credentials",
  24. action="store_true",
  25. help="allow credentials")
  26. parser.add_argument("--allowed-origins",
  27. type=json.loads,
  28. default=["*"],
  29. help="allowed origins")
  30. parser.add_argument("--allowed-methods",
  31. type=json.loads,
  32. default=["*"],
  33. help="allowed methods")
  34. parser.add_argument("--allowed-headers",
  35. type=json.loads,
  36. default=["*"],
  37. help="allowed headers")
  38. parser.add_argument(
  39. "--api-keys",
  40. type=str,
  41. default=None,
  42. help=
  43. "If provided, the server will require this key to be presented in the "
  44. "header.")
  45. parser.add_argument(
  46. "--admin-key",
  47. type=str,
  48. default=None,
  49. help=
  50. "If provided, the server will require this key to be presented in the "
  51. "header for admin operations.")
  52. parser.add_argument(
  53. "--launch-kobold-api",
  54. action="store_true",
  55. help=
  56. "Launch the Kobold API server in addition to the OpenAI API server.")
  57. parser.add_argument("--max-length",
  58. type=int,
  59. default=256,
  60. help="The maximum length of the generated response. "
  61. "For use with Kobold Horde.")
  62. parser.add_argument("--served-model-name",
  63. type=str,
  64. default=None,
  65. help="The model name used in the API. If not "
  66. "specified, the model name will be the same as "
  67. "the huggingface name.")
  68. parser.add_argument(
  69. "--lora-modules",
  70. type=str,
  71. default=None,
  72. nargs='+',
  73. action=LoRAParserAction,
  74. help=
  75. "LoRA module configurations in the format name=path. Multiple modules "
  76. "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(
  97. "--root-path",
  98. type=str,
  99. default=None,
  100. help="FastAPI root_path when app is behind a path based routing proxy")
  101. parser.add_argument(
  102. "--middleware",
  103. type=str,
  104. action="append",
  105. default=[],
  106. help="Additional ASGI middleware to apply to the app. "
  107. "We accept multiple --middleware arguments. "
  108. "The value should be an import path. "
  109. "If a function is provided, Aphrodite will add it to the server using "
  110. "@app.middleware('http'). "
  111. "If a class is provided, Aphrodite will add it to the server using "
  112. "app.add_middleware(). ")
  113. parser = AsyncEngineArgs.add_cli_args(parser)
  114. return parser