11 cfg = config.services.chatgpt-retrieval-plugin;
14 options.services.chatgpt-retrieval-plugin = {
15 enable = mkEnableOption "chatgpt-retrieval-plugin service";
20 description = "Port the chatgpt-retrieval-plugin service listens on.";
25 default = "127.0.0.1";
27 description = "The hostname or IP address for chatgpt-retrieval-plugin to bind to.";
30 bearerTokenPath = mkOption {
33 Path to the secret bearer token used for the http api authentication.
36 example = "config.age.secrets.CHATGPT_RETRIEVAL_PLUGIN_BEARER_TOKEN.path";
39 openaiApiKeyPath = mkOption {
42 Path to the secret openai api key used for embeddings.
45 example = "config.age.secrets.CHATGPT_RETRIEVAL_PLUGIN_OPENAI_API_KEY.path";
48 datastore = mkOption {
58 description = "This specifies the vector database provider you want to use to store and query embeddings.";
61 qdrantCollection = mkOption {
64 name of the qdrant collection used to store documents.
66 default = "document_chunks";
70 config = mkIf cfg.enable {
74 assertion = cfg.bearerTokenPath != "";
75 message = "services.chatgpt-retrieval-plugin.bearerTokenPath should not be an empty string.";
78 assertion = cfg.openaiApiKeyPath != "";
79 message = "services.chatgpt-retrieval-plugin.openaiApiKeyPath should not be an empty string.";
83 systemd.services.chatgpt-retrieval-plugin = {
84 description = "ChatGPT Retrieval Plugin";
85 after = [ "network.target" ];
86 wantedBy = [ "multi-user.target" ];
92 "BEARER_TOKEN:${cfg.bearerTokenPath}"
93 "OPENAI_API_KEY:${cfg.openaiApiKeyPath}"
95 StateDirectory = "chatgpt-retrieval-plugin";
96 StateDirectoryMode = "0755";
99 # it doesn't make sense to pass secrets as env vars, this is a hack until
100 # upstream has proper secret management.
102 export BEARER_TOKEN=$(${pkgs.systemd}/bin/systemd-creds cat BEARER_TOKEN)
103 export OPENAI_API_KEY=$(${pkgs.systemd}/bin/systemd-creds cat OPENAI_API_KEY)
104 exec ${pkgs.chatgpt-retrieval-plugin}/bin/start --host ${cfg.host} --port ${toString cfg.port}
108 DATASTORE = cfg.datastore;
109 QDRANT_COLLECTION = mkIf (cfg.datastore == "qdrant") cfg.qdrantCollection;
113 systemd.tmpfiles.rules = [
114 # create the directory for static files for fastapi
115 "C /var/lib/chatgpt-retrieval-plugin/.well-known - - - - ${pkgs.chatgpt-retrieval-plugin}/${pkgs.python3Packages.python.sitePackages}/.well-known"