-
Notifications
You must be signed in to change notification settings - Fork 727
/
Copy pathcli.py
114 lines (99 loc) · 2.54 KB
/
cli.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import click
import uvicorn
import os
from dotenv import load_dotenv
from goldenverba import verba_manager
from goldenverba.server.types import Credentials
load_dotenv()
@click.group()
def cli():
"""Main command group for verba."""
pass
@cli.command()
@click.option(
"--port",
default=8000,
help="FastAPI Port",
)
@click.option(
"--host",
default="localhost",
help="FastAPI Host",
)
@click.option(
"--prod/--no-prod",
default=False,
help="Run in production mode.",
)
@click.option(
"--workers",
default=4,
help="Workers to run Verba",
)
def start(port, host, prod, workers):
"""
Run the FastAPI application.
"""
uvicorn.run(
"goldenverba.server.api:app",
host=host,
port=port,
reload=(not prod),
workers=workers,
)
@click.option(
"--url",
default=os.getenv("WEAVIATE_URL_VERBA"),
help="Weaviate URL",
)
@click.option(
"--api_key",
default=os.getenv("WEAVIATE_API_KEY_VERBA"),
help="Weaviate API Key",
)
@click.option(
"--deployment",
default="",
help="Deployment (Local, Weaviate, Docker)",
)
@click.option(
"--full_reset",
default=False,
help="Full reset (True, False)",
)
@cli.command()
def reset(url, api_key, deployment, full_reset):
"""
Run the FastAPI application.
"""
import asyncio
manager = verba_manager.VerbaManager()
async def async_reset():
if url is not None and api_key is not None:
if deployment == "" or deployment == "Weaviate":
client = await manager.connect(
Credentials(deployment="Weaviate", url=url, key=api_key)
)
elif deployment == "Docker":
client = await manager.connect(
Credentials(deployment="Docker", url=url, key=api_key)
)
else:
raise ValueError("Invalid deployment")
else:
if deployment == "" or deployment == "Local":
client = await manager.connect(
Credentials(deployment="Local", url="", key="")
)
else:
raise ValueError("Invalid deployment")
if not full_reset:
await manager.reset_rag_config(client)
await manager.reset_theme_config(client)
await manager.reset_user_config(client)
else:
await manager.weaviate_manager.delete_all(client)
await client.close()
asyncio.run(async_reset())
if __name__ == "__main__":
cli()