From bf0f65bcaa638a5dacf7366d4f2357bb0e47a0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 29 Mar 2025 21:24:48 +0900 Subject: [PATCH] feat(chat): add api Modelize --- chat/chat.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/chat/chat.go b/chat/chat.go index c6785ad..aafb128 100644 --- a/chat/chat.go +++ b/chat/chat.go @@ -89,3 +89,18 @@ func (l *Log) Modelize(p model.Protocol, grp int64, sysp string) deepinfra.Model } 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 +}