typechain-0.2.0.0: An implementation of LangChain in Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

TypeChain.ChatModels.PromptTemplate

Synopsis

Documentation

class ToPrompt a where Source #

Typeclass used to convert generated record types into a list of messages.

Instances of this typeclass are generated by the makeTemplate function and should only be used if you need to construct a prompt manually.

Methods

toPrompt :: a -> [Message] Source #

Return the list of messages that should be used as the prompt.

makeTemplate :: String -> [Q PromptTemplate] -> Q [Dec] Source #

Given a typename and a list of messages, generate a data type and a function to construct it.

Example: `makeTemplate Translate [system "translate {a} to {b}.", user "{text}"]`

This generates a record named Translate with fields a, b, and text. It also generates a function mkTranslate :: String -> String -> String -> [Message]. To allow for quick and easy construction of the prompt if needed. Otherwise, you can use the generated data type in conjunction with the toPrompt function to be more explicit.

See the example on the repo's README.md for an example of what the generated code looks like.

user :: String -> Q PromptTemplate Source #

Convert a String into a compile prompt template for the makeTemplate function.

This particular function is for user messages.

assistant :: String -> Q PromptTemplate Source #

Convert a String into a compile prompt template for the makeTemplate function.

This particular function is for assistant messages.

system :: String -> Q PromptTemplate Source #

Convert a String into a compile prompt template for the makeTemplate function.

This particular function is for system messages.