A-gent-0.11.0.8: src/Internal/LLM.hs
{-# OPTIONS_GHC -Wall -Werror #-}
{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}
{-# LANGUAGE Safe #-}
--------------------------------------------------------------------------------
-- |
-- Copyright : (c) 2026 SPISE MISU ApS
-- License : SSPL-1.0 OR AGPL-3.0-only
-- Maintainer : SPISE MISU <mail+hackage@spisemisu.com>
-- Stability : experimental
--------------------------------------------------------------------------------
module Internal.LLM
( Exit (..)
, Root (..)
, Filter (..)
, Mode (..)
, View (..)
, Chit (..)
, Chat
, History (..)
, Mask (..)
, File (..)
, FileLine
, Files (..)
, Document (..)
, Template (..)
, modes
, tpl2xml
)
where
--------------------------------------------------------------------------------
newtype Exit = Exit Bool
newtype Root = Root FilePath
newtype Filter = Filter String
data Mode
= Auto
| Chat
| Code
| Docs
| Echo
| Plan
| Test
deriving (Bounded, Enum, Eq, Read, Show)
data View
= Chits
| Chats
data Chit =
Chit
{ prev :: ![String]
, next :: ![String]
}
type Chat = [String]
data History =
History
{ view :: ![View]
, chit :: !Chit
, chat :: !Chat
}
--------------------------------------------------------------------------------
newtype Mask = Mask [String]
--------------------------------------------------------------------------------
type Markdown = String
type FileLine = String
newtype File = File { file :: (FilePath, [FileLine]) }
newtype Files = Files { files :: [FilePath] }
newtype Document = Document { document :: File }
data Template =
Template
{ purpose :: !String
, instructions :: ![String]
, examples :: ![Markdown]
, documents :: ![Document]
}
--------------------------------------------------------------------------------
modes :: [Mode]
modes =
[ minBound .. maxBound ]
tpl2xml
:: Template
-> String
tpl2xml tpl =
( if eis && ees && eds then
pur
else
"<purpose>" ++ pur ++ "</purpose>"
) ++
( if eis then
[]
else
"<instructions>" ++
tis ++
"</instructions>"
) ++
( if ees then
[]
else
"<examples>" ++
tes ++
"</examples>"
) ++
( if eds then
[]
else
"<documents>" ++
concatMap aux tds ++
"</documents>"
)
where
pur =
purpose tpl ++
( if eis then
[]
else
". Follow the specififed `instructions`"
) ++
( if ees then
[]
else
". Output MUST match provided `examples`"
) ++
( if ees then
[]
else
". List of provided `documents`"
)
eis = null tis
ees = null tes
eds = null tds
tis =
concatMap (\ x -> "<instruction>" ++ x ++ "</instruction>")
$ instructions tpl
tes =
concatMap (\ x -> "<example>" ++ x ++ "</example>")
$ examples tpl
tds = zip [0 :: Int ..] $ documents tpl
aux (i, Document (File (src, ls))) =
"<document index=\"" ++ show i ++ "\">" ++
"<source>" ++ src ++ "</source>" ++
"<content>" ++ unlines ls ++ "</content>" ++
"</document>"