Unverified Commit 6af2210e authored by Yt's avatar Yt Committed by GitHub
Browse files

{chatgpt-retrieval-plugin,nixos/chatgpt-retrieval-plugin}: drop (#447045)

parents 7a011a37 feff0029
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -176,6 +176,8 @@

- `programs.goldwarden` has been removed, due to the software not working with newer versions of the Bitwarden and Vaultwarden servers, as well as it being abandoned upstream.

- The `chatgpt-retrieval-plugin` package and `services.chatgpt-retrieval-plugin` module were removed due to the package having been broken since at least November 2024.

- The `cardboard` package and `programs.cardboard` module were removed due to the package having been broken since at least November 2024.

- The default `kops` version is now 1.33.0 and versions 1.30 and older have been dropped. See [Upgrading Kubernetes](https://kops.sigs.k8s.io/tutorial/upgrading-kubernetes/) for instructions on how to update kOps.
+0 −1
Original line number Diff line number Diff line
@@ -1552,7 +1552,6 @@
  ./services/web-apps/calibre-web.nix
  ./services/web-apps/castopod.nix
  ./services/web-apps/changedetection-io.nix
  ./services/web-apps/chatgpt-retrieval-plugin.nix
  ./services/web-apps/chhoto-url.nix
  ./services/web-apps/cloudlog.nix
  ./services/web-apps/code-server.nix
+4 −0
Original line number Diff line number Diff line
@@ -113,6 +113,10 @@ in
      "cgmanager"
      "enable"
    ] "cgmanager was deprecated by lxc and therefore removed from nixpkgs.")
    (mkRemovedOptionModule [
      "services"
      "chatgpt-retrieval-plugin"
    ] "The corresponding package was removed from nixpkgs.")
    (mkRemovedOptionModule [
      "services"
      "chronos"
+0 −118
Original line number Diff line number Diff line
{
  config,
  pkgs,
  lib,
  ...
}:

with lib;

let
  cfg = config.services.chatgpt-retrieval-plugin;
in
{
  options.services.chatgpt-retrieval-plugin = {
    enable = mkEnableOption "chatgpt-retrieval-plugin service";

    port = mkOption {
      type = types.port;
      default = 8080;
      description = "Port the chatgpt-retrieval-plugin service listens on.";
    };

    host = mkOption {
      type = types.str;
      default = "127.0.0.1";
      example = "0.0.0.0";
      description = "The hostname or IP address for chatgpt-retrieval-plugin to bind to.";
    };

    bearerTokenPath = mkOption {
      type = types.path;
      description = ''
        Path to the secret bearer token used for the http api authentication.
      '';
      default = "";
      example = "config.age.secrets.CHATGPT_RETRIEVAL_PLUGIN_BEARER_TOKEN.path";
    };

    openaiApiKeyPath = mkOption {
      type = types.path;
      description = ''
        Path to the secret openai api key used for embeddings.
      '';
      default = "";
      example = "config.age.secrets.CHATGPT_RETRIEVAL_PLUGIN_OPENAI_API_KEY.path";
    };

    datastore = mkOption {
      type = types.enum [
        "pinecone"
        "weaviate"
        "zilliz"
        "milvus"
        "qdrant"
        "redis"
      ];
      default = "qdrant";
      description = "This specifies the vector database provider you want to use to store and query embeddings.";
    };

    qdrantCollection = mkOption {
      type = types.str;
      description = ''
        name of the qdrant collection used to store documents.
      '';
      default = "document_chunks";
    };
  };

  config = mkIf cfg.enable {

    assertions = [
      {
        assertion = cfg.bearerTokenPath != "";
        message = "services.chatgpt-retrieval-plugin.bearerTokenPath should not be an empty string.";
      }
      {
        assertion = cfg.openaiApiKeyPath != "";
        message = "services.chatgpt-retrieval-plugin.openaiApiKeyPath should not be an empty string.";
      }
    ];

    systemd.services.chatgpt-retrieval-plugin = {
      description = "ChatGPT Retrieval Plugin";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        DynamicUser = true;
        Restart = "always";
        LoadCredential = [
          "BEARER_TOKEN:${cfg.bearerTokenPath}"
          "OPENAI_API_KEY:${cfg.openaiApiKeyPath}"
        ];
        StateDirectory = "chatgpt-retrieval-plugin";
        StateDirectoryMode = "0755";
      };

      # it doesn't make sense to pass secrets as env vars, this is a hack until
      # upstream has proper secret management.
      script = ''
        export BEARER_TOKEN=$(${pkgs.systemd}/bin/systemd-creds cat BEARER_TOKEN)
        export OPENAI_API_KEY=$(${pkgs.systemd}/bin/systemd-creds cat OPENAI_API_KEY)
        exec ${pkgs.chatgpt-retrieval-plugin}/bin/start --host ${cfg.host} --port ${toString cfg.port}
      '';

      environment = {
        DATASTORE = cfg.datastore;
        QDRANT_COLLECTION = mkIf (cfg.datastore == "qdrant") cfg.qdrantCollection;
      };
    };

    systemd.tmpfiles.rules = [
      # create the directory for static files for fastapi
      "C /var/lib/chatgpt-retrieval-plugin/.well-known - - - - ${pkgs.chatgpt-retrieval-plugin}/${pkgs.python3Packages.python.sitePackages}/.well-known"
    ];
  };
}
+0 −73
Original line number Diff line number Diff line
{
  lib,
  python3Packages,
  fetchFromGitHub,
  python3,
  nix-update-script,
  dasel,
}:

python3Packages.buildPythonApplication {
  pname = "chatgpt-retrieval-plugin";
  version = "0-unstable-2023-03-28";
  format = "pyproject";

  src = fetchFromGitHub {
    owner = "openai";
    repo = "chatgpt-retrieval-plugin";
    rev = "958bb787bf34823538482a9eb3157c5bf994a182";
    hash = "sha256-fCNGzK5Uji6wGDTEwAf4FF/i+RC7ny3v4AsvQwIbehY=";
  };

  postPatch = ''
    substituteInPlace pyproject.toml \
      --replace 'fastapi = "^0.92.0"' 'fastapi = ">=0.92.0"' \
      --replace 'python-dotenv = "^0.21.1"' 'python-dotenv = "*"' \
      --replace 'python-multipart = "^0.0.6"' 'python-multipart = "^0.0.5"' \
      --replace 'redis = "4.5.1"' 'redis = "^4.5.1"' \
      --replace 'tiktoken = "^0.2.0"' 'tiktoken = "^0.3.0"' \
      --replace 'packages = [{include = "server"}]' 'packages = [{include = "server"}, {include = "models"}, {include = "datastore"}, {include = "services"}]'

    substituteInPlace server/main.py \
      --replace 'directory=".well-known"' 'directory="/var/lib/chatgpt-retrieval-plugin/.well-known"' \
      --replace '0.0.0.0' '127.0.0.1' \
      --replace '8000' '8080'

    ${dasel}/bin/dasel put -t string -f pyproject.toml -v '.well-known/*' '.tool.poetry.include.[]'
  '';

  nativeBuildInputs = with python3Packages; [
    poetry-core
  ];

  propagatedBuildInputs = with python3.pkgs; [
    fastapi
    arrow
    tiktoken
    python-multipart
    python-dotenv
    openai
    weaviate-client
    pinecone-client
    pymilvus
    uvicorn
    python-pptx
    tenacity
    pypdf2
    qdrant-client
    redis
    docx2txt
  ];

  passthru = {
    updateScript = nix-update-script { };
  };

  meta = with lib; {
    broken = true; # dependencies are not up to date, the project doesn't look well maintained, this doesn't look like it's going in the right direction. I'm happy to handle maintainership to whoever wants to.
    homepage = "https://github.com/openai/chatgpt-retrieval-plugin";
    description = "Tool to search and find personal or work documents by asking questions in everyday language";
    license = licenses.mit;
    maintainers = with maintainers; [ happysalada ];
  };
}
Loading