Skip to content

Commit

Permalink
Fix keywords not being loaded for child processes
Browse files Browse the repository at this point in the history
Remove redundant conditions with ollama trigger
  • Loading branch information
dormant-user committed Jun 9, 2024
1 parent 884fbeb commit 2aebb18
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 47 deletions.
17 changes: 13 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7352,11 +7352,20 @@ <h1>Crontab<a class="headerlink" href="#id2" title="Permalink to this heading">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>filename</strong> – Name of the env file.</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Loads the <code class="docutils literal notranslate"><span class="pre">EnvConfig</span></code> model.</p>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<ul class="simple">
<li><p>Loading environment variables from files are an additional feature.</p></li>
<li><p>Both the system’s and session’s env vars are processed by default.</p></li>
</ul>
</div>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>Loads the <code class="docutils literal notranslate"><span class="pre">EnvConfig</span></code> model.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><a class="reference internal" href="#jarvis.modules.models.classes.EnvConfig" title="jarvis.modules.models.classes.EnvConfig">EnvConfig</a></p>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><a class="reference internal" href="#jarvis.modules.models.classes.EnvConfig" title="jarvis.modules.models.classes.EnvConfig">EnvConfig</a></p>
</dd>
</dl>
</dd></dl>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

65 changes: 34 additions & 31 deletions jarvis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

version = "5.0.0"

if current_process().name == "MainProcess":
current_process().name = os.environ.get("PROCESS_NAME", "JARVIS")


def __preflight_check__() -> Callable:
"""Startup validator that imports Jarvis' main module to validate all dependencies' installation status.
Expand Down Expand Up @@ -43,34 +40,40 @@ def start() -> None:

def commandline() -> None:
"""Starter function to invoke Jarvis using commandline."""
if sys.argv[0].endswith("jarvis"):
choices = "\n\t* " + "\n\t* ".join(
("install", "dev-install", "start | run", "version | -v | --version | -V")
# This is to validate that only 'jarvis' command triggers this function and not invoked by other functions
assert sys.argv[0].endswith("jarvis"), "Invalid commandline trigger!!"
_pretext = "\n\t* "
choices = _pretext + _pretext.join(
("install", "dev-install", "start | run", "version | -v | --version | -V")
)
try:
arg = sys.argv[1].lower()
except (IndexError, AttributeError):
print(
f"Cannot proceed without arbitrary commands. Please choose from {choices}"
)
try:
arg = sys.argv[1].lower()
except (IndexError, AttributeError):
print(
f"Cannot proceed without arbitrary commands. Please choose from {choices}"
)
exit(1)
match arg:
case "install":
from jarvis.lib import install # noqa: F401
exit(1)
match arg:
case "install":
from jarvis.lib import install # noqa: F401

install.main()
case "dev-install":
from jarvis.lib import install # noqa: F401

install.dev()
case "start" | "run":
init = __preflight_check__()
init()
case "version" | "-v" | "-V" | "--version":
print(f"Jarvis {version}")
case _:
print(f"Unknown Option: {arg}\nArbitrary commands must be one of {choices}")

install.main()
case "dev-install":
from jarvis.lib import install # noqa: F401

install.dev()
case "start" | "run":
init = __preflight_check__()
init()
case "version" | "-v" | "-V" | "--version":
print(f"Jarvis {version}")
case _:
print(
f"Unknown Option: {arg}\nArbitrary commands must be one of {choices}"
)
else:
__preflight_check__()
# MainProcess has specific conditions to land at 'start' or 'commandline'
# __preflight_check__ still needs to be loaded for all other child processes
if current_process().name == "MainProcess":
current_process().name = os.environ.get("PROCESS_NAME", "JARVIS")
else:
__preflight_check__()
4 changes: 4 additions & 0 deletions jarvis/modules/models/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ def from_env_file(cls, filename: pathlib.Path) -> "EnvConfig":
Args:
filename: Name of the env file.
See Also:
- Loading environment variables from files are an additional feature.
- Both the system's and session's env vars are processed by default.
Returns:
EnvConfig:
Loads the ``EnvConfig`` model.
Expand Down
12 changes: 6 additions & 6 deletions jarvis/modules/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@
}
KEEP_TABLES = ("vpn", "party", "listener") # TABLES to keep from `fileio.base_db`
startup = settings.pname in ("JARVIS", "telegram_api", "jarvis_api")
if startup and env.startup_options and StartupOptions.all in env.startup_options:
# 'startup_gpt' is required since it has to be invoked only for certain child processes
# this will avoid running GPT instance for pre-commit as well
if startup and StartupOptions.all in env.startup_options:
startup_car = True
startup_gpt = True
startup_gpt = env.ollama
startup_thermostat = True
elif startup and env.startup_options:
elif startup:
startup_car = StartupOptions.car in env.startup_options
# Hard coded since GPT has its own trigger 'ollama' and it's not actually a background functionality
startup_gpt = True
startup_gpt = env.ollama
startup_thermostat = StartupOptions.thermostat in env.startup_options
else:
startup_car = False
# Hard coded since GPT has its own trigger 'ollama' and it's not actually a background functionality
startup_gpt = False
startup_thermostat = False

Expand Down
7 changes: 2 additions & 5 deletions jarvis/modules/transformer/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def query(self, phrase: str) -> None:
static_responses.un_processable()


if models.startup_gpt and models.env.ollama:
if models.startup_gpt:
if models.env.ollama_reuse_threshold:
start = (
f"Initiating GPT instance for {models.settings.pname!r} with a "
Expand All @@ -300,8 +300,5 @@ def query(self, phrase: str) -> None:
logger.error("Failed to load GPT instance for '%s'", models.settings.pname)
instance = None
else:
if models.startup_gpt and not models.env.ollama:
logger.warning(
"GPT has been disabled! To enable it, set the env var ollama=True"
)
logger.warning("GPT has been disabled! To enable it, set the env var ollama=True")
instance = None

0 comments on commit 2aebb18

Please sign in to comment.