-
-
Notifications
You must be signed in to change notification settings - Fork 623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompts: Add Save and FromFile functions to serialize/deserialize prompts to disk #193
Conversation
…m-disk' of https://github.com/cduggn/langchaingo into chains-Add-save-function-to-serialise-chains-to-and-from-disk
…p output to disk, and also to read from disk. Supports YAML and JSON formats
…m-disk' of https://github.com/cduggn/langchaingo into chains-Add-save-function-to-serialise-chains-to-and-from-disk
…tial path issues when supplying the string path argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should be in the business of wrapping serialization like this -- Go has great yaml and json support and folks may want their own formats and encodings.
Unless the langchain community comes up with some langchain-specific types of encoding I'm not sure it's worth it for us to wrap serialization in this manner.
Go encourages programming to the io.Reader and io.Writer interfaces which keeps code agnostic to underlying transport or storage concerns and I think we should embrace that and not address these concerns in this codebase.
load/filesystem.go
Outdated
NormalizeSuffix(path string) string | ||
} | ||
|
||
type LocalFileSystem struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm skepitcal we need this abstraction, the go stdlib has plenty of good filesystem io primitives and if anything adding this will constrain users of this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough, I was looking at this myopically, considering load package only. I'll revert the filesystem abstraction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmc I've removed the io package abstraction. There is a minimum set of prompt types supported with this PR, which doesn't include chatprompttemplate . It has a more complex interface structure. It's probably not suitable to leave an unimplemented function in the code . I can close the PR if this is not desirable
func (p ChatPromptTemplate) Save(path string) error {
_ = path
return ErrNotImplemented
}
…ains-to-and-from-disk
going to close this for now and revisit with a more succint commit history |
PR Checklist
memory: add interfaces for X, Y
orutil: add whizzbang helpers
).Fixes #123
).golangci-lint
checks.Description
This PR adds the ability to serialize and deserialize (some) prompt templates to and from disk. This is useful for sharing, storing, and versioning prompts. It supports JSON and YAML formats.
prompt.FormatPrompter
interface was updated to include aSave
functionThe prompt types supported in this initial PR include the following with conditions.
PromptTemplate
: supports Save and creation FromFileHumanMessagePromptTemplate
: supports Save and creation FromFileSystemMessagePromptTemplate
: supports Save and creation FromFileGenericMessagePromptTemplate
: not used explicitly however it does implement the MessageFormatter interface and as such it was necessary to provide an implementation of SaveAIMessagePromptTemplate
: same as GenericMessagePromptTemplate this is not called explicitly however due to its contract with the MessageFormatter interface I have also provided an implementation of SaveExisting Implementation
Serialization for prompt templates is available in the upstream Python version of the library in the following packages: