1 Star 0 Fork 0

Survivor_zzc / langchaingo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
buffer_options.go 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
Survivor_zzc 提交于 2023-10-24 17:21 . package name
package memory
import "gitee.com/zzcadmin/langchaingo/schema"
// ConversationBufferOption is a function for creating new buffer
// with other then the default values.
type ConversationBufferOption func(b *ConversationBuffer)
// WithChatHistory is an option for providing the chat history store.
func WithChatHistory(chatHistory schema.ChatMessageHistory) ConversationBufferOption {
return func(b *ConversationBuffer) {
b.ChatHistory = chatHistory
}
}
// WithReturnMessages is an option for specifying should it return messages.
func WithReturnMessages(returnMessages bool) ConversationBufferOption {
return func(b *ConversationBuffer) {
b.ReturnMessages = returnMessages
}
}
// WithInputKey is an option for specifying the input key.
func WithInputKey(inputKey string) ConversationBufferOption {
return func(b *ConversationBuffer) {
b.InputKey = inputKey
}
}
// WithOutputKey is an option for specifying the output key.
func WithOutputKey(outputKey string) ConversationBufferOption {
return func(b *ConversationBuffer) {
b.OutputKey = outputKey
}
}
// WithHumanPrefix is an option for specifying the human prefix.
func WithHumanPrefix(humanPrefix string) ConversationBufferOption {
return func(b *ConversationBuffer) {
b.HumanPrefix = humanPrefix
}
}
// WithAIPrefix is an option for specifying the AI prefix.
func WithAIPrefix(aiPrefix string) ConversationBufferOption {
return func(b *ConversationBuffer) {
b.AIPrefix = aiPrefix
}
}
// WithMemoryKey is an option for specifying the memory key.
func WithMemoryKey(memoryKey string) ConversationBufferOption {
return func(b *ConversationBuffer) {
b.MemoryKey = memoryKey
}
}
func applyBufferOptions(opts ...ConversationBufferOption) *ConversationBuffer {
m := &ConversationBuffer{
ReturnMessages: false,
InputKey: "",
OutputKey: "",
HumanPrefix: "Human",
AIPrefix: "AI",
MemoryKey: "history",
}
for _, opt := range opts {
opt(m)
}
if m.ChatHistory == nil {
m.ChatHistory = NewChatMessageHistory()
}
return m
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zzcadmin/langchaingo.git
git@gitee.com:zzcadmin/langchaingo.git
zzcadmin
langchaingo
langchaingo
v0.4.7

搜索帮助

344bd9b3 5694891 D2dac590 5694891