From 689ef459357da82d1f2ce15f5ca338ee272df098 Mon Sep 17 00:00:00 2001 From: "Lennart J. Kurzweg (Nx2)" Date: Wed, 4 Sep 2024 17:08:09 +0200 Subject: [PATCH] ooo --- home-modules/ollama.nix | 37 +++++++++++++++++++++++++++++++++++++ home.nix | 1 + 2 files changed, 38 insertions(+) create mode 100644 home-modules/ollama.nix diff --git a/home-modules/ollama.nix b/home-modules/ollama.nix new file mode 100644 index 0000000..d9dc5fa --- /dev/null +++ b/home-modules/ollama.nix @@ -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 ") + 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) +'') + ]; +} + diff --git a/home.nix b/home.nix index de2f250..881177c 100755 --- a/home.nix +++ b/home.nix @@ -29,6 +29,7 @@ ./home-modules/nx-gcal-event.nix ./home-modules/obs.nix ./home-modules/office.nix + ./home-modules/ollama.nix ./home-modules/pandoc.nix ./home-modules/pnx.nix ./home-modules/programming/c.nix