-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An implementation of LangChain in Haskell -- -- Please see README.md for examples and usage. @package typechain @version 0.1.1.0 module DotEnv -- | A DotEnv is a HashMap of ByteString keys and values type DotEnv = HashMap ByteString ByteString -- | An EnvPath is either a path to a .env file or the default .env file data EnvPath EnvPath :: FilePath -> EnvPath DefaultEnv :: EnvPath -- | Load a DotEnv from an EnvPath loadEnv :: EnvPath -> IO DotEnv -- | Get a value from a DotEnv -- -- Format: key=value getEnv :: DotEnv -> ByteString -> Maybe ByteString module TypeChain.ChatModels.Types type TypeChain model = StateT model IO type TypeChainT = StateT type ApiKey = ByteString -- | Way of distinguising who said what in a conversation data Role User :: Role Assistant :: Role System :: Role -- | A message with a role and content (lenses role and -- content) data Message Message :: Role -> String -> Message [_role] :: Message -> Role [_content] :: Message -> String role :: Lens' Message Role content :: Lens' Message String -- | Pattern synonym for creating a Message with User -- role pattern UserMessage :: String -> Message -- | Pattern synonym for creating a Message with -- Assistant role pattern AssistantMessage :: String -> Message -- | Pattern synonym for creating a Message with System -- role pattern SystemMessage :: String -> Message -- | Helper typeclass to allow for multiple types to be passed to the -- ChatModel functions. -- -- NOTE: If this is used with the OverloadedStrings extension, -- you will need type annotations when using the String -- instance. class MsgList a -- | Convert to a list of messages toMsgList :: MsgList a => a -> [Message] -- | A class for Chat Models In order to achieve compatibility with as many -- different kinds of LLMS as possible, the predict function is -- constrained to MonadIO so that it has the capability to either make an -- API call, run a local model, or any other action that may require IO. -- -- Computations with a ChatModel are expected to be run in a -- StateT monad (see TypeChain and TypeChainT -- for specific types) so that the model can be updated with new messages -- and the output messages can be logged. -- -- Functions that operate in a context where multiple models are -- available (e.g. predicts and addMsgsTo) use lenses -- to allow extraction and modification of the model without knowing the -- specific state type. -- -- Exmaple: If working with two models, you can use (model1, -- model2) as the state type and pass the _1 and -- _2 lenses to predicts and addMsgsTo to -- specify which model to use in the function. class ChatModel a -- | Predict for current and only model This function should prompt the -- model (either via API or locally), and return the response. -- -- NOTE: If a model has the capability to remember previous messages, it -- should implement RememberingChatModel and automatically -- manage this functionality in the predict function. predict :: (ChatModel a, MonadIO m, MonadThrow m, MsgList msg) => msg -> TypeChainT a m [Message] -- | Predict for a specific model via lens This function should prompt the -- model (either via API or locally), log the input messages, log the -- output messages, and return the output messages. -- -- NOTE: If a model has the capability to remember previous messages, it -- should implement RememberingChatModel and automatically -- manage this functionality in the predicts function. predicts :: (ChatModel a, MonadIO m, MonadThrow m, MsgList msg) => Lens' s a -> msg -> TypeChainT s m [Message] class ChatModel a => RememberingChatModel a -- | Enable/Disable memory for current and only model setMemoryEnabled :: (RememberingChatModel a, Monad m) => Bool -> TypeChainT a m () -- | Enable/Disable memory for specific model setMemoryEnabledFor :: (RememberingChatModel a, Monad m) => Lens' s a -> Bool -> TypeChainT s m () -- | Remove all remembered messages for the current and only model. This -- does not affect a model's ability to remember future messages. forget :: (RememberingChatModel a, Monad m) => TypeChainT a m () -- | Remove all remebered messages for a specific model. This does not -- affect a model's ability to remember future messages. forgetFor :: (RememberingChatModel a, Monad m) => Lens' s a -> TypeChainT s m () -- | Remember a list of messages for the current and only model. This does -- not affect a model's ability to remember future messages and should -- respect the current memory setting. memorize :: (RememberingChatModel a, Monad m) => [Message] -> TypeChainT a m () -- | Remember a list of messages for a specific model. This does not affect -- a model's ability to remember future messages and should respect the -- current memory setting. memorizes :: (RememberingChatModel a, Monad m) => Lens' s a -> [Message] -> TypeChainT s m () -- | Retrieve all remembered messages for the current and only model. This -- does not forget any messages nor affect a model's ability to remember -- future messages. remember :: (RememberingChatModel a, Monad m) => TypeChainT a m [Message] -- | Retrieve all remembered messages for a specific model. This does not -- forget any messages nor affect a model's ability to remember future -- messages. rememberFor :: (RememberingChatModel a, Monad m) => Lens' s a -> TypeChainT s m [Message] instance TypeChain.ChatModels.Types.MsgList GHC.Base.String instance TypeChain.ChatModels.Types.MsgList TypeChain.ChatModels.Types.Message instance TypeChain.ChatModels.Types.MsgList [TypeChain.ChatModels.Types.Message] instance Data.Aeson.Types.ToJSON.ToJSON TypeChain.ChatModels.Types.Role instance Data.Aeson.Types.FromJSON.FromJSON TypeChain.ChatModels.Types.Role instance Data.Aeson.Types.ToJSON.ToJSON TypeChain.ChatModels.Types.Message instance Data.Aeson.Types.FromJSON.FromJSON TypeChain.ChatModels.Types.Message instance GHC.Generics.Generic TypeChain.ChatModels.Types.Message instance GHC.Show.Show TypeChain.ChatModels.Types.Message instance GHC.Show.Show TypeChain.ChatModels.Types.Role module TypeChain.ChatModels.PromptTemplate makeTemplate :: [Q PromptTemplate] -> Q Exp user :: String -> Q PromptTemplate assistant :: String -> Q PromptTemplate system :: String -> Q PromptTemplate instance GHC.Classes.Eq TypeChain.ChatModels.PromptTemplate.TemplateToken module TypeChain.ChatModels.OpenAI data OpenAIChat OpenAIChat :: OpenAIChatModel -> Maybe [Message] -> Float -> ApiKey -> OpenAIChat [chatModel] :: OpenAIChat -> OpenAIChatModel -- | Nothing = Do not remember messages [messages] :: OpenAIChat -> Maybe [Message] [temperature] :: OpenAIChat -> Float [apiKey] :: OpenAIChat -> ApiKey data OpenAIChatModel GPT35Turbo :: OpenAIChatModel GPT4 :: OpenAIChatModel GPT4Turbo :: OpenAIChatModel -- | Create an OpenAI chat model with default values -- -- Model: GPT-3.5-Turbo -- -- Memorization: Enabled -- -- Temperature: 0.7 -- -- ApiKey: value initOpenAIChat :: OpenAIChat instance GHC.Generics.Generic TypeChain.ChatModels.OpenAI.OpenAIChat instance GHC.Generics.Generic TypeChain.ChatModels.OpenAI.Choices instance GHC.Generics.Generic TypeChain.ChatModels.OpenAI.OpenAIResponse instance Data.Aeson.Types.FromJSON.FromJSON TypeChain.ChatModels.OpenAI.OpenAIResponse instance TypeChain.ChatModels.Types.ChatModel TypeChain.ChatModels.OpenAI.OpenAIChat instance Data.Aeson.Types.FromJSON.FromJSON TypeChain.ChatModels.OpenAI.Choices instance Data.Aeson.Types.ToJSON.ToJSON TypeChain.ChatModels.OpenAI.OpenAIChat instance TypeChain.ChatModels.Types.RememberingChatModel TypeChain.ChatModels.OpenAI.OpenAIChat instance GHC.Show.Show TypeChain.ChatModels.OpenAI.OpenAIChatModel instance Data.Aeson.Types.ToJSON.ToJSON TypeChain.ChatModels.OpenAI.OpenAIChatModel module TypeChain.ChatModels