forked from Arush-Pimpalkar/Transfinitte23_BX1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_examples.py
executable file
·175 lines (141 loc) · 3.47 KB
/
run_examples.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python
"""
This is the main entrypoint for running all examples with centralized configuration.
However, all examples are self-contained and can also be run directly.
"""
import functools
import click
from dotenv import load_dotenv
load_dotenv()
@click.group
def cli() -> None:
pass
def common_options(func):
@click.option(
"--host",
"-h",
envvar="PATHWAY_REST_CONNECTOR_HOST",
type=str,
default="127.0.0.1",
help="Rest input connector host.",
)
@click.option(
"--port",
"-p",
envvar="PATHWAY_REST_CONNECTOR_PORT",
type=int,
default=8080,
help="Rest input connector port.",
)
@click.option(
"--data_dir",
envvar="PATHWAY_DATA_DIR",
type=str,
required=False,
)
@click.option(
"--cache_dir",
"-c",
envvar="PATHWAY_CACHE_DIR",
type=str,
default="/tmp/cache",
)
@click.option(
"--embedder_locator",
"-e",
envvar="EMBEDDER_LOCATOR",
type=str,
required=False,
help="Embedding model locator.",
)
@click.option(
"--embedding_dimension",
"-d",
envvar="EMBEDDING_DIMENSION",
type=int,
required=False,
help="Embedding model output dimension.",
)
@click.option(
"--max_tokens",
"-x",
envvar="MAX_OUTPUT_TOKENS",
type=int,
required=False,
help="Maximum output tokens of the LLM.",
)
@click.option(
"--model_locator",
"-m",
envvar="MODEL_LOCATOR",
type=str,
required=False,
help="LLM locator for text completion/generation.",
)
@click.option(
"--api_key",
"-k",
envvar="OPENAI_API_TOKEN",
type=str,
required=False,
help="API Key for OpenAI/HuggingFace Inference APIs.",
)
@click.option(
"--temperature",
"-t",
envvar="MODEL_TEMPERATURE",
type=float,
required=False,
help="LLM temperature, controls the randomness of the outputs.",
)
@click.option(
"--device",
envvar="DEVICE",
type=str,
required=False,
help="Device to run models on, e.g. 'cpu', 'cuda'",
)
@functools.wraps(func)
def wrapper(**kwargs):
kwargs = {k: v for k, v in kwargs.items() if v is not None}
return func(**kwargs)
return wrapper
@cli.command()
@common_options
def local(**kwargs):
from examples.pipelines.local import run
return run(**kwargs)
@cli.command()
@common_options
def contextful(**kwargs):
from examples.pipelines.contextful import run
return run(**kwargs)
@cli.command()
@common_options
def s3(**kwargs):
from examples.pipelines.contextful_s3 import run
return run(**kwargs)
@cli.command()
@common_options
def contextless(**kwargs):
from examples.pipelines.contextless import run
return run(**kwargs)
@cli.command()
@common_options
def unstructured(**kwargs):
from examples.pipelines.unstructured import run
return run(**kwargs)
@cli.command()
@common_options
def unstructuredtosql(**kwargs):
from examples.pipelines.unstructured_to_sql_on_the_fly import run
return run(**kwargs)
@cli.command()
@common_options
def alert(**kwargs):
from examples.pipelines.alert import run
return run(**kwargs)
def main():
cli.main()
if __name__ == "__main__":
cli.main()