Skip to content

Commit 34972db

Browse files
authored
go : add temperature options (ggml-org#2417)
* Fixed go cuda bindings building * Added note to go bindings Readme to build using cuda support * Added temperature bindings for Go --------- Co-authored-by: Binozo <[email protected]>
1 parent bea43e0 commit 34972db

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

bindings/go/params.go

+12
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ func (p *Params) SetEntropyThold(t float32) {
131131
p.entropy_thold = C.float(t)
132132
}
133133

134+
func (p *Params) SetTemperature(t float32) {
135+
p.temperature = C.float(t)
136+
}
137+
138+
// Sets the fallback temperature incrementation
139+
// Pass -1.0 to disable this feature
140+
func (p *Params) SetTemperatureFallback(t float32) {
141+
p.temperature_inc = C.float(t)
142+
}
143+
134144
// Set initial prompt
135145
func (p *Params) SetInitialPrompt(prompt string) {
136146
p.initial_prompt = C.CString(prompt)
@@ -162,6 +172,8 @@ func (p *Params) String() string {
162172
str += fmt.Sprintf(" audio_ctx=%d", p.audio_ctx)
163173
str += fmt.Sprintf(" initial_prompt=%s", C.GoString(p.initial_prompt))
164174
str += fmt.Sprintf(" entropy_thold=%f", p.entropy_thold)
175+
str += fmt.Sprintf(" temperature=%f", p.temperature)
176+
str += fmt.Sprintf(" temperature_inc=%f", p.temperature_inc)
165177
str += fmt.Sprintf(" beam_size=%d", p.beam_search.beam_size)
166178
if p.translate {
167179
str += " translate"

bindings/go/pkg/whisper/context.go

+11
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ func (context *context) SetEntropyThold(t float32) {
140140
context.params.SetEntropyThold(t)
141141
}
142142

143+
// Set Temperature
144+
func (context *context) SetTemperature(t float32) {
145+
context.params.SetTemperature(t)
146+
}
147+
148+
// Set the fallback temperature incrementation
149+
// Pass -1.0 to disable this feature
150+
func (context *context) SetTemperatureFallback(t float32) {
151+
context.params.SetTemperatureFallback(t)
152+
}
153+
143154
// Set initial prompt
144155
func (context *context) SetInitialPrompt(prompt string) {
145156
context.params.SetInitialPrompt(prompt)

bindings/go/pkg/whisper/interface.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,22 @@ type Context interface {
3838
IsMultilingual() bool // Return true if the model is multilingual.
3939
Language() string // Get language
4040

41-
SetOffset(time.Duration) // Set offset
42-
SetDuration(time.Duration) // Set duration
43-
SetThreads(uint) // Set number of threads to use
44-
SetSplitOnWord(bool) // Set split on word flag
45-
SetTokenThreshold(float32) // Set timestamp token probability threshold
46-
SetTokenSumThreshold(float32) // Set timestamp token sum probability threshold
47-
SetMaxSegmentLength(uint) // Set max segment length in characters
48-
SetTokenTimestamps(bool) // Set token timestamps flag
49-
SetMaxTokensPerSegment(uint) // Set max tokens per segment (0 = no limit)
50-
SetAudioCtx(uint) // Set audio encoder context
51-
SetMaxContext(n int) // Set maximum number of text context tokens to store
52-
SetBeamSize(n int) // Set Beam Size
53-
SetEntropyThold(t float32) // Set Entropy threshold
54-
SetInitialPrompt(prompt string) // Set initial prompt
41+
SetOffset(time.Duration) // Set offset
42+
SetDuration(time.Duration) // Set duration
43+
SetThreads(uint) // Set number of threads to use
44+
SetSplitOnWord(bool) // Set split on word flag
45+
SetTokenThreshold(float32) // Set timestamp token probability threshold
46+
SetTokenSumThreshold(float32) // Set timestamp token sum probability threshold
47+
SetMaxSegmentLength(uint) // Set max segment length in characters
48+
SetTokenTimestamps(bool) // Set token timestamps flag
49+
SetMaxTokensPerSegment(uint) // Set max tokens per segment (0 = no limit)
50+
SetAudioCtx(uint) // Set audio encoder context
51+
SetMaxContext(n int) // Set maximum number of text context tokens to store
52+
SetBeamSize(n int) // Set Beam Size
53+
SetEntropyThold(t float32) // Set Entropy threshold
54+
SetInitialPrompt(prompt string) // Set initial prompt
55+
SetTemperature(t float32) // Set temperature
56+
SetTemperatureFallback(t float32) // Set temperature incrementation
5557

5658
// Process mono audio data and return any errors.
5759
// If defined, newly generated segments are passed to the

0 commit comments

Comments
 (0)