-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure Clients to Implement Versioning, Restructure APIs Finer G…
…rained Versioning
- Loading branch information
1 parent
c1872dc
commit ee55d31
Showing
138 changed files
with
2,836 additions
and
916 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. | ||
// Use of this source code is governed by a MIT license that can be found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
api "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1" | ||
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1/interfaces" | ||
client "github.com/deepgram/deepgram-go-sdk/pkg/client/manage" | ||
) | ||
|
||
func main() { | ||
// init library | ||
client.InitWithDefault() | ||
|
||
// context | ||
ctx := context.Background() | ||
|
||
//client | ||
dg := client.NewWithDefaults() | ||
mgClient := api.New(dg) | ||
|
||
// list projects | ||
respList, err := mgClient.ListProjects(ctx) | ||
if err != nil { | ||
fmt.Printf("ListProjects failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
var projectID string | ||
for _, item := range respList.Projects { | ||
projectID = item.ProjectID | ||
name := item.Name | ||
fmt.Printf("ListProjects() - Name: %s, ID: %s\n", name, projectID) | ||
break | ||
} | ||
|
||
// list invitations | ||
respGet, err := mgClient.ListInvitations(ctx, projectID) | ||
if err != nil { | ||
fmt.Printf("ListInvitations failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
if len(respGet.Invites) == 0 { | ||
fmt.Printf("ListInvitations() - No invitations found\n") | ||
} else { | ||
for _, item := range respGet.Invites { | ||
id := item.Email | ||
scope := item.Scope | ||
fmt.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) | ||
} | ||
} | ||
|
||
// send invite | ||
respMessage, err := mgClient.SendInvitation(ctx, projectID, &interfaces.InvitationRequest{ | ||
Email: "[email protected]", | ||
Scope: "member", | ||
}) | ||
if err != nil { | ||
fmt.Printf("SendInvitation failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("SendInvitation() - Result: %s\n", respMessage.Message) | ||
|
||
// list invitations | ||
respGet, err = mgClient.ListInvitations(ctx, projectID) | ||
if err != nil { | ||
fmt.Printf("ListInvitations failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
if len(respGet.Invites) == 0 { | ||
fmt.Printf("ListInvitations() - No invitations found\n") | ||
} else { | ||
for _, item := range respGet.Invites { | ||
id := item.Email | ||
scope := item.Scope | ||
fmt.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) | ||
} | ||
} | ||
|
||
// delete invitation | ||
respMessage, err = mgClient.DeleteInvitation(ctx, projectID, "[email protected]") | ||
if err != nil { | ||
fmt.Printf("DeleteInvitation failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("DeleteInvitation() - Result: %s\n", respMessage.Message) | ||
|
||
// list invitations | ||
respGet, err = mgClient.ListInvitations(ctx, projectID) | ||
if err != nil { | ||
fmt.Printf("ListInvitations failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
if len(respGet.Invites) == 0 { | ||
fmt.Printf("ListInvitations() - No invitations found\n") | ||
} else { | ||
for _, item := range respGet.Invites { | ||
id := item.Email | ||
scope := item.Scope | ||
fmt.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) | ||
} | ||
} | ||
|
||
// There isnt an API call to add a member to a project. So will leave this commented out as an example | ||
// Leave Project | ||
// respMessage, err = mgClient.LeaveProject(ctx, projectID) | ||
// if err != nil { | ||
// fmt.Printf("LeaveProject failed. Err: %v\n", err) | ||
// os.Exit(1) | ||
// } | ||
// fmt.Printf("LeaveProject() - Name: %s\n", respMessage.Message) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. | ||
// Use of this source code is governed by a MIT license that can be found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
prettyjson "github.com/hokaccha/go-prettyjson" | ||
|
||
api "github.com/deepgram/deepgram-go-sdk/pkg/api/listen/v1/rest" | ||
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces" | ||
client "github.com/deepgram/deepgram-go-sdk/pkg/client/listen" | ||
) | ||
|
||
const ( | ||
filePath string = "./Bueller-Life-moves-pretty-fast.mp3" | ||
) | ||
|
||
func main() { | ||
// init library | ||
client.Init(client.InitLib{ | ||
LogLevel: client.LogLevelTrace, // LogLevelStandard / LogLevelFull / LogLevelTrace | ||
}) | ||
|
||
// Go context | ||
ctx := context.Background() | ||
|
||
// set the Transcription options | ||
options := &interfaces.PreRecordedTranscriptionOptions{ | ||
Model: "nova-2", | ||
Punctuate: true, | ||
Paragraphs: true, | ||
SmartFormat: true, | ||
Language: "en-US", | ||
Utterances: true, | ||
} | ||
|
||
// create a Deepgram client | ||
c := client.NewREST("", &interfaces.ClientOptions{ | ||
Host: "https://api.deepgram.com", | ||
}) | ||
dg := api.New(c) | ||
|
||
// example on how to send a custom header | ||
// need to import ( | ||
// "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces" | ||
// ) | ||
// | ||
// headers := make(map[string][]string, 0) | ||
// headers["MY-CUSTOM-HEADER"] = []string{"CUSTOM"} | ||
// ctx = cfginterfaces.WithCustomHeaders(ctx, headers) | ||
// | ||
// example on how to send a custom parameter | ||
// params := make(map[string][]string, 0) | ||
// params["utterances"] = []string{"true"} | ||
// ctx = cfginterfaces.WithCustomParameters(ctx, params) | ||
|
||
// send/process file to Deepgram | ||
res, err := dg.FromFile(ctx, filePath, options) | ||
if err != nil { | ||
if e, ok := err.(*interfaces.StatusError); ok { | ||
fmt.Printf("DEEPGRAM ERROR:\n%s:\n%s\n", e.DeepgramError.ErrCode, e.DeepgramError.ErrMsg) | ||
} | ||
fmt.Printf("FromStream failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
data, err := json.Marshal(res) | ||
if err != nil { | ||
fmt.Printf("json.Marshal failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// make the JSON pretty | ||
prettyJSON, err := prettyjson.Format(data) | ||
if err != nil { | ||
fmt.Printf("prettyjson.Marshal failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("\n\nResult:\n%s\n\n", prettyJSON) | ||
|
||
// dump example VTT | ||
vtt, err := res.ToWebVTT() | ||
if err != nil { | ||
fmt.Printf("ToWebVTT failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("\n\n\nVTT:\n%s\n\n\n", vtt) | ||
|
||
// dump example SRT | ||
srt, err := res.ToSRT() | ||
if err != nil { | ||
fmt.Printf("ToSRT failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("\n\n\nSRT:\n%s\n\n\n", srt) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.