2023-04-30 12:16:48 +02:00
#!/usr/bin/env python3
# Copyright (c) 2023 Julian Müller (ChaoticByte)
from argparse import ArgumentParser
2023-05-18 15:34:34 +02:00
from json import load
from pathlib import Path
2023-04-30 12:16:48 +02:00
import uvicorn
from frontend . app import app
if __name__ == " __main__ " :
2023-05-18 15:34:34 +02:00
koala_profile_path = Path ( __file__ ) . parent / " profiles " / " koala.json "
2023-04-30 12:16:48 +02:00
# CLI
ap = ArgumentParser ( )
2023-05-18 15:34:34 +02:00
ap . add_argument ( " --profile " , help = " Path to a profile file that includes settings for a specific model (default: ./profiles/koala.json) " , type = Path , default = koala_profile_path )
2023-04-30 12:16:48 +02:00
ap . add_argument ( " --host " , help = " Address to listen on (default: localhost) " , type = str , default = " localhost " )
ap . add_argument ( " --port " , help = " Port to listen on (default: 8080) " , type = int , default = 8080 )
ap . add_argument ( " --api " , help = " URL of the API Server (default: ' http://localhost:7331 ' ) " , type = str , default = " http://localhost:7331 " )
args = ap . parse_args ( )
2023-05-18 15:34:34 +02:00
# Read profile
with args . profile . open ( " r " ) as pf :
profile = load ( pf )
# Check profile
assert " name " in profile
assert " conversation_prefix " in profile
assert " user_keyword " in profile
assert " assistant_keyword " in profile
assert " stop_sequence " in profile
2023-04-30 12:16:48 +02:00
# Pass frontend config to the app
2023-05-18 15:34:34 +02:00
app . config . frontend_config = {
" api_url " : args . api . rstrip ( " / " ) ,
" profile " : {
" name " : profile [ " name " ] ,
" conversation_prefix " : profile [ " conversation_prefix " ] ,
" user_keyword " : profile [ " user_keyword " ] ,
" assistant_keyword " : profile [ " assistant_keyword " ] ,
" stop_sequence " : profile [ " stop_sequence " ]
}
}
2023-04-30 12:16:48 +02:00
# Run
uvicorn . run ( app , host = args . host , port = args . port )