From 6fe1818ec9591ce0754986698512be95feefde5f Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Wed, 12 Apr 2023 09:36:43 -0400 Subject: [PATCH] first test Signed-off-by: Xe Iaso --- flake.lock | 75 +++++++++++++++++++++++++++- flake.nix | 48 +++++++++++++++--- index.ts | 11 +++- citations.bib => paper/citations.bib | 0 types/plottoriffic.d.ts | 24 +++++++++ 5 files changed, 148 insertions(+), 10 deletions(-) rename citations.bib => paper/citations.bib (100%) create mode 100644 types/plottoriffic.d.ts diff --git a/flake.lock b/flake.lock index 2d0dcb2..8261923 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,40 @@ { "nodes": { + "iosevka": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1679684486, + "narHash": "sha256-XMpeeKmzxYpkh8uuxyGHcYzgORVysC8vMIVbzQdPtTs=", + "owner": "Xe", + "repo": "iosevka", + "rev": "85a6850cf67884b2d4752442bb9246415681e9e9", + "type": "github" + }, + "original": { + "owner": "Xe", + "repo": "iosevka", + "type": "github" + } + }, "nixpkgs": { + "locked": { + "lastModified": 1678898370, + "narHash": "sha256-xTICr1j+uat5hk9FyuPOFGxpWHdJRibwZC+ATi0RbtE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ac718d02867a84b42522a0ece52d841188208f2c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1681217261, "narHash": "sha256-RbxCHWN3Vhyv/WEsXcJlDwF7bpvZ9NxDjfSouQxXEKo=", @@ -17,8 +51,10 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "utils": "utils" + "iosevka": "iosevka", + "nixpkgs": "nixpkgs_2", + "typst": "typst", + "utils": "utils_2" } }, "systems": { @@ -36,7 +72,42 @@ "type": "github" } }, + "typst": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1681296471, + "narHash": "sha256-437YmGedi3S8GT7WOQTgruQEl/+QqB/8mOuGpJphjYg=", + "owner": "typst", + "repo": "typst", + "rev": "1198e0cd385737efc38dbd8ba13db802a68e0dc7", + "type": "github" + }, + "original": { + "owner": "typst", + "repo": "typst", + "type": "github" + } + }, "utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "utils_2": { "inputs": { "systems": "systems" }, diff --git a/flake.nix b/flake.nix index 52abde6..b08f1b6 100644 --- a/flake.nix +++ b/flake.nix @@ -2,17 +2,51 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; utils.url = "github:numtide/flake-utils"; + + # Explicitly pulling from that version of nixpkgs to avoid font duplication. + iosevka.url = "github:Xe/iosevka"; + + typst.url = "github:typst/typst"; + typst.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, utils }: + outputs = { self, nixpkgs, utils, typst, iosevka }: utils.lib.eachDefaultSystem (system: - let pkgs = nixpkgs.legacyPackages.${system}; in - { + let + pkgs = import nixpkgs { + inherit system; + overlays = [ typst.overlays.default ]; + }; + typstWithIosevka = let + fontsConf = pkgs.symlinkJoin { + name = "typst-fonts"; + paths = + [ "${self.packages.${system}.iosevka}" ]; + }; + in pkgs.writeShellApplication { + name = "typst"; + text = '' + ${pkgs.typst-dev}/bin/typst \ + --font-path ${fontsConf} \ + "$@" + ''; + runtimeInputs = [ ]; + }; + in { + packages.iosevka = pkgs.stdenvNoCC.mkDerivation { + name = "iosevka-iaso-ttf"; + buildInputs = with pkgs; [ unzip ]; + dontUnpack = true; + buildPhase = '' + unzip ${self.inputs.iosevka.packages.${system}.default}/ttf.zip + ''; + installPhase = '' + mkdir -p $out + cp ttf/* $out + ''; + }; devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - nodejs-18_x - pandoc - ]; + buildInputs = with pkgs; [ nodejs-18_x pandoc typstWithIosevka ]; shellHook = '' export PATH="$PATH":$(pwd)/node_modules/.bin ''; diff --git a/index.ts b/index.ts index f724d82..fa3b886 100644 --- a/index.ts +++ b/index.ts @@ -1,8 +1,12 @@ import * as dotenv from "dotenv"; import { Configuration, OpenAIApi } from "openai"; +import PlotGenerator from "@xeserv/plottoriffic"; dotenv.config(); +const pg = new PlotGenerator({}); +const plot = pg.generate(); + const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); @@ -10,6 +14,11 @@ const openai = new OpenAIApi(configuration); const completion = await openai.createChatCompletion({ model: "gpt-3.5-turbo", - messages: [{ role: "user", content: "Hello world" }], + messages: [ + { + role: "user", + content: "Write me a plot summary for the following story:\n\n" + plot.plot, + }, + ], }); console.log(completion.data.choices[0].message); diff --git a/citations.bib b/paper/citations.bib similarity index 100% rename from citations.bib rename to paper/citations.bib diff --git a/types/plottoriffic.d.ts b/types/plottoriffic.d.ts new file mode 100644 index 0000000..9469364 --- /dev/null +++ b/types/plottoriffic.d.ts @@ -0,0 +1,24 @@ +declare module "@xeserv/plottoriffic" { + export default PlotGenerator; + + export type Character = { + symbol: string; + name: string; + description: string; + }; + + export type Plot = { + subject: string; + group: string; + subgroup: string; + description: string; + cast: Character[]; + plot: string; + }; + + export class PlotGenerator { + constructor({ flipGenders }: { flipGenders?: boolean }); + + generate(): Plot; + } +}