96 lines
3.3 KiB
Nix

{
pkgs,
lib,
optimizeWithFlags,
...
}:
let
models = [
{
name = "DeepSeek-R1-Distill-Qwen-7B-Q6_K.gguf";
context_length = 32768;
gen_length = 8192;
source = pkgs.fetchurl {
url = "https://huggingface.co/bartowski/DeepSeek-R1-Distill-Qwen-7B-GGUF/resolve/main/DeepSeek-R1-Distill-Qwen-7B-Q6_K.gguf?download=true";
sha256 = "3ffa00e72db05668453687d5ab8e7c9fb19705cfd57292a956db17a3633c93f3";
};
}
];
gpt4all_package = (
optimizeWithFlags
(pkgs.gpt4all.overrideAttrs (old: {
patches = old.patches ++ [
./disable-settings-err.patch
./disable-version-check.patch
];
}))
# compile flags
[
"-O3"
"-ffast-math"
"-march=native"
"-mtune=native"
"-fno-finite-math-only" # https://github.com/ggerganov/llama.cpp/pull/7154#issuecomment-2143844461
]
);
in
{
home.packages = [
gpt4all_package
];
home.file =
lib.recursiveUpdate
{
".config/nomic.ai/GPT4All.ini".text =
let
system_prompt = "You are an expert LLM who works step-by-step from first principles to derive an answer to the user's prompt. For each step, title the step and begin showing your work, then decide if your work is comprehensive and if you're ready to provide your final answer. Make sure to exhaust ALL POSSIBILITIES before answering. INTERNAL REASONING STEPS ARE NOT SHOWN TO THE USER, ONLY A \"Final Answer\" SECTION WILL BE SHOWN TO THE USER. USE AS MANY REASONING STEPS AS POSSIBLE. EXPLORE ALTERNATE ANSWERS AND CONSIDER THAT YOUR ANSWER OR ANY ASSUMPTIONS MAY BE WRONG. IDENTIFY POSSIBLE ERRORS IN YOUR REASONING AND WHERE SUCH ERRORS MAY BE. FULLY TEST ALL OTHER POSSIBILITIES. YOU CAN BE WRONG. SHOW YOUR WORK WHEN RE-EXAMINING. FULLY COMPLETE THE PROBLEM BEFORE FINALIZING YOUR ANSWER, DO NOT LEAVE PLACEHOLDER INFORMATION IN YOUR ANSWER.";
in
''
[General]
chatTheme=Dark
height=940
suggestionMode=Off
threadCount=8
uniqueId=7096f2d2-448d-4272-a132-d37e77f8a781
userDefaultModel=${
# select the first element of `models` to be the default model
(builtins.elemAt models 0).name
}
width=1472
x=0
y=0
[download]
lastVersionStarted=${gpt4all_package.version}
''
+ (lib.concatStrings (
map (model: ''
[model-${model.name}]
contextLength=${builtins.toString model.context_length}
filename=${model.name}
maxLength=${builtins.toString model.gen_length}
promptBatchSize=256
systemMessage="${
# replace newlines with the string "\n" for gpt4all to properly parse
builtins.replaceStrings [ "\n" ] [ "\\n" ] system_prompt
}\n"
'') models
))
+ ''
[network]
isActive=true
usageStatsActive=true
'';
}
(
builtins.listToAttrs (
map (f: {
name = ".local/share/nomic.ai/GPT4All/${f.name}";
value.source = f.source;
}) models
)
);
}