-
Notifications
You must be signed in to change notification settings - Fork 1
/
providers.go
97 lines (83 loc) · 2.44 KB
/
providers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package coord
import (
"sort"
"sync"
"github.com/lemon-mint/coord/provider"
)
var (
llmProvidersMu sync.RWMutex
llmProviders = make(map[string]provider.LLMProvider)
ttsProvidersMu sync.RWMutex
ttsProviders = make(map[string]provider.TTSProvider)
embeddingProvidersMu sync.RWMutex
embeddingProviders = make(map[string]provider.EmbeddingProvider)
)
// ListLLMProviders returns the names of the registered llm providers.
func ListLLMProviders() []string {
llmProvidersMu.RLock()
defer llmProvidersMu.RUnlock()
list := make([]string, 0, len(llmProviders))
for name := range llmProviders {
list = append(list, name)
}
sort.Strings(list)
return list
}
// RegisterLLMProvider registers a llm provider.
func RegisterLLMProvider(name string, p provider.LLMProvider) {
llmProvidersMu.Lock()
defer llmProvidersMu.Unlock()
llmProviders[name] = p
}
// RemoveLLMProvider removes a llm provider.
func RemoveLLMProvider(name string) {
llmProvidersMu.Lock()
defer llmProvidersMu.Unlock()
delete(llmProviders, name)
}
// ListTTSProviders returns the names of the registered tts providers.
func ListTTSProviders() []string {
ttsProvidersMu.RLock()
defer ttsProvidersMu.RUnlock()
list := make([]string, 0, len(ttsProviders))
for name := range ttsProviders {
list = append(list, name)
}
sort.Strings(list)
return list
}
// RegisterTTSProvider registers a tts provider.
func RegisterTTSProvider(name string, p provider.TTSProvider) {
ttsProvidersMu.Lock()
defer ttsProvidersMu.Unlock()
ttsProviders[name] = p
}
// RemoveTTSProvider removes a tts provider.
func RemoveTTSProvider(name string) {
ttsProvidersMu.Lock()
defer ttsProvidersMu.Unlock()
delete(ttsProviders, name)
}
// ListEmbeddingProviders returns the names of the registered embedding providers.
func ListEmbeddingProviders() []string {
embeddingProvidersMu.RLock()
defer embeddingProvidersMu.RUnlock()
list := make([]string, 0, len(embeddingProviders))
for name := range embeddingProviders {
list = append(list, name)
}
sort.Strings(list)
return list
}
// RegisterEmbeddingProvider registers an embedding provider.
func RegisterEmbeddingProvider(name string, p provider.EmbeddingProvider) {
embeddingProvidersMu.Lock()
defer embeddingProvidersMu.Unlock()
embeddingProviders[name] = p
}
// RemoveEmbeddingProvider removes an embedding provider.
func RemoveEmbeddingProvider(name string) {
embeddingProvidersMu.Lock()
defer embeddingProvidersMu.Unlock()
delete(embeddingProviders, name)
}