Skip to content

Commit

Permalink
change to User-Agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
Weimin-Wan committed Aug 21, 2023
1 parent 82dda92 commit 772134d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 12 additions & 1 deletion deepgram/deepgram.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package deepgram
import (
"encoding/json"
"net/http"
"runtime"
"strings"
)

var sdkVersion string = "0.10.0"
var dgAgent string = "deepgram-go-sdk/v" + sdkVersion

var dgAgent string = "@deepgram/sdk/" + sdkVersion + " go/" + goVersion()

type Client struct {
ApiKey string
Expand Down Expand Up @@ -44,3 +47,11 @@ func GetJson(resp *http.Response, target interface{}) error {

return json.NewDecoder(resp.Body).Decode(target)
}

func goVersion() string {
version := runtime.Version()
if strings.HasPrefix(version, "go") {
return version[2:]
}
return version
}
12 changes: 6 additions & 6 deletions deepgram/prerecorded.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ type PreRecordedTranscriptionOptions struct {
Utterances bool `json:"utterances" url:"utterances,omitempty" `
Utt_split float64 `json:"utt_split" url:"utt_split,omitempty" `
Version string `json:"version" url:"version,omitempty" `
FillerWords string `json:"filler_words" url:"filler_words,omitempty" `
FillerWords string `json:"filler_words" url:"filler_words,omitempty" `
}

type PreRecordedResponse struct {
Request_id string `json:"request_id,omitempty"`
Metadata Metadata `json:"metadata"`
Results Results `json:"results"`
Request_id string `json:"request_id,omitempty"`
Metadata Metadata `json:"metadata"`
Results Results `json:"results"`
}

type Metadata struct {
Expand Down Expand Up @@ -203,7 +203,7 @@ func (dg *Client) PreRecordedFromStream(source ReadStreamSource, options PreReco
"Host": []string{dg.Host},
"Content-Type": []string{source.Mimetype},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

res, err := client.Do(req)
Expand Down Expand Up @@ -246,7 +246,7 @@ func (dg *Client) PreRecordedFromURL(source UrlSource, options PreRecordedTransc
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result PreRecordedResponse
Expand Down
2 changes: 1 addition & 1 deletion deepgram/transcriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (dg *Client) LiveTranscription(options LiveTranscriptionOptions) (*websocke
header := http.Header{
"Host": []string{dg.Host},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

c, resp, err := websocket.DefaultDialer.Dial(u.String(), header)
Expand Down

0 comments on commit 772134d

Please sign in to comment.