Skip to content

Commit c1b31bd

Browse files
committed
perf: skip LLM imports when MYCLI_LLM_OFF is set
1 parent eea4df4 commit c1b31bd

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Internal
1515
* Add CI on macOS.
1616
* Add limited CI on Windows.
1717
* Add limited CI on Windows WSL.
18+
* Speed up startup by skipping LLM imports when `MYCLI_LLM_OFF` is set.
1819

1920

2021
1.73.1 (2026/05/29)

mycli/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Contributors:
117117
* yurenchen000
118118
* Linuxdazhao
119119
* Puneet Dixit
120+
* Liu Zhenlong
120121

121122

122123
Created by:

mycli/packages/special/__init__.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from mycli.packages.special.dbcommands import (
24
list_databases,
35
list_tables,
@@ -41,12 +43,30 @@
4143
write_pipe_once,
4244
write_tee,
4345
)
44-
from mycli.packages.special.llm import (
45-
FinishIteration,
46-
handle_llm,
47-
is_llm_command,
48-
sql_using_llm,
49-
)
46+
47+
if not os.environ.get('MYCLI_LLM_OFF'):
48+
from mycli.packages.special.llm import (
49+
FinishIteration,
50+
handle_llm,
51+
is_llm_command,
52+
sql_using_llm,
53+
)
54+
else:
55+
56+
class FinishIteration(Exception): # type: ignore[no-redef]
57+
def __init__(self, results=None):
58+
self.results = results
59+
60+
def is_llm_command(command: str) -> bool: # type: ignore[no-redef]
61+
return False
62+
63+
def handle_llm(*args, **kwargs): # type: ignore[no-redef, misc]
64+
raise FinishIteration(results=None)
65+
66+
def sql_using_llm(*args, **kwargs): # type: ignore[no-redef, misc]
67+
raise FinishIteration(results=None)
68+
69+
5070
from mycli.packages.special.main import (
5171
CommandNotFound,
5272
SpecialCommandAlias,

0 commit comments

Comments
 (0)