mirror of
https://github.com/mudler/LocalAI.git
synced 2024-06-07 19:40:48 +00:00
6559ac11b1
* feat(ui): allow to set system prompt for chat Make also the models in the index clickable, and display as table Fixes #2257 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(vision): support also png with base64 input Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): support vision and upload of files Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * display the processed image Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * make trust remote code stand out Signed-off-by: mudler <mudler@localai.io> * feat(ui): track in progress job across index/model gallery Signed-off-by: mudler <mudler@localai.io> * minor fixups Signed-off-by: mudler <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Signed-off-by: mudler <mudler@localai.io>
84 lines
1.3 KiB
Go
84 lines
1.3 KiB
Go
package xsync
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type SyncedMap[K comparable, V any] struct {
|
|
mu sync.RWMutex
|
|
m map[K]V
|
|
}
|
|
|
|
func NewSyncedMap[K comparable, V any]() *SyncedMap[K, V] {
|
|
return &SyncedMap[K, V]{
|
|
m: make(map[K]V),
|
|
}
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Map() map[K]V {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
return m.m
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Get(key K) V {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
return m.m[key]
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Keys() []K {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
keys := make([]K, 0, len(m.m))
|
|
for k := range m.m {
|
|
keys = append(keys, k)
|
|
}
|
|
return keys
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Values() []V {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
values := make([]V, 0, len(m.m))
|
|
for _, v := range m.m {
|
|
values = append(values, v)
|
|
}
|
|
return values
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Len() int {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
return len(m.m)
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Iterate(f func(key K, value V) bool) {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
for k, v := range m.m {
|
|
if !f(k, v) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Set(key K, value V) {
|
|
m.mu.Lock()
|
|
m.m[key] = value
|
|
m.mu.Unlock()
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Delete(key K) {
|
|
m.mu.Lock()
|
|
delete(m.m, key)
|
|
m.mu.Unlock()
|
|
}
|
|
|
|
func (m *SyncedMap[K, V]) Exists(key K) bool {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
_, ok := m.m[key]
|
|
return ok
|
|
}
|