generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathmain.py
87 lines (74 loc) · 2.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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
import os
import sys
from dotenv import load_dotenv
import logging
from deepgram.utils import verboselogs
from deepgram import (
DeepgramClient,
DeepgramClientOptions,
UsageFieldsOptions,
UsageSummaryOptions,
UsageRequestOptions,
)
load_dotenv()
def main():
try:
# Create a Deepgram client using the API key
# config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.SPAM)
config: DeepgramClientOptions = DeepgramClientOptions()
deepgram: DeepgramClient = DeepgramClient("", config)
# get projects
projectResp = deepgram.manage.v("1").get_projects()
if projectResp is None:
print(f"ListProjects failed.")
sys.exit(1)
myId = None
myName = None
for project in projectResp.projects:
myId = project.project_id
myName = project.name
print(f"ListProjects() - ID: {myId}, Name: {myName}")
break
# list requests
requestId = None
options: UsageRequestOptions = {}
listResp = deepgram.manage.v("1").get_usage_requests(myId, options)
if listResp is None:
print("No requests found")
else:
print(f"GetUsageRequests() - listResp: {listResp}")
for request in listResp.requests:
requestId = request.request_id
break
print(f"request_id: {requestId}")
print("")
# get request
getResp = deepgram.manage.v("1").get_usage_request(myId, requestId)
if getResp is None:
print("No request found")
else:
print(f"GetUsageRequest() - getResp: {getResp}")
print("")
# get fields
options: UsageFieldsOptions = {}
listFields = deepgram.manage.v("1").get_usage_fields(myId, options)
if listFields is None:
print(f"UsageFields not found.")
sys.exit(1)
else:
print(f"GetUsageFields Models - listFields: {listFields}")
print("")
# list usage
options: UsageSummaryOptions = {}
getSummary = deepgram.manage.v("1").get_usage_summary(myId, options)
if getSummary is None:
print("UsageSummary not found")
else:
print(f"GetSummary - getSummary: {getSummary}")
except Exception as e:
print(f"Exception: {e}")
if __name__ == "__main__":
main()