-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathapp.py
More file actions
75 lines (62 loc) · 2.4 KB
/
app.py
File metadata and controls
75 lines (62 loc) · 2.4 KB
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
import logging
from warnings import warn
import pathway as pw
from dotenv import load_dotenv
from pathway.xpacks.llm.document_store import DocumentStore
from pathway.xpacks.llm.servers import DocumentStoreServer
from pydantic import BaseModel, ConfigDict, InstanceOf
# To use advanced features with Pathway Scale, get your free license key from
# https://pathway.com/features and paste it below.
# To use Pathway Community, comment out the line below.
pw.set_license_key("demo-license-key-with-telemetry")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(name)s %(levelname)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
load_dotenv()
class App(BaseModel):
document_store: InstanceOf[DocumentStore]
host: str = "0.0.0.0"
port: int = 8000
with_cache: bool | None = None # deprecated
persistence_backend: pw.persistence.Backend | None = None
persistence_mode: pw.PersistenceMode | None = pw.PersistenceMode.UDF_CACHING
terminate_on_error: bool = False
def run(self) -> None:
server = DocumentStoreServer( # noqa: F841
self.host, self.port, self.document_store
)
if self.persistence_mode is None:
if self.with_cache is True:
warn(
"`with_cache` is deprecated. Please use `persistence_mode` instead.",
DeprecationWarning,
)
persistence_mode = pw.PersistenceMode.UDF_CACHING
else:
persistence_mode = None
else:
persistence_mode = self.persistence_mode
if persistence_mode is not None:
if self.persistence_backend is None:
persistence_backend = pw.persistence.Backend.filesystem("./Cache")
else:
persistence_backend = self.persistence_backend
persistence_config = pw.persistence.Config(
persistence_backend,
persistence_mode=persistence_mode,
)
else:
persistence_config = None
pw.run(
persistence_config=persistence_config,
terminate_on_error=self.terminate_on_error,
monitoring_level=pw.MonitoringLevel.NONE,
)
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
if __name__ == "__main__":
with open("app.yaml") as f:
config = pw.load_yaml(f)
app = App(**config)
app.run()