10
10
from langchain_cli .namespaces .migrate import main as migrate_namespace
11
11
from langchain_cli .utils .packages import get_langserve_export , get_package_root
12
12
13
+ TEMPLATE_CMD = "template"
14
+ APP_CMD = "app"
15
+ INTEGRATION_CMD = "integration"
16
+
13
17
app = typer .Typer (no_args_is_help = True , add_completion = False )
14
18
app .add_typer (
15
- template_namespace .package_cli , name = "template" , help = template_namespace .__doc__
19
+ template_namespace .package_cli , name = TEMPLATE_CMD , help = template_namespace .__doc__
16
20
)
17
- app .add_typer (app_namespace .app_cli , name = "app" , help = app_namespace .__doc__ )
21
+ app .add_typer (app_namespace .app_cli , name = APP_CMD , help = app_namespace .__doc__ )
18
22
app .add_typer (
19
23
integration_namespace .integration_cli ,
20
- name = "integration" ,
24
+ name = INTEGRATION_CMD ,
21
25
help = integration_namespace .__doc__ ,
22
26
)
23
27
24
28
app .command (
25
29
name = "migrate" ,
26
30
context_settings = {
27
- # Let Grit handle the arguments
28
31
"allow_extra_args" : True ,
29
32
"ignore_unknown_options" : True ,
30
33
},
31
- )(
32
- migrate_namespace .migrate ,
33
- )
34
+ )(migrate_namespace .migrate )
34
35
35
36
36
37
def version_callback (show_version : bool ) -> None :
38
+ """Displays the CLI version and exits."""
37
39
if show_version :
38
40
typer .echo (f"langchain-cli { __version__ } " )
39
41
raise typer .Exit ()
@@ -49,34 +51,41 @@ def main(
49
51
callback = version_callback ,
50
52
is_eager = True ,
51
53
),
52
- ):
54
+ ) -> None :
55
+ """CLI entry point."""
53
56
pass
54
57
55
58
56
59
@app .command ()
57
60
def serve (
58
61
* ,
59
62
port : Annotated [
60
- Optional [int ], typer .Option (help = "The port to run the server on" )
63
+ Optional [int ],
64
+ typer .Option (help = "The port to run the server on" ),
61
65
] = None ,
62
66
host : Annotated [
63
- Optional [str ], typer .Option (help = "The host to run the server on" )
67
+ Optional [str ],
68
+ typer .Option (help = "The host to run the server on" ),
64
69
] = None ,
65
70
) -> None :
66
- """
67
- Start the LangServe app, whether it's a template or an app.
68
- """
69
-
70
- # see if is a template
71
+ """Start the LangServe app, either as a template or an app."""
71
72
try :
72
73
project_dir = get_package_root ()
73
74
pyproject = project_dir / "pyproject.toml"
74
75
get_langserve_export (pyproject )
75
- except KeyError :
76
- # not a template
76
+ except KeyError as e :
77
+ typer .secho (
78
+ f"Error: { e } . This project does not seem to be a template." ,
79
+ fg = typer .colors .RED ,
80
+ )
77
81
app_namespace .serve (port = port , host = host )
82
+ except FileNotFoundError :
83
+ typer .secho (
84
+ "Error: `pyproject.toml` not found. "
85
+ "Ensure you are in a valid project directory." ,
86
+ fg = typer .colors .RED ,
87
+ )
78
88
else :
79
- # is a template
80
89
template_namespace .serve (port = port , host = host )
81
90
82
91
0 commit comments