mirror of
https://github.com/fumiama/deepinfra.git
synced 2026-06-12 14:06:35 +08:00
feat(model): add item pre/post modelize hook
This commit is contained in:
13
chat/chat.go
13
chat/chat.go
@@ -14,6 +14,7 @@ type Log[T fmt.Stringer] struct {
|
||||
itemsep string
|
||||
defaultprompt string
|
||||
m map[int64][]*batch[T]
|
||||
preM, postM func(*T)
|
||||
}
|
||||
|
||||
func NewLog[T fmt.Stringer](batchcap, itemscap int, itemsep, defaultprompt string) Log[T] {
|
||||
@@ -35,6 +36,18 @@ func NewLog[T fmt.Stringer](batchcap, itemscap int, itemsep, defaultprompt strin
|
||||
}
|
||||
}
|
||||
|
||||
// SetPreModelize will be called before calling item.String()
|
||||
func (l *Log[T]) SetPreModelize(fn func(*T)) *Log[T] {
|
||||
l.preM = fn
|
||||
return l
|
||||
}
|
||||
|
||||
// SetPreModelize will be called after calling item.String()
|
||||
func (l *Log[T]) SetPostModelize(fn func(*T)) *Log[T] {
|
||||
l.postM = fn
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *Log[T]) Add(grp int64, item T, isbot bool) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user