GET Request Output
Once POST Compute Request has been submitted on different models, the computed metadata is stored and can be accessed by using requestId. The time taken to compute metadata from different models is dependant on the time duration of the Conversation and the number of models enabled.
A 60 minute long conversation should take around 15-20 minutes to get to processed status.
To track the status of requested models the Get Processing State route can be used. This route can be integrated with your code by using long-polling to check the state periodically until the processing of the all the requestId are in processed state. For more information refer to the Example given below.

Get Processing state

The state of a particular request ID can take the following values.
State
Description
uploaded
When the model processing request has been acknowledged by Marsview and the request is either queued or being processed.
error
When there was an error processing the model. This could either be a configuration issue or an Internal Server error. In case of a failure, more information can be found from the metadata section or by referring to the Error Code given in the JSON response.
processed
When the model processing request has completed successfully.
get
https://api.marsview.ai
/cb/v1/conversation/get_txn/:txnId
Get Processing State
get
https://api.marsview.ai
/cb/v1/conversation/fetch_metadata/:txnId
Get Request Metadata

Example: How to fetch speech to text output for a Transaction ID using Long-polling

This example will demonstrate how to long-poll for Speech-to-text model processing to complete and fetch the Speech-to-text model metadata once the model.state.status is in processed state.
For more information on how to send a compute request on a Particular Transaction ID refer to the Compute Metadata section of the documentation.

Step 1: Get the authentication token.

Using your 'API Key' and 'API Secret'you can generate the token as shown below.
Curl
1
curl --location --request POST 'https://api.marsview.ai/cb/v1/auth/create_access_token' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"apiKey": "{{Insert API Key}}",
5
"apiSecret": "{{Insert API Secret}}",
6
"userId": "[email protected]"
7
}'
8
Copied!

Step 2: Long-poll on the processing state

Using the Get Processing State method the Processing request status can be fetched periodically (every 300 seconds in this case).
  • If the process is in uploaded state we continue to poll until the process is in either processed or error state.
  • If the process is in processed state or error state we can move to Step 3.
Step 3: Fetching metadata
Once a particular request is in processed state Metadata for that model can be fetched using the Get Request Metadata method.
Shown below is an example Python code snippet for step 2 and step 3
Python
1
import requests
2
txn_id = "replace this with your Transaction ID"
3
auth_token = "Bearer <API TOKEN>"
4
5
processing_state_url = "https://api.marsview.ai/cb/v1/conversation/get_txn/{txn_id}"
6
metadata_url = "https://api.marsview.aicb/v1/conversation/fetch_metadata/{txnId}"
7
8
def get_speech_to_text_state():
9
payload={}
10
headers = {
11
'authorization': '{}'.format(auth_token)
12
}
13
response = requests.request("GET", processing_state_url.format(txn_id=user_id), headers=headers, json=payload)
14
print(response.text)
15
if response.status_code == 200 and response.json()["status"] == "true":
16
return response.json()["data"]["enableModels"]["state"]["status"]
17
else:
18
raise Exception("Custom exception")
19
20
def get_speech_to_text_metadata():
21
payload={}
22
headers = {
23
'authorization': '{}'.format(auth_token)
24
}
25
26
response = requests.request("GET", metadata_url.format(txn_id=user_id), headers=headers, json=payload)
27
if response.status_code == 200 and response.json()["status"] == "true":
28
return response.json()["data"]["transcript"]
29
else:
30
raise Exception("Custom exception")
31
32
def long_poll_results():
33
while True:
34
state = get_speech_to_text_state()
35
if state == "processed":
36
return get_speech_to_text_metadata()
37
elif state == "uploaded":
38
time.sleep(300)
39
elif state == "error":
40
raise Exception("An error has occured during the processing of this request")
41
if __name__ == "__main__":
42
long_poll_results()
Copied!
Last modified 3mo ago