args.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. nargs="+",
  64. type=str,
  65. default=None,
  66. help="The model name(s) used in the API. If multiple "
  67. "names are provided, the server will respond to any "
  68. "of the provided names. The model name in the model "
  69. "field of a response will be the first name in this "
  70. "list. If not specified, the model name will be the "
  71. "same as the `--model` argument.")
  72. parser.add_argument(
  73. "--lora-modules",
  74. type=str,
  75. default=None,
  76. nargs='+',
  77. action=LoRAParserAction,
  78. help=
  79. "LoRA module configurations in the format name=path. Multiple modules "
  80. "can be specified.")
  81. parser.add_argument("--chat-template",
  82. type=str,
  83. default=None,
  84. help="The file path to the chat template, "
  85. "or the template in single-line form "
  86. "for the specified model")
  87. parser.add_argument("--response-role",
  88. type=str,
  89. default="assistant",
  90. help="The role name to return if "
  91. "`request.add_generation_prompt=true`.")
  92. parser.add_argument("--ssl-keyfile",
  93. type=str,
  94. default=None,
  95. help="The file path to the SSL key file")
  96. parser.add_argument("--ssl-certfile",
  97. type=str,
  98. default=None,
  99. help="The file path to the SSL cert file")
  100. parser.add_argument(
  101. "--root-path",
  102. type=str,
  103. default=None,
  104. help="FastAPI root_path when app is behind a path based routing proxy")
  105. parser.add_argument(
  106. "--middleware",
  107. type=str,
  108. action="append",
  109. default=[],
  110. help="Additional ASGI middleware to apply to the app. "
  111. "We accept multiple --middleware arguments. "
  112. "The value should be an import path. "
  113. "If a function is provided, Aphrodite will add it to the server using "
  114. "@app.middleware('http'). "
  115. "If a class is provided, Aphrodite will add it to the server using "
  116. "app.add_middleware(). ")
  117. parser = AsyncEngineArgs.add_cli_args(parser)
  118. return parser