Skip to content

Commit c4e1861

Browse files
authoredAug 28, 2024
go : add beamsize/entropythold/maxcontext to context interface (#2350)
* feat(go binding): add beamsize/entropythold/maxcontext to context interface fixes: #2349 * fix go building build * fix dynamic link .so and header.h * remove LD_LIBRARY_PATH * remove ggml obj from whisper dynamic lib * drop LIB_GGML
1 parent da9809f commit c4e1861

File tree

6 files changed

+36
-3
lines changed

6 files changed

+36
-3
lines changed
 

‎Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,8 @@ $(LIB_WHISPER): \
971971
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
972972

973973
$(LIB_WHISPER_S): \
974-
$(OBJ_WHISPER)
974+
$(OBJ_WHISPER) \
975+
$(OBJ_GGML)
975976
ar rcs $(LIB_WHISPER_S) $^
976977

977978
# common

‎bindings/go/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GGML_METAL_PATH_RESOURCES := $(abspath ../..)
1414
BUILD_DIR := build
1515
MODELS_DIR := models
1616
EXAMPLES_DIR := $(wildcard examples/*)
17-
INCLUDE_PATH := $(abspath ../..)
17+
INCLUDE_PATH := $(abspath ../../include):$(abspath ../../ggml/include)
1818
LIBRARY_PATH := $(abspath ../..)
1919

2020
ifeq ($(UNAME_S),Darwin)

‎bindings/go/params.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ func (p *Params) SetAudioCtx(n int) {
119119
p.audio_ctx = C.int(n)
120120
}
121121

122+
func (p *Params) SetMaxContext(n int) {
123+
p.n_max_text_ctx = C.int(n)
124+
}
125+
126+
func (p *Params) SetBeamSize(n int) {
127+
p.beam_search.beam_size = C.int(n)
128+
}
129+
130+
func (p *Params) SetEntropyThold(t float32) {
131+
p.entropy_thold = C.float(t)
132+
}
133+
122134
// Set initial prompt
123135
func (p *Params) SetInitialPrompt(prompt string) {
124136
p.initial_prompt = C.CString(prompt)
@@ -149,6 +161,8 @@ func (p *Params) String() string {
149161
str += fmt.Sprintf(" duration_ms=%d", p.duration_ms)
150162
str += fmt.Sprintf(" audio_ctx=%d", p.audio_ctx)
151163
str += fmt.Sprintf(" initial_prompt=%s", C.GoString(p.initial_prompt))
164+
str += fmt.Sprintf(" entropy_thold=%f", p.entropy_thold)
165+
str += fmt.Sprintf(" beam_size=%d", p.beam_search.beam_size)
152166
if p.translate {
153167
str += " translate"
154168
}

‎bindings/go/pkg/whisper/context.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ func (context *context) SetAudioCtx(n uint) {
125125
context.params.SetAudioCtx(int(n))
126126
}
127127

128+
// Set maximum number of text context tokens to store
129+
func (context *context) SetMaxContext(n int) {
130+
context.params.SetMaxContext(n)
131+
}
132+
133+
// Set Beam Size
134+
func (context *context) SetBeamSize(n int) {
135+
context.params.SetBeamSize(n)
136+
}
137+
138+
// Set Entropy threshold
139+
func (context *context) SetEntropyThold(t float32) {
140+
context.params.SetEntropyThold(t)
141+
}
142+
128143
// Set initial prompt
129144
func (context *context) SetInitialPrompt(prompt string) {
130145
context.params.SetInitialPrompt(prompt)

‎bindings/go/pkg/whisper/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type Context interface {
4848
SetTokenTimestamps(bool) // Set token timestamps flag
4949
SetMaxTokensPerSegment(uint) // Set max tokens per segment (0 = no limit)
5050
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
5154
SetInitialPrompt(prompt string) // Set initial prompt
5255

5356
// Process mono audio data and return any errors.

‎bindings/go/whisper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// CGO
1010

1111
/*
12-
#cgo LDFLAGS: -lwhisper -lm -lstdc++
12+
#cgo LDFLAGS: -lwhisper -lm -lstdc++ -fopenmp
1313
#cgo darwin LDFLAGS: -framework Accelerate -framework Metal -framework Foundation -framework CoreGraphics
1414
#include <whisper.h>
1515
#include <stdlib.h>

0 commit comments

Comments
 (0)
Failed to load comments.