aboutsummaryrefslogtreecommitdiff
path: root/src/gpt_chat_cli/main.py
blob: 7af4d2dd9e8bdc96a69cfd1855b52df88fe79011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3

# PYTHON_ARGCOMPLETE_OK

def main():
    # defer other imports until autocomplete has finished
    from .argparsing import parse_raw_args_or_complete

    raw_args = parse_raw_args_or_complete()

    # post process and validate
    from .argvalidation import (
        Arguments,
        post_process_raw_args
    )

    args = post_process_raw_args( raw_args )

    # populate key
    import openai

    openai.api_key = args.openai_key

    # execute relevant command
    from .cmd import (
        version,
        list_models,
        interactive,
        singleton,
    )

    if args.version:
        version()
    elif args.list_models:
        list_models()
    elif args.interactive:
        interactive(args)
    else:
        singleton(args)

    return 0

if __name__ == "__main__":
    main()