2023-06-30 15:11:20 -04:00
|
|
|
import argparse
|
2023-05-18 00:17:35 -04:00
|
|
|
from chainforge.flask_app import run_server
|
2023-04-19 15:08:31 -04:00
|
|
|
|
2023-05-18 00:17:35 -04:00
|
|
|
# Main Chainforge start
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description='Chainforge command line tool')
|
|
|
|
|
|
|
|
# Serve command
|
|
|
|
subparsers = parser.add_subparsers(dest='serve')
|
|
|
|
serve_parser = subparsers.add_parser('serve', help='Start Chainforge server')
|
2023-05-04 11:34:12 -04:00
|
|
|
|
2023-06-30 15:11:20 -04:00
|
|
|
# TODO: Add this back
|
2023-05-04 11:34:12 -04:00
|
|
|
# Turn on to disable all outbound LLM API calls and replace them with dummy calls
|
|
|
|
# that return random strings of ASCII characters. Useful for testing interface without wasting $$.
|
2023-06-30 15:11:20 -04:00
|
|
|
# serve_parser.add_argument('--dummy-responses',
|
|
|
|
# help="""Disables queries to LLMs, replacing them with spoofed responses composed of random ASCII characters.
|
|
|
|
# Produces each dummy response at random intervals between 0.1 and 3 seconds.""",
|
|
|
|
# dest='dummy_responses',
|
|
|
|
# action='store_true')
|
2023-05-18 00:17:35 -04:00
|
|
|
|
|
|
|
# TODO: Reimplement this where the React server is given the backend's port before loading.
|
2023-12-04 18:53:57 -05:00
|
|
|
serve_parser.add_argument('--port',
|
|
|
|
help='The port to run the server on. Defaults to 8000.',
|
|
|
|
type=int, default=8000, nargs='?')
|
2023-07-20 11:17:58 -04:00
|
|
|
serve_parser.add_argument('--host',
|
|
|
|
help="The host to run the server on. Defaults to 'localhost'.",
|
|
|
|
type=str, default="localhost", nargs='?')
|
2023-12-04 18:53:57 -05:00
|
|
|
|
2023-05-04 11:34:12 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-05-18 00:17:35 -04:00
|
|
|
# Currently only support the 'serve' command...
|
|
|
|
if not args.serve:
|
|
|
|
parser.print_help()
|
|
|
|
exit(0)
|
|
|
|
|
2023-07-20 11:17:58 -04:00
|
|
|
port = args.port if args.port else 8000
|
|
|
|
host = args.host if args.host else "localhost"
|
2023-05-06 13:02:47 -04:00
|
|
|
|
2023-07-20 11:17:58 -04:00
|
|
|
print(f"Serving Flask server on {host} on port {port}...")
|
|
|
|
run_server(host=host, port=port, cmd_args=args)
|
2023-05-18 00:17:35 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|