From 7dd1acafa27b90ad6541b9369e171e6e69dfc96a Mon Sep 17 00:00:00 2001 From: rboone Date: Thu, 11 Apr 2024 17:09:48 +0200 Subject: [PATCH 01/17] added 3 env variables to more easily and correctly configure shell_gpt containers --- Dockerfile | 3 +++ sgpt/app.py | 2 +- sgpt/config.py | 3 +++ sgpt/role.py | 5 ++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f87b7b9..4da1cfdb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM python:3-slim +ENV IN_CONTAINER=true +ENV OS_OUTSIDE_CONTAINER="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" + WORKDIR /app COPY . /app diff --git a/sgpt/app.py b/sgpt/app.py index bd092165..e1fee23c 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -57,7 +57,7 @@ def main( rich_help_panel="Assistance Options", ), interaction: bool = typer.Option( - True, + True if cfg.get("IN_CONTAINER") == "false" else False, help="Interactive mode for --shell option.", rich_help_panel="Assistance Options", ), diff --git a/sgpt/config.py b/sgpt/config.py index 981cba74..e38f61df 100644 --- a/sgpt/config.py +++ b/sgpt/config.py @@ -34,6 +34,9 @@ "API_BASE_URL": os.getenv("API_BASE_URL", "default"), "PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"), "USE_LITELLM": os.getenv("USE_LITELLM", "false"), + "IN_CONTAINER": os.getenv("IN_CONTAINER", "false"), + "OS_OUTSIDE_CONTAINER": os.getenv("OS_OUTSIDE_CONTAINER", "Linux/Debian 12 (bookworm)"), + "SHELL_OUTSIDE_CONTAINER": os.getenv("SHELL_OUTSIDE_CONTAINER", "/bin/bash"), # New features might add their own config variables here. } diff --git a/sgpt/role.py b/sgpt/role.py index 4671da9a..59e5bc65 100644 --- a/sgpt/role.py +++ b/sgpt/role.py @@ -62,7 +62,10 @@ def __init__( @classmethod def create_defaults(cls) -> None: cls.storage.parent.mkdir(parents=True, exist_ok=True) - variables = {"shell": cls._shell_name(), "os": cls._os_name()} + if cfg.get("IN_CONTAINER") != "true": + variables = {"shell": cls._shell_name(), "os": cls._os_name()} + else: # running in container + variables = {"shell": cfg.get("SHELL_OUTSIDE_CONTAINER"), "os": cfg.get("OS_OUTSIDE_CONTAINER")} for default_role in ( SystemRole("ShellGPT", DEFAULT_ROLE, variables), SystemRole("Shell Command Generator", SHELL_ROLE, variables), From 0c9964197d7c4ea16b6c56539b9107df6f862836 Mon Sep 17 00:00:00 2001 From: rboone Date: Thu, 11 Apr 2024 17:10:24 +0200 Subject: [PATCH 02/17] added ollama Dockerfile example --- Dockerfile_ollama | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Dockerfile_ollama diff --git a/Dockerfile_ollama b/Dockerfile_ollama new file mode 100644 index 00000000..aa502825 --- /dev/null +++ b/Dockerfile_ollama @@ -0,0 +1,20 @@ +FROM python:3-slim + +ENV DEFAULT_MODEL=ollama/mistral:7b-instruct-v0.2-q4_K_M +ENV API_BASE_URL=http://127.0.0.1:11434 +ENV USE_LITELLM=true +ENV OPENAI_API_KEY=bad_key +ENV PRETTIFY_MARKDOWN=false + +ENV IN_CONTAINER=true +ENV OS_OUTSIDE_CONTAINER="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" + +WORKDIR /app +COPY . /app + +RUN apt-get update && apt-get install -y gcc +RUN pip install --no-cache /app[litellm] && mkdir -p /tmp/shell_gpt + +VOLUME /tmp/shell_gpt + +ENTRYPOINT ["sgpt"] From 98e2c326dc0ddf511de8488dfd396e521eb77453 Mon Sep 17 00:00:00 2001 From: rboone Date: Thu, 11 Apr 2024 17:40:51 +0200 Subject: [PATCH 03/17] having SHELL_OUTSIDE_CONTAINER in Dockerfile is more intuitive --- Dockerfile | 1 + Dockerfile_ollama | 1 + 2 files changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 4da1cfdb..0c90f25c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM python:3-slim ENV IN_CONTAINER=true ENV OS_OUTSIDE_CONTAINER="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" +ENV SHELL_OUTSIDE_CONTAINER=/bin/bash WORKDIR /app COPY . /app diff --git a/Dockerfile_ollama b/Dockerfile_ollama index aa502825..0a695095 100644 --- a/Dockerfile_ollama +++ b/Dockerfile_ollama @@ -8,6 +8,7 @@ ENV PRETTIFY_MARKDOWN=false ENV IN_CONTAINER=true ENV OS_OUTSIDE_CONTAINER="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" +ENV SHELL_OUTSIDE_CONTAINER=/bin/bash WORKDIR /app COPY . /app From a1abe7a38f66846ff6e62a3547f01b946fc58649 Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Mon, 15 Apr 2024 15:55:42 +0200 Subject: [PATCH 04/17] changes based on feedback, including README.md update --- Dockerfile | 6 +++--- Dockerfile_ollama | 21 --------------------- README.md | 18 +++++++++++++++++- sgpt/app.py | 2 +- sgpt/config.py | 6 +++--- sgpt/role.py | 37 ++++++++++++++++++++----------------- 6 files changed, 44 insertions(+), 46 deletions(-) delete mode 100644 Dockerfile_ollama diff --git a/Dockerfile b/Dockerfile index 0c90f25c..8ec75b8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM python:3-slim -ENV IN_CONTAINER=true -ENV OS_OUTSIDE_CONTAINER="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" -ENV SHELL_OUTSIDE_CONTAINER=/bin/bash +ENV SHELL_INTERACTION=false +ENV OVERWRITE_OS_NAME="" +ENV OVERWRITE_SHELL_NAME="" WORKDIR /app COPY . /app diff --git a/Dockerfile_ollama b/Dockerfile_ollama deleted file mode 100644 index 0a695095..00000000 --- a/Dockerfile_ollama +++ /dev/null @@ -1,21 +0,0 @@ -FROM python:3-slim - -ENV DEFAULT_MODEL=ollama/mistral:7b-instruct-v0.2-q4_K_M -ENV API_BASE_URL=http://127.0.0.1:11434 -ENV USE_LITELLM=true -ENV OPENAI_API_KEY=bad_key -ENV PRETTIFY_MARKDOWN=false - -ENV IN_CONTAINER=true -ENV OS_OUTSIDE_CONTAINER="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" -ENV SHELL_OUTSIDE_CONTAINER=/bin/bash - -WORKDIR /app -COPY . /app - -RUN apt-get update && apt-get install -y gcc -RUN pip install --no-cache /app[litellm] && mkdir -p /tmp/shell_gpt - -VOLUME /tmp/shell_gpt - -ENTRYPOINT ["sgpt"] diff --git a/README.md b/README.md index 55649973..e31b06f6 100644 --- a/README.md +++ b/README.md @@ -461,9 +461,16 @@ docker run --rm \ ghcr.io/ther1d/shell_gpt --chat rainbow "what are the colors of a rainbow" ``` +When using a container, please note: +* The \[E\]xecute option for --shell with interaction will not work, since it would try this Execute in the docker container. +=> setting the `SHELL_INTERACTION` environment variable to false , makes sense. +* Since, most likely the os and shell of your container are not identical to the environment you want help with: +set the environment variables `OVERWRITE_OS_NAME` and `OVERWRITE_SHELL_NAME` according to your setup. + + Example of a conversation, using an alias and the `OPENAI_API_KEY` environment variable: ```shell -alias sgpt="docker run --rm --env OPENAI_API_KEY --volume gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt" +alias sgpt="docker run --rm --env OPENAI_API_KEY --env SHELL_INTERACTION=false OVERWRITE_OS_NAME=Debian --env OVERWRITE_SHELL_NAME=bash --volume gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt" export OPENAI_API_KEY="your OPENAI API key" sgpt --chat rainbow "what are the colors of a rainbow" sgpt --chat rainbow "inverse the list of your last answer" @@ -475,4 +482,13 @@ You also can use the provided `Dockerfile` to build your own image: docker build -t sgpt . ``` +Example environment variables for a working Ollama setup, using Docker: +* ENV DEFAULT_MODEL=ollama/mistral:7b-instruct-v0.2-q4_K_M +* ENV API_BASE_URL=http://10.10.10.10:11434 +* ENV USE_LITELLM=true +* ENV OPENAI_API_KEY=bad_key +* ENV SHELL_INTERACTION=false +* ENV OVERWRITE_OS_NAME="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" +* ENV OVERWRITE_SHELL_NAME=/bin/bash + Additional documentation: [Azure integration](https://github.com/TheR1D/shell_gpt/wiki/Azure), [Ollama integration](https://github.com/TheR1D/shell_gpt/wiki/Ollama). diff --git a/sgpt/app.py b/sgpt/app.py index e1fee23c..f53e4bd1 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -57,7 +57,7 @@ def main( rich_help_panel="Assistance Options", ), interaction: bool = typer.Option( - True if cfg.get("IN_CONTAINER") == "false" else False, + False if cfg.get("SHELL_INTERACTION") == "false" else True, help="Interactive mode for --shell option.", rich_help_panel="Assistance Options", ), diff --git a/sgpt/config.py b/sgpt/config.py index e38f61df..afbf68da 100644 --- a/sgpt/config.py +++ b/sgpt/config.py @@ -34,9 +34,9 @@ "API_BASE_URL": os.getenv("API_BASE_URL", "default"), "PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"), "USE_LITELLM": os.getenv("USE_LITELLM", "false"), - "IN_CONTAINER": os.getenv("IN_CONTAINER", "false"), - "OS_OUTSIDE_CONTAINER": os.getenv("OS_OUTSIDE_CONTAINER", "Linux/Debian 12 (bookworm)"), - "SHELL_OUTSIDE_CONTAINER": os.getenv("SHELL_OUTSIDE_CONTAINER", "/bin/bash"), + "SHELL_INTERACTION ": os.getenv("SHELL_INTERACTION ", "true"), + "OVERWRITE_OS_NAME": os.getenv("OVERWRITE_OS_NAME", ""), + "OVERWRITE_SHELL_NAME ": os.getenv("OVERWRITE_SHELL_NAME", ""), # New features might add their own config variables here. } diff --git a/sgpt/role.py b/sgpt/role.py index 59e5bc65..73e9b4c0 100644 --- a/sgpt/role.py +++ b/sgpt/role.py @@ -62,10 +62,7 @@ def __init__( @classmethod def create_defaults(cls) -> None: cls.storage.parent.mkdir(parents=True, exist_ok=True) - if cfg.get("IN_CONTAINER") != "true": - variables = {"shell": cls._shell_name(), "os": cls._os_name()} - else: # running in container - variables = {"shell": cfg.get("SHELL_OUTSIDE_CONTAINER"), "os": cfg.get("OS_OUTSIDE_CONTAINER")} + variables = {"shell": cls._shell_name(), "os": cls._os_name()} for default_role in ( SystemRole("ShellGPT", DEFAULT_ROLE, variables), SystemRole("Shell Command Generator", SHELL_ROLE, variables), @@ -116,22 +113,28 @@ def get_role_name(cls, initial_message: str) -> Optional[str]: @classmethod def _os_name(cls) -> str: - current_platform = platform.system() - if current_platform == "Linux": - return "Linux/" + distro_name(pretty=True) - if current_platform == "Windows": - return "Windows " + platform.release() - if current_platform == "Darwin": - return "Darwin/MacOS " + platform.mac_ver()[0] - return current_platform + if cfg.get("OVERWRITE_OS_NAME") != "": + return cfg.get("OVERWRITE_OS_NAME") + else: + current_platform = platform.system() + if current_platform == "Linux": + return "Linux/" + distro_name(pretty=True) + if current_platform == "Windows": + return "Windows " + platform.release() + if current_platform == "Darwin": + return "Darwin/MacOS " + platform.mac_ver()[0] + return current_platform @classmethod def _shell_name(cls) -> str: - current_platform = platform.system() - if current_platform in ("Windows", "nt"): - is_powershell = len(getenv("PSModulePath", "").split(pathsep)) >= 3 - return "powershell.exe" if is_powershell else "cmd.exe" - return basename(getenv("SHELL", "/bin/sh")) + if cfg.get("OVERWRITE_SHELL_NAME") != "": + return cfg.get("OVERWRITE_SHELL_NAME") + else: + current_platform = platform.system() + if current_platform in ("Windows", "nt"): + is_powershell = len(getenv("PSModulePath", "").split(pathsep)) >= 3 + return "powershell.exe" if is_powershell else "cmd.exe" + return basename(getenv("SHELL", "/bin/sh")) @property def _exists(self) -> bool: From 5cd6d43aa0e96a4b94f511e3731c5b745c73a25a Mon Sep 17 00:00:00 2001 From: rboone Date: Tue, 16 Apr 2024 15:12:59 +0200 Subject: [PATCH 05/17] More logical / readable way to decide interaction default value --- sgpt/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sgpt/app.py b/sgpt/app.py index f53e4bd1..e58a907a 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -57,7 +57,7 @@ def main( rich_help_panel="Assistance Options", ), interaction: bool = typer.Option( - False if cfg.get("SHELL_INTERACTION") == "false" else True, + True if cfg.get("SHELL_INTERACTION") != "false" else False, help="Interactive mode for --shell option.", rich_help_panel="Assistance Options", ), From 97b2a3aff26ec7c01f6569f33de110258a873c1d Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Wed, 24 Apr 2024 09:57:08 +0200 Subject: [PATCH 06/17] edited example to output pretty OS name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e31b06f6..3ff2a0b8 100644 --- a/README.md +++ b/README.md @@ -470,7 +470,7 @@ set the environment variables `OVERWRITE_OS_NAME` and `OVERWRITE_SHELL_NAME` acc Example of a conversation, using an alias and the `OPENAI_API_KEY` environment variable: ```shell -alias sgpt="docker run --rm --env OPENAI_API_KEY --env SHELL_INTERACTION=false OVERWRITE_OS_NAME=Debian --env OVERWRITE_SHELL_NAME=bash --volume gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt" +alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OVERWRITE_OS_NAME=$(grep -oP '^PRETTY_NAME="\K[^"]+' /etc/os-release) --env OVERWRITE_SHELL_NAME=$(echo $SHELL) ghcr.io/ther1d/shell_gpt" export OPENAI_API_KEY="your OPENAI API key" sgpt --chat rainbow "what are the colors of a rainbow" sgpt --chat rainbow "inverse the list of your last answer" From e04f2fe89ef444d4d4afd63dc5c72dc444c5cc7e Mon Sep 17 00:00:00 2001 From: Robin Boone <43806560+Robinsane@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:18:24 +0200 Subject: [PATCH 07/17] OVERWRITE_OS_NAME default OVERWRITE_OS_NAME value "default" + got rid of redundant else Co-authored-by: Farkhod Sadykov --- sgpt/role.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sgpt/role.py b/sgpt/role.py index 73e9b4c0..95df12c1 100644 --- a/sgpt/role.py +++ b/sgpt/role.py @@ -113,17 +113,16 @@ def get_role_name(cls, initial_message: str) -> Optional[str]: @classmethod def _os_name(cls) -> str: - if cfg.get("OVERWRITE_OS_NAME") != "": + if cfg.get("OVERWRITE_OS_NAME") != "default": return cfg.get("OVERWRITE_OS_NAME") - else: - current_platform = platform.system() - if current_platform == "Linux": - return "Linux/" + distro_name(pretty=True) - if current_platform == "Windows": - return "Windows " + platform.release() - if current_platform == "Darwin": - return "Darwin/MacOS " + platform.mac_ver()[0] - return current_platform + current_platform = platform.system() + if current_platform == "Linux": + return "Linux/" + distro_name(pretty=True) + if current_platform == "Windows": + return "Windows " + platform.release() + if current_platform == "Darwin": + return "Darwin/MacOS " + platform.mac_ver()[0] + return current_platform @classmethod def _shell_name(cls) -> str: From f874b5f00c61943790fa6cebeaa439a5709077fa Mon Sep 17 00:00:00 2001 From: Robin Boone <43806560+Robinsane@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:19:06 +0200 Subject: [PATCH 08/17] OVERWRITE_SHELL_NAME OVERWRITE_SHELL_NAME default value "default" + got rid of redundant else Co-authored-by: Farkhod Sadykov --- sgpt/role.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sgpt/role.py b/sgpt/role.py index 95df12c1..88022236 100644 --- a/sgpt/role.py +++ b/sgpt/role.py @@ -126,14 +126,13 @@ def _os_name(cls) -> str: @classmethod def _shell_name(cls) -> str: - if cfg.get("OVERWRITE_SHELL_NAME") != "": + if cfg.get("OVERWRITE_SHELL_NAME") != "default": return cfg.get("OVERWRITE_SHELL_NAME") - else: - current_platform = platform.system() - if current_platform in ("Windows", "nt"): - is_powershell = len(getenv("PSModulePath", "").split(pathsep)) >= 3 - return "powershell.exe" if is_powershell else "cmd.exe" - return basename(getenv("SHELL", "/bin/sh")) + current_platform = platform.system() + if current_platform in ("Windows", "nt"): + is_powershell = len(getenv("PSModulePath", "").split(pathsep)) >= 3 + return "powershell.exe" if is_powershell else "cmd.exe" + return basename(getenv("SHELL", "/bin/sh")) @property def _exists(self) -> bool: From 1143d7318e8cb0e4ebccbf65a39e27b2050659ad Mon Sep 17 00:00:00 2001 From: Robin Boone <43806560+Robinsane@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:23:05 +0200 Subject: [PATCH 09/17] default values for OVERWRITE_SHELL_NAME and OVERWRITE_SHELL_NAME Co-authored-by: Farkhod Sadykov --- sgpt/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sgpt/config.py b/sgpt/config.py index afbf68da..26f7ff42 100644 --- a/sgpt/config.py +++ b/sgpt/config.py @@ -35,8 +35,8 @@ "PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"), "USE_LITELLM": os.getenv("USE_LITELLM", "false"), "SHELL_INTERACTION ": os.getenv("SHELL_INTERACTION ", "true"), - "OVERWRITE_OS_NAME": os.getenv("OVERWRITE_OS_NAME", ""), - "OVERWRITE_SHELL_NAME ": os.getenv("OVERWRITE_SHELL_NAME", ""), + "OVERWRITE_OS_NAME": os.getenv("OVERWRITE_OS_NAME", "default"), + "OVERWRITE_SHELL_NAME ": os.getenv("OVERWRITE_SHELL_NAME", "default"), # New features might add their own config variables here. } From b510b72914f736ee5711afd4ec68d95cc441896d Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Wed, 24 Apr 2024 10:35:04 +0200 Subject: [PATCH 10/17] default overwrite values in Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ec75b8b..8e84fa92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM python:3-slim ENV SHELL_INTERACTION=false -ENV OVERWRITE_OS_NAME="" -ENV OVERWRITE_SHELL_NAME="" +ENV OVERWRITE_OS_NAME=default +ENV OVERWRITE_SHELL_NAME=default WORKDIR /app COPY . /app From 9ef27fb190666b41a34d6f2ea9230239a6f9bddc Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Thu, 20 Jun 2024 10:10:15 +0200 Subject: [PATCH 11/17] Less confusing variables: OS_NAME and SHELL_NAME with default value auto --- Dockerfile | 4 ++-- sgpt/config.py | 4 ++-- sgpt/role.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8e84fa92..9acc1570 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM python:3-slim ENV SHELL_INTERACTION=false -ENV OVERWRITE_OS_NAME=default -ENV OVERWRITE_SHELL_NAME=default +ENV OS_NAME =auto +ENV SHELL_NAME =auto WORKDIR /app COPY . /app diff --git a/sgpt/config.py b/sgpt/config.py index 26f7ff42..161728f3 100644 --- a/sgpt/config.py +++ b/sgpt/config.py @@ -35,8 +35,8 @@ "PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"), "USE_LITELLM": os.getenv("USE_LITELLM", "false"), "SHELL_INTERACTION ": os.getenv("SHELL_INTERACTION ", "true"), - "OVERWRITE_OS_NAME": os.getenv("OVERWRITE_OS_NAME", "default"), - "OVERWRITE_SHELL_NAME ": os.getenv("OVERWRITE_SHELL_NAME", "default"), + "OS_NAME ": os.getenv("OS_NAME ", "auto"), + "SHELL_NAME ": os.getenv("SHELL_NAME ", "auto"), # New features might add their own config variables here. } diff --git a/sgpt/role.py b/sgpt/role.py index 88022236..2e841aaf 100644 --- a/sgpt/role.py +++ b/sgpt/role.py @@ -113,8 +113,8 @@ def get_role_name(cls, initial_message: str) -> Optional[str]: @classmethod def _os_name(cls) -> str: - if cfg.get("OVERWRITE_OS_NAME") != "default": - return cfg.get("OVERWRITE_OS_NAME") + if cfg.get("OS_NAME ") != "auto": + return cfg.get("OS_NAME ") current_platform = platform.system() if current_platform == "Linux": return "Linux/" + distro_name(pretty=True) @@ -126,8 +126,8 @@ def _os_name(cls) -> str: @classmethod def _shell_name(cls) -> str: - if cfg.get("OVERWRITE_SHELL_NAME") != "default": - return cfg.get("OVERWRITE_SHELL_NAME") + if cfg.get("SHELL_NAME ") != "auto": + return cfg.get("SHELL_NAME ") current_platform = platform.system() if current_platform in ("Windows", "nt"): is_powershell = len(getenv("PSModulePath", "").split(pathsep)) >= 3 From a12d84604d5268159112756b0726a3d2d74e332f Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Thu, 20 Jun 2024 10:15:15 +0200 Subject: [PATCH 12/17] Change as desired by TheR1D, in order to keep the code base consistent. (Note: if SHELL_INTERACTION contains an unintended / weird value, it will act as if it contained false, which is not the intended default behaviour) --- sgpt/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sgpt/app.py b/sgpt/app.py index e58a907a..733b7ce4 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -57,7 +57,7 @@ def main( rich_help_panel="Assistance Options", ), interaction: bool = typer.Option( - True if cfg.get("SHELL_INTERACTION") != "false" else False, + cfg.get("SHELL_INTERACTION") == "true", help="Interactive mode for --shell option.", rich_help_panel="Assistance Options", ), From fdff2c056ee1f71e422f336a72600f8438def0e5 Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Thu, 20 Jun 2024 10:26:08 +0200 Subject: [PATCH 13/17] doc changes: renamed env vars + OS_NAME =$(uname -s) in order for it to work on Mac too --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3ff2a0b8..f9a9594d 100644 --- a/README.md +++ b/README.md @@ -465,18 +465,21 @@ When using a container, please note: * The \[E\]xecute option for --shell with interaction will not work, since it would try this Execute in the docker container. => setting the `SHELL_INTERACTION` environment variable to false , makes sense. * Since, most likely the os and shell of your container are not identical to the environment you want help with: -set the environment variables `OVERWRITE_OS_NAME` and `OVERWRITE_SHELL_NAME` according to your setup. +set the environment variables `OS_NAME ` and `SHELL_NAME ` according to your setup. Example of a conversation, using an alias and the `OPENAI_API_KEY` environment variable: ```shell -alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OVERWRITE_OS_NAME=$(grep -oP '^PRETTY_NAME="\K[^"]+' /etc/os-release) --env OVERWRITE_SHELL_NAME=$(echo $SHELL) ghcr.io/ther1d/shell_gpt" +alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OS_NAME =$(uname -s) --env SHELL_NAME =$(echo $SHELL) ghcr.io/ther1d/shell_gpt" export OPENAI_API_KEY="your OPENAI API key" sgpt --chat rainbow "what are the colors of a rainbow" sgpt --chat rainbow "inverse the list of your last answer" sgpt --chat rainbow "translate your last answer in french" ``` +Note: if you're on Linux, in order to get a more detailed os name, you could use: +--env OS_NAME =$(grep -oP '^PRETTY_NAME="\K[^"]+' /etc/os-release) + You also can use the provided `Dockerfile` to build your own image: ```shell docker build -t sgpt . @@ -488,7 +491,7 @@ Example environment variables for a working Ollama setup, using Docker: * ENV USE_LITELLM=true * ENV OPENAI_API_KEY=bad_key * ENV SHELL_INTERACTION=false -* ENV OVERWRITE_OS_NAME="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" -* ENV OVERWRITE_SHELL_NAME=/bin/bash +* ENV OS_NAME ="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" +* ENV SHELL_NAME =/bin/bash Additional documentation: [Azure integration](https://github.com/TheR1D/shell_gpt/wiki/Azure), [Ollama integration](https://github.com/TheR1D/shell_gpt/wiki/Ollama). From 00da9de09a8e97aeb90ba0cc3649dff1a4daff3a Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Thu, 20 Jun 2024 12:50:46 +0200 Subject: [PATCH 14/17] Fixed accidental spaces + update Readme with useful suggestion instead of linux command --- Dockerfile | 4 ++-- README.md | 13 ++++++------- sgpt/config.py | 4 ++-- sgpt/role.py | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9acc1570..a92fccce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM python:3-slim ENV SHELL_INTERACTION=false -ENV OS_NAME =auto -ENV SHELL_NAME =auto +ENV OS_NAME=auto +ENV SHELL_NAME=auto WORKDIR /app COPY . /app diff --git a/README.md b/README.md index 3885187f..34eaad42 100644 --- a/README.md +++ b/README.md @@ -465,20 +465,19 @@ When using a container, please note: * The \[E\]xecute option for --shell with interaction will not work, since it would try this Execute in the docker container. => setting the `SHELL_INTERACTION` environment variable to false , makes sense. * Since, most likely the os and shell of your container are not identical to the environment you want help with: -set the environment variables `OS_NAME ` and `SHELL_NAME ` according to your setup. +set the environment variables `OS_NAME` and `SHELL_NAME` according to your setup. Example of a conversation, using an alias and the `OPENAI_API_KEY` environment variable: ```shell -alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OS_NAME =$(uname -s) --env SHELL_NAME =$(echo $SHELL) ghcr.io/ther1d/shell_gpt" +alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OS_NAME=$(uname -s) --env SHELL_NAME=$(echo $SHELL) ghcr.io/ther1d/shell_gpt" export OPENAI_API_KEY="your OPENAI API key" sgpt --chat rainbow "what are the colors of a rainbow" sgpt --chat rainbow "inverse the list of your last answer" sgpt --chat rainbow "translate your last answer in french" ``` - -Note: if you're on Linux, in order to get a more detailed os name, you could use: ---env OS_NAME =$(grep -oP '^PRETTY_NAME="\K[^"]+' /etc/os-release) +Note: +Consider filling in a more specific OS_NAME instead of using $(uname -s) You also can use the provided `Dockerfile` to build your own image: ```shell @@ -491,7 +490,7 @@ Example environment variables for a working Ollama setup, using Docker: * ENV USE_LITELLM=true * ENV OPENAI_API_KEY=bad_key * ENV SHELL_INTERACTION=false -* ENV OS_NAME ="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" -* ENV SHELL_NAME =/bin/bash +* ENV OS_NAME="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" +* ENV SHELL_NAME=/bin/bash Additional documentation: [Azure integration](https://github.com/TheR1D/shell_gpt/wiki/Azure), [Ollama integration](https://github.com/TheR1D/shell_gpt/wiki/Ollama). diff --git a/sgpt/config.py b/sgpt/config.py index dd979e06..82a078af 100644 --- a/sgpt/config.py +++ b/sgpt/config.py @@ -35,8 +35,8 @@ "PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"), "USE_LITELLM": os.getenv("USE_LITELLM", "false"), "SHELL_INTERACTION ": os.getenv("SHELL_INTERACTION ", "true"), - "OS_NAME ": os.getenv("OS_NAME ", "auto"), - "SHELL_NAME ": os.getenv("SHELL_NAME ", "auto"), + "OS_NAME": os.getenv("OS_NAME", "auto"), + "SHELL_NAME ": os.getenv("SHELL_NAME", "auto"), # New features might add their own config variables here. } diff --git a/sgpt/role.py b/sgpt/role.py index 2e841aaf..2ae34e1d 100644 --- a/sgpt/role.py +++ b/sgpt/role.py @@ -113,8 +113,8 @@ def get_role_name(cls, initial_message: str) -> Optional[str]: @classmethod def _os_name(cls) -> str: - if cfg.get("OS_NAME ") != "auto": - return cfg.get("OS_NAME ") + if cfg.get("OS_NAME") != "auto": + return cfg.get("OS_NAME") current_platform = platform.system() if current_platform == "Linux": return "Linux/" + distro_name(pretty=True) @@ -126,8 +126,8 @@ def _os_name(cls) -> str: @classmethod def _shell_name(cls) -> str: - if cfg.get("SHELL_NAME ") != "auto": - return cfg.get("SHELL_NAME ") + if cfg.get("SHELL_NAME") != "auto": + return cfg.get("SHELL_NAME") current_platform = platform.system() if current_platform in ("Windows", "nt"): is_powershell = len(getenv("PSModulePath", "").split(pathsep)) >= 3 From cfaa71b59fa44943c7a11a6d97189cea08794d9f Mon Sep 17 00:00:00 2001 From: Robin Boone <43806560+Robinsane@users.noreply.github.com> Date: Fri, 21 Jun 2024 09:12:54 +0200 Subject: [PATCH 15/17] Update README.md suggestion TheR1D Co-authored-by: Farkhod Sadykov --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 34eaad42..9fa3ac36 100644 --- a/README.md +++ b/README.md @@ -470,7 +470,7 @@ set the environment variables `OS_NAME` and `SHELL_NAME` according to your setup Example of a conversation, using an alias and the `OPENAI_API_KEY` environment variable: ```shell -alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OS_NAME=$(uname -s) --env SHELL_NAME=$(echo $SHELL) ghcr.io/ther1d/shell_gpt" +alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OPENAI_API_KEY --env OS_NAME=$(uname -s) --env SHELL_NAME=$(echo $SHELL) ghcr.io/ther1d/shell_gpt" export OPENAI_API_KEY="your OPENAI API key" sgpt --chat rainbow "what are the colors of a rainbow" sgpt --chat rainbow "inverse the list of your last answer" From d3b36d66b090973969ee19bbb7b173ad665c997f Mon Sep 17 00:00:00 2001 From: Robin Boone <43806560+Robinsane@users.noreply.github.com> Date: Fri, 21 Jun 2024 09:13:43 +0200 Subject: [PATCH 16/17] Dockerfile env var ENV PRETTIFY_MARKDOWN=false Co-authored-by: Farkhod Sadykov --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index a92fccce..2dc99b78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM python:3-slim ENV SHELL_INTERACTION=false +ENV PRETTIFY_MARKDOWN=false ENV OS_NAME=auto ENV SHELL_NAME=auto From 6d213fd3ff5de3d3fa20eb43374817d60393e2c7 Mon Sep 17 00:00:00 2001 From: Robin Boone Date: Fri, 21 Jun 2024 09:35:44 +0200 Subject: [PATCH 17/17] Clear explanation of what to do when you want to use Ollama for LLM requests in combination with ShellGPT in a docker container --- README.md | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9fa3ac36..59f45fe4 100644 --- a/README.md +++ b/README.md @@ -484,13 +484,35 @@ You also can use the provided `Dockerfile` to build your own image: docker build -t sgpt . ``` -Example environment variables for a working Ollama setup, using Docker: -* ENV DEFAULT_MODEL=ollama/mistral:7b-instruct-v0.2-q4_K_M -* ENV API_BASE_URL=http://10.10.10.10:11434 -* ENV USE_LITELLM=true -* ENV OPENAI_API_KEY=bad_key -* ENV SHELL_INTERACTION=false -* ENV OS_NAME="Linux/Red Hat Enterprise Linux 8.8 (Ootpa)" -* ENV SHELL_NAME=/bin/bash - -Additional documentation: [Azure integration](https://github.com/TheR1D/shell_gpt/wiki/Azure), [Ollama integration](https://github.com/TheR1D/shell_gpt/wiki/Ollama). +### Docker + Ollama + +If you want to send your requests to an Ollama instance and run ShellGPT inside a Docker container, you need to adjust the Dockerfile and build the container yourself: the litellm package is needed and env variables need to be set correctly. + +Example Dockerfile: +``` +FROM python:3-slim + +ENV DEFAULT_MODEL=ollama/mistral:7b-instruct-v0.2-q4_K_M +ENV API_BASE_URL=http://10.10.10.10:11434 +ENV USE_LITELLM=true +ENV OPENAI_API_KEY=bad_key +ENV SHELL_INTERACTION=false +ENV PRETTIFY_MARKDOWN=false +ENV OS_NAME="Red Hat Enterprise Linux 8.6 (Ootpa)" +ENV SHELL_NAME=auto + +WORKDIR /app +COPY . /app + +RUN apt-get update && apt-get install -y gcc +RUN pip install --no-cache /app[litellm] && mkdir -p /tmp/shell_gpt + +VOLUME /tmp/shell_gpt + +ENTRYPOINT ["sgpt"] +``` + + +## Additional documentation +* [Azure integration](https://github.com/TheR1D/shell_gpt/wiki/Azure) +* [Ollama integration](https://github.com/TheR1D/shell_gpt/wiki/Ollama)