Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix On-Prem Host for Prerecorded, Add More Debug Trace #171

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/prerecorded/file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func main() {
}

// create a Deepgram client
c := client.NewWithDefaults()
c := client.New("", interfaces.ClientOptions{
Host: "https://api.deepgram.com",
})
dg := prerecorded.New(c)

// example on how to send a custom header
Expand Down
2 changes: 1 addition & 1 deletion examples/prerecorded/intent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
func main() {
// init library
client.Init(client.InitLib{
LogLevel: client.LogLevelStandard, // LogLevelStandard / LogLevelFull / LogLevelTrace
LogLevel: client.LogLevelDefault, // LogLevelStandard / LogLevelFull / LogLevelTrace
})

// Go context
Expand Down
2 changes: 1 addition & 1 deletion examples/prerecorded/sentiment/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
func main() {
// init library
client.Init(client.InitLib{
LogLevel: client.LogLevelStandard, // LogLevelStandard / LogLevelFull / LogLevelTrace
LogLevel: client.LogLevelDefault, // LogLevelStandard / LogLevelFull / LogLevelTrace
})

// Go context
Expand Down
2 changes: 1 addition & 1 deletion examples/prerecorded/stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
func main() {
// init library
client.Init(client.InitLib{
LogLevel: client.LogLevelFull,
LogLevel: client.LogLevelDefault, // LogLevelStandard / LogLevelFull / LogLevelTrace
})

// context
Expand Down
2 changes: 1 addition & 1 deletion examples/prerecorded/summary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
func main() {
// init library
client.Init(client.InitLib{
LogLevel: client.LogLevelStandard, // LogLevelStandard / LogLevelFull / LogLevelTrace
LogLevel: client.LogLevelDefault, // LogLevelStandard / LogLevelFull / LogLevelTrace
})

// Go context
Expand Down
2 changes: 1 addition & 1 deletion examples/prerecorded/topic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
func main() {
// init library
client.Init(client.InitLib{
LogLevel: client.LogLevelStandard, // LogLevelStandard / LogLevelFull / LogLevelTrace
LogLevel: client.LogLevelDefault, // LogLevelStandard / LogLevelFull / LogLevelTrace
})

// Go context
Expand Down
9 changes: 7 additions & 2 deletions examples/streaming/microphone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ func main() {
// Go context
ctx := context.Background()

// client options
cOptions := interfaces.ClientOptions{
EnableKeepAlive: true,
}

// set the Transcription options
options := interfaces.LiveTranscriptionOptions{
tOptions := interfaces.LiveTranscriptionOptions{
Model: "nova-2",
Language: "en-US",
Punctuate: true,
Expand All @@ -93,7 +98,7 @@ func main() {
callback := MyCallback{}

// create a Deepgram client
dgClient, err := client.NewWithDefaults(ctx, options, callback)
dgClient, err := client.New(ctx, "", cOptions, tOptions, callback)
if err != nil {
fmt.Println("ERROR creating LiveTranscription connection:", err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/version/prerecorded-version.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetPrerecordedAPI(ctx context.Context, host, version, path string, options
host = common.DefaultHost
}

r, err := regexp.Compile("^(wss|ws)://(.+)$")
r, err := regexp.Compile("^(https|http)://(.+)$")
if err != nil {
klog.V(1).Infof("regexp.Compile err: %v\n", err)
return "", err
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/live/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Notes:
- The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY
*/
func NewForDemo(ctx context.Context, options interfaces.LiveTranscriptionOptions) (*Client, error) {
return New(ctx, "", &interfaces.ClientOptions{}, options, nil)
return New(ctx, "", interfaces.ClientOptions{}, options, nil)
}

/*
Expand All @@ -42,7 +42,7 @@ Notes:
- The callback handler is set to the default handler which just prints all messages to the console
*/
func NewWithDefaults(ctx context.Context, options interfaces.LiveTranscriptionOptions, callback msginterfaces.LiveMessageCallback) (*Client, error) {
return New(ctx, "", &interfaces.ClientOptions{}, options, callback)
return New(ctx, "", interfaces.ClientOptions{}, options, callback)
}

/*
Expand All @@ -55,7 +55,7 @@ Input parameters:
- tOptions: LiveTranscriptionOptions which allows overriding things like language, model, etc.
- callback: LiveMessageCallback which is a callback that allows you to perform actions based on the transcription
*/
func New(ctx context.Context, apiKey string, cOptions *interfaces.ClientOptions, tOptions interfaces.LiveTranscriptionOptions, callback msginterfaces.LiveMessageCallback) (*Client, error) {
func New(ctx context.Context, apiKey string, cOptions interfaces.ClientOptions, tOptions interfaces.LiveTranscriptionOptions, callback msginterfaces.LiveMessageCallback) (*Client, error) {
klog.V(6).Infof("live.New() ENTER\n")

if apiKey != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/live/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// Client is a struct representing the websocket client connection
type Client struct {
cOptions *interfaces.ClientOptions
cOptions interfaces.ClientOptions
tOptions interfaces.LiveTranscriptionOptions

sendBuf chan []byte
Expand Down
32 changes: 27 additions & 5 deletions pkg/client/prerecorded/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"net/http"
"net/url"
"os"
"strings"

klog "k8s.io/klog/v2"

Expand All @@ -36,7 +37,7 @@ Notes:
- The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY
*/
func NewWithDefaults() *Client {
return New("", &interfaces.ClientOptions{})
return New("", interfaces.ClientOptions{})
}

/*
Expand All @@ -47,7 +48,7 @@ Input parameters:
- apiKey: string containing the Deepgram API key
- options: ClientOptions which allows overriding things like hostname, version of the API, etc.
*/
func New(apiKey string, options *interfaces.ClientOptions) *Client {
func New(apiKey string, options interfaces.ClientOptions) *Client {
if apiKey != "" {
options.ApiKey = apiKey
}
Expand Down Expand Up @@ -183,7 +184,14 @@ func (c *Client) DoStream(ctx context.Context, src io.Reader, options interfaces
_, err := io.Copy(b, res.Body)
return err
default:
d := json.NewDecoder(res.Body)
resultStr, errRead := io.ReadAll(res.Body)
if errRead != nil {
klog.V(1).Infof("io.ReadAll failed. Err: %v\n", errRead)
klog.V(6).Infof("prerecorded.DoStream() LEAVE\n")
return errRead
}
klog.V(5).Infof("json.NewDecoder Raw:\n\n%s\n\n", resultStr)
d := json.NewDecoder(strings.NewReader(string(resultStr)))
klog.V(3).Infof("json.NewDecoder\n")
klog.V(6).Infof("prerecorded.DoStream() LEAVE\n")
return d.Decode(resBody)
Expand Down Expand Up @@ -309,7 +317,14 @@ func (c *Client) DoURL(ctx context.Context, url string, options interfaces.PreRe
_, err := io.Copy(b, res.Body)
return err
default:
d := json.NewDecoder(res.Body)
resultStr, errRead := io.ReadAll(res.Body)
if errRead != nil {
klog.V(1).Infof("io.ReadAll failed. Err: %v\n", errRead)
klog.V(6).Infof("prerecorded.DoURL() LEAVE\n")
return errRead
}
klog.V(5).Infof("json.NewDecoder Raw:\n\n%s\n\n", resultStr)
d := json.NewDecoder(strings.NewReader(string(resultStr)))
klog.V(3).Infof("json.NewDecoder\n")
klog.V(6).Infof("prerecorded.DoURL() LEAVE\n")
return d.Decode(resBody)
Expand Down Expand Up @@ -395,7 +410,14 @@ func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{})
_, err := io.Copy(b, res.Body)
return err
default:
d := json.NewDecoder(res.Body)
resultStr, errRead := io.ReadAll(res.Body)
if errRead != nil {
klog.V(1).Infof("io.ReadAll failed. Err: %v\n", errRead)
klog.V(6).Infof("prerecorded.Do() LEAVE\n")
return errRead
}
klog.V(5).Infof("json.NewDecoder Raw:\n\n%s\n\n", resultStr)
d := json.NewDecoder(strings.NewReader(string(resultStr)))
klog.V(3).Infof("json.NewDecoder\n")
klog.V(6).Infof("prerecorded.Do() LEAVE\n")
return d.Decode(resBody)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/prerecorded/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import (
type Client struct {
*rest.Client

cOptions *interfaces.ClientOptions
cOptions interfaces.ClientOptions
}
2 changes: 1 addition & 1 deletion pkg/client/rest/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// New allocated a Simple HTTP client
func NewHTTPClient(options *interfaces.ClientOptions) *HttpClient {
func NewHTTPClient(options interfaces.ClientOptions) *HttpClient {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: options.SkipServerAuth},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (

// NewWithDefaults creates a REST client with default options
func NewWithDefaults() *Client {
return New(&interfaces.ClientOptions{})
return New(interfaces.ClientOptions{})
}

// New REST client
func New(options *interfaces.ClientOptions) *Client {
func New(options interfaces.ClientOptions) *Client {
err := options.Parse()
if err != nil {
klog.V(1).Infof("options.Parse failed. Err: %v\n", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/rest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type HttpClient struct {
d *debugContainer
UserAgent string

options *interfaces.ClientOptions
options interfaces.ClientOptions
}

// Client which extends HttpClient to support REST
type Client struct {
*HttpClient

Options *interfaces.ClientOptions
Options interfaces.ClientOptions
}
6 changes: 3 additions & 3 deletions tests/prerecorded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestPrerecordedFromURL(t *testing.T) {
httpmock.RegisterResponder("POST", betaEndPoint, preRecordedFromURLHandler)

t.Run("Test Basic PreRecordedFromURL", func(t *testing.T) {
c := client.New(MockAPIKey, &interfaces.ClientOptions{})
c := client.New(MockAPIKey, interfaces.ClientOptions{})
httpmock.ActivateNonDefault(&c.Client.HttpClient.Client)
dg := prerecorded.New(c)
_, err := dg.FromURL(
Expand All @@ -137,7 +137,7 @@ func TestPrerecordedFromURL(t *testing.T) {
})

t.Run("Test PreRecordedFromURL with summarize v1", func(t *testing.T) {
c := client.New(MockAPIKey, &interfaces.ClientOptions{})
c := client.New(MockAPIKey, interfaces.ClientOptions{})
httpmock.ActivateNonDefault(&c.Client.HttpClient.Client)
dg := prerecorded.New(c)
_, err := dg.FromURL(
Expand All @@ -153,7 +153,7 @@ func TestPrerecordedFromURL(t *testing.T) {
})

t.Run("Test PreRecordedFromURL with summarize v2", func(t *testing.T) {
c := client.New(MockAPIKey, &interfaces.ClientOptions{})
c := client.New(MockAPIKey, interfaces.ClientOptions{})
httpmock.ActivateNonDefault(&c.Client.HttpClient.Client)
dg := prerecorded.New(c)
_, err := dg.FromURL(
Expand Down
Loading