From 8c12c6830b37851cccb3fea75faa820fce49284a Mon Sep 17 00:00:00 2001 From: Javier Martinez Date: Tue, 24 Sep 2024 08:30:58 +0200 Subject: [PATCH 1/3] fix: docker permissions (#2059) * fix: missing depends_on * chore: update copy permissions * chore: update entrypoint * Revert "chore: update entrypoint" This reverts commit f73a36af2f3b8b385f99a84d0eb020899f3e0e80. * Revert "chore: update copy permissions" This reverts commit fabc3f66bba9bd066a3f67bcaf5f9bfb5f6e031b. * style: fix docker warning * fix: multiples fixes * fix: user permissions writing local_data folder --- Dockerfile.llamacpp-cpu | 6 +++--- Dockerfile.ollama | 6 +++--- docker-compose.yaml | 12 ++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Dockerfile.llamacpp-cpu b/Dockerfile.llamacpp-cpu index fce9915..feab165 100644 --- a/Dockerfile.llamacpp-cpu +++ b/Dockerfile.llamacpp-cpu @@ -1,6 +1,6 @@ ### IMPORTANT, THIS IMAGE CAN ONLY BE RUN IN LINUX DOCKER ### You will run into a segfault in mac -FROM python:3.11.6-slim-bookworm as base +FROM python:3.11.6-slim-bookworm AS base # Install poetry RUN pip install pipx @@ -20,14 +20,14 @@ RUN apt update && apt install -y \ # https://python-poetry.org/docs/configuration/#virtualenvsin-project ENV POETRY_VIRTUALENVS_IN_PROJECT=true -FROM base as dependencies +FROM base AS dependencies WORKDIR /home/worker/app COPY pyproject.toml poetry.lock ./ ARG POETRY_EXTRAS="ui embeddings-huggingface llms-llama-cpp vector-stores-qdrant" RUN poetry install --no-root --extras "${POETRY_EXTRAS}" -FROM base as app +FROM base AS app ENV PYTHONUNBUFFERED=1 ENV PORT=8080 diff --git a/Dockerfile.ollama b/Dockerfile.ollama index 5a8b73a..83fd129 100644 --- a/Dockerfile.ollama +++ b/Dockerfile.ollama @@ -1,4 +1,4 @@ -FROM python:3.11.6-slim-bookworm as base +FROM python:3.11.6-slim-bookworm AS base # Install poetry RUN pip install pipx @@ -10,14 +10,14 @@ ENV PATH=".venv/bin/:$PATH" # https://python-poetry.org/docs/configuration/#virtualenvsin-project ENV POETRY_VIRTUALENVS_IN_PROJECT=true -FROM base as dependencies +FROM base AS dependencies WORKDIR /home/worker/app COPY pyproject.toml poetry.lock ./ ARG POETRY_EXTRAS="ui vector-stores-qdrant llms-ollama embeddings-ollama" RUN poetry install --no-root --extras "${POETRY_EXTRAS}" -FROM base as app +FROM base AS app ENV PYTHONUNBUFFERED=1 ENV PORT=8080 ENV APP_ENV=prod diff --git a/docker-compose.yaml b/docker-compose.yaml index c2ef0f6..2d6dff2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,11 +8,12 @@ services: # This service builds from an external Dockerfile and runs the Ollama mode. private-gpt-ollama: image: ${PGPT_IMAGE:-zylonai/private-gpt}:${PGPT_TAG:-0.6.2}-ollama # x-release-please-version + user: root build: context: . dockerfile: Dockerfile.ollama volumes: - - ./local_data/:/home/worker/app/local_data + - ./local_data:/home/worker/app/local_data ports: - "8001:8001" environment: @@ -27,11 +28,14 @@ services: - ollama-cpu - ollama-cuda - ollama-api + depends_on: + - ollama # Private-GPT service for the local mode # This service builds from a local Dockerfile and runs the application in local mode. private-gpt-llamacpp-cpu: image: ${PGPT_IMAGE:-zylonai/private-gpt}:${PGPT_TAG:-0.6.2}-llamacpp-cpu # x-release-please-version + user: root build: context: . dockerfile: Dockerfile.llamacpp-cpu @@ -44,7 +48,7 @@ services: environment: PORT: 8001 PGPT_PROFILES: local - HF_TOKEN: ${HF_TOKEN} + HF_TOKEN: ${HF_TOKEN:-} profiles: - llamacpp-cpu @@ -57,7 +61,7 @@ services: ollama: image: traefik:v2.10 ports: - - "8081:8080" + - "11434:11434" command: - "--providers.file.filename=/etc/router.yml" - "--log.level=ERROR" @@ -98,4 +102,4 @@ services: count: 1 capabilities: [gpu] profiles: - - ollama-cuda \ No newline at end of file + - ollama-cuda From f9182b3a86d88af7c699b41b3a5f21401117acfc Mon Sep 17 00:00:00 2001 From: Liam Dowd <101684827+itsliamdowd@users.noreply.github.com> Date: Tue, 24 Sep 2024 07:31:30 +0100 Subject: [PATCH 2/3] feat: Adding MistralAI mode (#2065) * Adding MistralAI mode * Update embedding_component.py * Update ui.py * Update settings.py * Update embedding_component.py * Update settings.py * Update settings.py * Update settings-mistral.yaml * Update llm_component.py * Update settings-mistral.yaml * Update settings.py * Update settings.py * Update ui.py * Update embedding_component.py * Delete settings-mistral.yaml --------- Co-authored-by: SkiingIsFun123 <101684827+SkiingIsFun123@users.noreply.github.com> Co-authored-by: Javier Martinez --- poetry.lock | 50 ++++++++++++++++++- .../embedding/embedding_component.py | 17 +++++++ private_gpt/settings/settings.py | 9 +++- pyproject.toml | 2 + 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 8310e1e..25e0bbd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2238,6 +2238,17 @@ files = [ {file = "joblib-1.4.2.tar.gz", hash = "sha256:2382c5816b2636fbd20a09e0f4e9dad4736765fdfb7dca582943b9c1366b3f0e"}, ] +[[package]] +name = "jsonpath-python" +version = "1.0.6" +description = "A more powerful JSONPath implementation in modern python" +optional = true +python-versions = ">=3.6" +files = [ + {file = "jsonpath-python-1.0.6.tar.gz", hash = "sha256:dd5be4a72d8a2995c3f583cf82bf3cd1a9544cfdabf2d22595b67aff07349666"}, + {file = "jsonpath_python-1.0.6-py3-none-any.whl", hash = "sha256:1e3b78df579f5efc23565293612decee04214609208a2335884b3ee3f786b575"}, +] + [[package]] name = "kiwisolver" version = "1.4.5" @@ -2481,6 +2492,21 @@ huggingface-hub = {version = ">=0.19.0", extras = ["inference"]} llama-index-core = ">=0.10.1,<0.11.0" sentence-transformers = ">=2.6.1" +[[package]] +name = "llama-index-embeddings-mistralai" +version = "0.1.6" +description = "llama-index embeddings mistralai integration" +optional = true +python-versions = "<4.0,>=3.9" +files = [ + {file = "llama_index_embeddings_mistralai-0.1.6-py3-none-any.whl", hash = "sha256:d69d6fc0be8a1772aaf890bc036f2d575af46070b375a2649803c0eb9736ea1b"}, + {file = "llama_index_embeddings_mistralai-0.1.6.tar.gz", hash = "sha256:7c9cbf974b1e7d14ded34d3eb749a0d1a379fb151ab75115cc1ffdd08a96a045"}, +] + +[package.dependencies] +llama-index-core = ">=0.10.1,<0.11.0" +mistralai = ">=1.0.0" + [[package]] name = "llama-index-embeddings-ollama" version = "0.1.2" @@ -3002,6 +3028,27 @@ files = [ {file = "minijinja-2.0.1.tar.gz", hash = "sha256:e774beffebfb8a1ad17e638ef70917cf5e94593f79acb8a8fff7d983169f3a4e"}, ] +[[package]] +name = "mistralai" +version = "1.0.3" +description = "Python Client SDK for the Mistral AI API." +optional = true +python-versions = "<4.0,>=3.8" +files = [ + {file = "mistralai-1.0.3-py3-none-any.whl", hash = "sha256:64af7c9192e64dc66b2da6d1c4d54a1324a881c21665a2f93d6b35d9de9f87c8"}, + {file = "mistralai-1.0.3.tar.gz", hash = "sha256:84f1a217666c76fec9d477ae266399b813c3ac32a4a348d2ecd5fe1c039b0667"}, +] + +[package.dependencies] +httpx = ">=0.27.0,<0.28.0" +jsonpath-python = ">=1.0.6,<2.0.0" +pydantic = ">=2.8.2,<2.9.0" +python-dateutil = ">=2.9.0.post0,<3.0.0" +typing-inspect = ">=0.9.0,<0.10.0" + +[package.extras] +gcp = ["google-auth (==2.27.0)", "requests (>=2.32.3,<3.0.0)"] + [[package]] name = "mmh3" version = "4.1.0" @@ -6692,6 +6739,7 @@ cffi = ["cffi (>=1.11)"] embeddings-azopenai = ["llama-index-embeddings-azure-openai"] embeddings-gemini = ["llama-index-embeddings-gemini"] embeddings-huggingface = ["einops", "llama-index-embeddings-huggingface"] +embeddings-mistral = ["llama-index-embeddings-mistralai"] embeddings-ollama = ["llama-index-embeddings-ollama", "ollama"] embeddings-openai = ["llama-index-embeddings-openai"] embeddings-sagemaker = ["boto3"] @@ -6714,4 +6762,4 @@ vector-stores-qdrant = ["llama-index-vector-stores-qdrant"] [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.12" -content-hash = "45264d80672084e35ca0ea11b368a29001a3b9003822bddc67fb18489a8fe519" +content-hash = "3fa6ef447847895b1a16b8b0422dd9e4fda1aaaadef3af71971eb412da89bf67" diff --git a/private_gpt/components/embedding/embedding_component.py b/private_gpt/components/embedding/embedding_component.py index 5d3e997..b55cef8 100644 --- a/private_gpt/components/embedding/embedding_component.py +++ b/private_gpt/components/embedding/embedding_component.py @@ -144,6 +144,23 @@ class EmbeddingComponent: api_key=settings.gemini.api_key, model_name=settings.gemini.embedding_model, ) + case "mistralai": + try: + from llama_index.embeddings.mistralai import ( # type: ignore + MistralAIEmbedding, + ) + except ImportError as e: + raise ImportError( + "Mistral dependencies not found, install with `poetry install --extras embeddings-mistral`" + ) from e + + api_key = settings.openai.api_key + model = settings.openai.embedding_model + + self.embedding_model = MistralAIEmbedding( + api_key=api_key, + model=model, + ) case "mock": # Not a random number, is the dimensionality used by # the default embedding model diff --git a/private_gpt/settings/settings.py b/private_gpt/settings/settings.py index 4cf192a..9b4238d 100644 --- a/private_gpt/settings/settings.py +++ b/private_gpt/settings/settings.py @@ -197,7 +197,14 @@ class HuggingFaceSettings(BaseModel): class EmbeddingSettings(BaseModel): mode: Literal[ - "huggingface", "openai", "azopenai", "sagemaker", "ollama", "mock", "gemini" + "huggingface", + "openai", + "azopenai", + "sagemaker", + "ollama", + "mock", + "gemini", + "mistralai", ] ingest_mode: Literal["simple", "batch", "parallel", "pipeline"] = Field( "simple", diff --git a/pyproject.toml b/pyproject.toml index da9fab8..afbb83c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ llama-index-embeddings-huggingface = {version ="^0.2.2", optional = true} llama-index-embeddings-openai = {version ="^0.1.10", optional = true} llama-index-embeddings-azure-openai = {version ="^0.1.10", optional = true} llama-index-embeddings-gemini = {version ="^0.1.8", optional = true} +llama-index-embeddings-mistralai = {version ="^0.1.6", optional = true} llama-index-vector-stores-qdrant = {version ="^0.2.10", optional = true} llama-index-vector-stores-milvus = {version ="^0.1.20", optional = true} llama-index-vector-stores-chroma = {version ="^0.1.10", optional = true} @@ -83,6 +84,7 @@ embeddings-openai = ["llama-index-embeddings-openai"] embeddings-sagemaker = ["boto3"] embeddings-azopenai = ["llama-index-embeddings-azure-openai"] embeddings-gemini = ["llama-index-embeddings-gemini"] +embeddings-mistral = ["llama-index-embeddings-mistralai"] vector-stores-qdrant = ["llama-index-vector-stores-qdrant"] vector-stores-clickhouse = ["llama-index-vector-stores-clickhouse", "clickhouse_connect"] vector-stores-chroma = ["llama-index-vector-stores-chroma"] From fa3c30661d2ab04634361e20e7819365e3dd351a Mon Sep 17 00:00:00 2001 From: J Date: Tue, 24 Sep 2024 02:33:02 -0400 Subject: [PATCH 3/3] fix: Add default mode option to settings (#2078) * Add default mode option to settings * Revise default_mode to Literal (enum) and add to settings.yaml * Revise to pass make check/test * Default mode: RAG --------- Co-authored-by: Jason --- private_gpt/settings/settings.py | 4 ++++ private_gpt/ui/ui.py | 9 ++++++--- settings.yaml | 14 ++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/private_gpt/settings/settings.py b/private_gpt/settings/settings.py index 9b4238d..abe5662 100644 --- a/private_gpt/settings/settings.py +++ b/private_gpt/settings/settings.py @@ -357,6 +357,10 @@ class AzureOpenAISettings(BaseModel): class UISettings(BaseModel): enabled: bool path: str + default_mode: Literal["RAG", "Search", "Basic", "Summarize"] = Field( + "RAG", + description="The default mode.", + ) default_chat_system_prompt: str = Field( None, description="The default system prompt to use for the chat mode.", diff --git a/private_gpt/ui/ui.py b/private_gpt/ui/ui.py index 2c1dcd3..04258ac 100644 --- a/private_gpt/ui/ui.py +++ b/private_gpt/ui/ui.py @@ -99,8 +99,11 @@ class PrivateGptUi: self._selected_filename = None # Initialize system prompt based on default mode - self.mode = MODES[0] - self._system_prompt = self._get_default_system_prompt(self.mode) + default_mode_map = {mode.value: mode for mode in Modes} + self._default_mode = default_mode_map.get( + settings().ui.default_mode, Modes.RAG_MODE + ) + self._system_prompt = self._get_default_system_prompt(self._default_mode) def _chat( self, message: str, history: list[list[str]], mode: Modes, *_: Any @@ -390,7 +393,7 @@ class PrivateGptUi: with gr.Row(equal_height=False): with gr.Column(scale=3): - default_mode = MODES[0] + default_mode = self._default_mode mode = gr.Radio( [mode.value for mode in MODES], label="Mode", diff --git a/settings.yaml b/settings.yaml index f030604..eda1af8 100644 --- a/settings.yaml +++ b/settings.yaml @@ -25,21 +25,23 @@ data: ui: enabled: true path: / + # "RAG", "Search", "Basic", or "Summarize" + default_mode: "RAG" default_chat_system_prompt: > - You are a helpful, respectful and honest assistant. + You are a helpful, respectful and honest assistant. Always answer as helpfully as possible and follow ALL given instructions. Do not speculate or make up information. Do not reference any given instructions or context. default_query_system_prompt: > - You can only answer questions about the provided context. - If you know the answer but it is not based in the provided context, don't provide + You can only answer questions about the provided context. + If you know the answer but it is not based in the provided context, don't provide the answer, just state the answer is not in the context provided. default_summarization_system_prompt: > - Provide a comprehensive summary of the provided context information. + Provide a comprehensive summary of the provided context information. The summary should cover all the key points and main ideas presented in - the original text, while also condensing the information into a concise + the original text, while also condensing the information into a concise and easy-to-understand format. Please ensure that the summary includes - relevant details and examples that support the main ideas, while avoiding + relevant details and examples that support the main ideas, while avoiding any unnecessary information or repetition. delete_file_button_enabled: true delete_all_files_button_enabled: true