mirror of
https://github.com/fumiama/deepinfra.git
synced 2026-06-12 05:50:27 +08:00
feat(chat): add api Modelize
This commit is contained in:
15
chat/chat.go
15
chat/chat.go
@@ -89,3 +89,18 @@ func (l *Log) Modelize(p model.Protocol, grp int64, sysp string) deepinfra.Model
|
|||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modelize into any type from index and message
|
||||||
|
func Modelize[T any](l *Log, grp int64, f func(int, string) T) []T {
|
||||||
|
l.mu.RLock()
|
||||||
|
defer l.mu.RUnlock()
|
||||||
|
sz := len(l.m[grp])
|
||||||
|
if sz == 0 {
|
||||||
|
return []T{f(0, l.defaultprompt)}
|
||||||
|
}
|
||||||
|
t := make([]T, sz)
|
||||||
|
for i, msg := range l.m[grp] {
|
||||||
|
t[i] = f(i, msg.String())
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user