1 { config, pkgs, lib, ... }:
6 cfg = config.services.chatgpt-retrieval-plugin;
9 options.services.chatgpt-retrieval-plugin = {
10 enable = mkEnableOption "chatgpt-retrieval-plugin service";
15 description = "Port the chatgpt-retrieval-plugin service listens on.";
20 default = "127.0.0.1";
22 description = "The hostname or IP address for chatgpt-retrieval-plugin to bind to.";
25 bearerTokenPath = mkOption {
28 Path to the secret bearer token used for the http api authentication.
31 example = "config.age.secrets.CHATGPT_RETRIEVAL_PLUGIN_BEARER_TOKEN.path";
34 openaiApiKeyPath = mkOption {
37 Path to the secret openai api key used for embeddings.
40 example = "config.age.secrets.CHATGPT_RETRIEVAL_PLUGIN_OPENAI_API_KEY.path";
43 datastore = mkOption {
44 type = types.enum [ "pinecone" "weaviate" "zilliz" "milvus" "qdrant" "redis" ];
46 description = "This specifies the vector database provider you want to use to store and query embeddings.";
49 qdrantCollection = mkOption {
52 name of the qdrant collection used to store documents.
54 default = "document_chunks";
58 config = mkIf cfg.enable {
62 assertion = cfg.bearerTokenPath != "";
63 message = "services.chatgpt-retrieval-plugin.bearerTokenPath should not be an empty string.";
66 assertion = cfg.openaiApiKeyPath != "";
67 message = "services.chatgpt-retrieval-plugin.openaiApiKeyPath should not be an empty string.";
71 systemd.services.chatgpt-retrieval-plugin = {
72 description = "ChatGPT Retrieval Plugin";
73 after = [ "network.target" ];
74 wantedBy = [ "multi-user.target" ];
80 "BEARER_TOKEN:${cfg.bearerTokenPath}"
81 "OPENAI_API_KEY:${cfg.openaiApiKeyPath}"
83 StateDirectory = "chatgpt-retrieval-plugin";
84 StateDirectoryMode = "0755";
87 # it doesn't make sense to pass secrets as env vars, this is a hack until
88 # upstream has proper secret management.
90 export BEARER_TOKEN=$(${pkgs.systemd}/bin/systemd-creds cat BEARER_TOKEN)
91 export OPENAI_API_KEY=$(${pkgs.systemd}/bin/systemd-creds cat OPENAI_API_KEY)
92 exec ${pkgs.chatgpt-retrieval-plugin}/bin/start --host ${cfg.host} --port ${toString cfg.port}
96 DATASTORE = cfg.datastore;
97 QDRANT_COLLECTION = mkIf (cfg.datastore == "qdrant") cfg.qdrantCollection;
101 systemd.tmpfiles.rules = [
102 # create the directory for static files for fastapi
103 "C /var/lib/chatgpt-retrieval-plugin/.well-known - - - - ${pkgs.chatgpt-retrieval-plugin}/${pkgs.python3Packages.python.sitePackages}/.well-known"