This commit is contained in:
Lennart J. Kurzweg (Nx2)
2024-09-04 17:08:09 +02:00
parent 2492c5bd80
commit 689ef45935
2 changed files with 38 additions and 0 deletions

37
home-modules/ollama.nix Normal file
View File

@@ -0,0 +1,37 @@
{ pkgs, ... }:
{
home.packages = with pkgs; [
(writers.writePython3Bin "ooo" {
libraries = [ pkgs.python3Packages.ollama ];
flakeIgnore = [ "E501" "E305" "E701" "E704" "E302" "E114" "F841" "E121" ];
} /* python */ ''
import sys
import ollama
if len(sys.argv) < 2:
print("Usage: ./ooo.py <system_message>")
sys.exit(1)
system_message = sys.argv[1]
input_text = sys.stdin.read()
try:
response = ollama.chat(model='llama3.1:8b', messages=[
{
'role': 'system',
'content': "You are a text transformer. Follow the folling instruction:\n\n" + system_message + "\n\nOnly output the transformed text. Do not add any addidional conversation around the output. Just the result.",
},
{
'role': 'user',
'content': input_text,
},
])
print(response['message']['content'])
sys.exit(0)
except Exception as e:
print(f"An error occurred: {e}", file=sys.stderr)
sys.exit(1)
'')
];
}