-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcapability.go
More file actions
106 lines (94 loc) · 2.36 KB
/
capability.go
File metadata and controls
106 lines (94 loc) · 2.36 KB
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
98
99
100
101
102
103
104
105
106
package llmspecs
import (
"fmt"
"strings"
)
// Capability represents a model's features or modalities using bitmasks.
type Capability uint64
const (
// Modalities (0-15 bit)
ModalityTextIn Capability = 1 << iota
ModalityTextOut
ModalityImageIn
ModalityImageOut
ModalityAudioIn
ModalityAudioOut
ModalityVideoIn
ModalityVideoOut
ModalityFileIn
ModalityFileOut
)
const (
// Features (16-31 bit)
CapFunctionCall Capability = 1 << (16 + iota)
CapJsonMode
CapSystemPrompt
// Types (32-47 bit)
CapChat Capability = 1 << (32 + iota)
CapEmbedding
CapRerank
CapTTS
CapASR
CapMultimodal
)
// 建立一个内部映射表,用于快速匹配字符串
// 建议按位序排列,这样生成的字符串切片也是有序的
var capabilityNames = []struct {
mask Capability
name string
}{
{ModalityTextIn, "TextIn"},
{ModalityTextOut, "TextOut"},
{ModalityImageIn, "ImageIn"},
{ModalityImageOut, "ImageOut"},
{ModalityAudioIn, "AudioIn"},
{ModalityAudioOut, "AudioOut"},
{ModalityVideoIn, "VideoIn"},
{ModalityVideoOut, "VideoOut"},
{ModalityFileIn, "FileIn"},
{ModalityFileOut, "FileOut"},
{CapFunctionCall, "FunctionCall"},
{CapJsonMode, "JsonMode"},
{CapSystemPrompt, "SystemPrompt"},
{CapChat, "Chat"},
{CapEmbedding, "Embedding"},
{CapRerank, "Rerank"},
{CapTTS, "TTS"},
{CapASR, "ASR"},
{CapMultimodal, "Multimodal"},
}
// Has checks if the capability set contains the given capability.
func (c Capability) Has(other Capability) bool {
return c&other != 0
}
// ToStrings 将当前的位掩码组合分解为字符串切片
func (c Capability) ToStrings() []string {
if c == 0 {
return []string{}
}
var names []string
for _, entry := range capabilityNames {
if c.Has(entry.mask) {
names = append(names, entry.name)
}
}
// 研发细节:处理可能存在的未定义位(版本兼容性考虑)
// 如果有些位在 capabilityNames 里没定义,但 c 里面有,可以记录为 Unknown
definedMask := Capability(0)
for _, entry := range capabilityNames {
definedMask |= entry.mask
}
if c & ^definedMask != 0 {
names = append(names, fmt.Sprintf("Unknown(0x%X)", uint64(c & ^definedMask)))
}
return names
}
// String 实现 fmt.Stringer 接口
// 这样在 fmt.Printf("%v", cap) 时会自动调用
func (c Capability) String() string {
names := c.ToStrings()
if len(names) == 0 {
return "None"
}
return strings.Join(names, "|")
}