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

Error Occurs When Retrieving Usage Information Due to Delay in Data Availability #457

Closed
Viamo opened this issue Sep 7, 2024 · 24 comments
Closed

Comments

@Viamo
Copy link

Viamo commented Sep 7, 2024

What is the current behavior?

When calling deepgram.listen.prerecorded.v('1').transcribe_file(payload, options) followed immediately by deepgram.manage.v('1').get_usage_request(DEEPGRAM_PROJECT_ID, requestId), an error occurs in the file client.py at line 1004. The variable result has a value of None.

Steps to reproduce

  1. Call deepgram.listen.prerecorded.v('1').transcribe_file(payload, options).
  2. Immediately call deepgram.manage.v('1').get_usage_request(DEEPGRAM_PROJECT_ID, requestId) with DEEPGRAM_PROJECT_ID and requestId.

Expected behavior

The get_usage_request function should return valid usage information without returning None, and the package should handle the error if the data is not available yet.

Please tell us about your environment

  • Operating System/Version: Windows 10
  • Python Version: v3.11

Other information

The issue appears to be related to the delay in retrieving usage information. Even if the information is unavailable, the error should still be handled properly by the package.

@davidvonthenen
Copy link
Contributor

I looked into this, and it is an API issue. I will forward it to engineering, as the API should return an error instead of a result.

In the meantime, I would recommend checking for the null value in the result to determine data availability if you have a need for the API that quickly; otherwise, will need to wait for this fix in the API.

@Viamo
Copy link
Author

Viamo commented Sep 9, 2024

The variable result is not accessible because it is inside the package. The only way is to give up on the SDK and access the API directly, but for now, I just added sleep().

@davidvonthenen
Copy link
Contributor

The variable result is not accessible because it is inside the package. The only way is to give up on the SDK and access the API directly, but for now, I just added sleep().

Let me take a look at this and see what I can do.

@Viamo
Copy link
Author

Viamo commented Sep 9, 2024

Thank you for the help. I'm using sleep(), and that’s sufficient for now. It would be great if you could address the errors at your end. Thanks!

@davidvonthenen
Copy link
Contributor

Will be available in the 3.7.0 that is building right now.

@Viamo
Copy link
Author

Viamo commented Oct 17, 2024

It appears that the error is still occurring because, in the file client.py, on line 1002, the variable result receives a value that may be None, and on line 1006, the operation UsageRequest.from_json(result) throws an error.
I propose adding a None check to ensure that the variable result is properly validated before passing it to UsageRequest.from_json(result).

deepgram-sdk, version: 3.7.3

@davidvonthenen
Copy link
Contributor

We just need to mark the field Optional which will set it to None. Will make that change. I also think you mean response not result, correct?
https://github.com/deepgram/deepgram-python-sdk/blob/main/deepgram/clients/manage/v1/response.py#L489

@Viamo
Copy link
Author

Viamo commented Oct 17, 2024

No, I mean result in line 1002. I conducted some investigations and found that sometimes the result has a value of 'null', which causes an error when calling res = UsageRequest.from_json('null').

2024-10-17_214427+
2024-10-17_214523
2024-10-17_185407

@Viamo
Copy link
Author

Viamo commented Oct 17, 2024

And one more bug:

Sometimes usage.response is null in code:
usage = deepgram.manage.v('1').get_usage_request(DEEPGRAM_PROJECT_ID, request_id)

Screenshot for for i in range(10):

There is a difference in the third iteration with the same request.

2024-10-17_193757+

@davidvonthenen
Copy link
Contributor

davidvonthenen commented Oct 17, 2024

ahhhh I see. My misunderstanding on where the error is. That sounds reasonable. thanks for your help with this!!

@Viamo
Copy link
Author

Viamo commented Oct 18, 2024

Why might the data be unavailable? Is it possible to ensure the data is always available (availability exception is still necessary to implement)? In third-party APIs, usage is returned immediately in the results of the first API call, without requiring a second API call to retrieve usage, which is why their data is always available.

@davidvonthenen
Copy link
Contributor

davidvonthenen commented Oct 18, 2024

I am not sure, but I will pass this along to the API platform team to see if they can address that. Otherwise, if we do receive a None value from any of the API calls (not just this one), we should throw an exception.

@davidvonthenen
Copy link
Contributor

This should be available in 3.7.4

@Viamo
Copy link
Author

Viamo commented Oct 20, 2024

Hi David! Is this the fix for the error?
If so, could you double-check to ensure it’s correct? The issue occurs when the received value is not None, but 'null' (as a string), as I mentioned above.

2024-10-20_151832


2024-10-20_153104

@davidvonthenen
Copy link
Contributor

I ended up duplicating it. Give this a try:
https://github.com/deepgram/deepgram-python-sdk/releases/tag/v3.7.5

@Viamo
Copy link
Author

Viamo commented Oct 22, 2024

Hi, David! I tested v3.7.5 and noticed an odd issue: when making identical transcribe_file and get_usage_request requests multiple times, the "usd" field sometimes has a value of 0.0 in the response. I’ve attached a screenshot 1 showing the differences between

  • the request with a correct response (on the left, "request_id": "f3a3b1db-5557-4f86-8366-ba6e72022feb") and
  • the request with a defective response (on the right, "request_id": "35262ffd-b945-4ed5-be3d-c2337312648f").

If I repeat the get_usage_request request with the same request_id, the "usd" field then has the correct value (screenshot 2).

In the end, the minimal loop log looks like this:

usd = 0.00007
usd = 0.00007
usd = 0.00007
[DeepgramError] DeepgramError: Response is not available yet. Please try again later.
usd = 0.00007
usd = 0.00007
usd = 0.00007
usd = 0
usd = 0.00007
usd = 0.00007
[DeepgramError] DeepgramError: Response is not available yet. Please try again later.
usd = 0.00007
usd = 0.00007
usd = 0
usd = 0.00007
usd = 0.00007
usd = 0.00007
usd = 0.00007
[DeepgramError] DeepgramError: Response is not available yet. Please try again later.
usd = 0.00007
usd = 0.00007
usd = 0.00007

Sometimes I get a DeepgramError, and sometimes the "usd" field is 0.
As I understand it, the usage record doesn't appear immediately but gradually, so sometimes I may not receive the usage at all, or receive usage without a response, or receive usage with a response but without the usd field. I think the issue is with the API.

2024-10-22_165118+

2024-10-22_235104+

@davidvonthenen
Copy link
Contributor

Yea, the behavior is definitely API related since the SDK is only passing things through.

For the times you get 0.0, if you re-query a little later, does it give you the correct value?

@Viamo
Copy link
Author

Viamo commented Oct 23, 2024

If I repeat the get_usage_request request with the same request_id, the "usd" field then has the correct value (screenshot 2).

@davidvonthenen
Copy link
Contributor

Yeah, that's the API, and it is probably due to the internal replication of values. In your use case, you need to take note of the value and retry. I can pass this feedback along since this is an API artifact.

@Viamo
Copy link
Author

Viamo commented Oct 23, 2024

Yes, please pass along this feedback.

As I understand it, the usage record doesn't appear immediately but gradually, so sometimes I may not receive the usage at all, or receive usage without a response, or receive usage with a response but without the usd field. I think the issue is with the API.

@Viamo
Copy link
Author

Viamo commented Nov 20, 2024

Hello! Again this error 😫:

[AttributeError] 'NoneType' object has no attribute 'items'
  File "E:\PyProjects3\megogo-tiktok\scripts\s04_transcribe_audio_3_deepgram.py", line 39, in <module>
    transcribe_audio_with_deepgram(time_file_reporter, token_file_reporter)
  File "E:\PyProjects3\megogo-tiktok\scripts\s04_transcribe_audio_3_deepgram.py", line 29, in transcribe_audio_with_deepgram
    transcription_price = get_usage_usd(request_id)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\PyProjects3\megogo-tiktok\services\audio_deepgram.py", line 57, in get_usage_usd
    usage = deepgram.manage.v('1').get_usage_request(DEEPGRAM_PROJECT_ID, request_id)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\PyProjects3\megogo-tiktok\.venv\Lib\site-packages\deepgram\clients\manage\v1\client.py", line 1006, in get_usage_request
    res = UsageRequest.from_json(result)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\PyProjects3\megogo-tiktok\.venv\Lib\site-packages\dataclasses_json\api.py", line 63, in from_json
    return cls.from_dict(kvs, infer_missing=infer_missing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\PyProjects3\megogo-tiktok\.venv\Lib\site-packages\dataclasses_json\api.py", line 70, in from_dict
    return _decode_dataclass(cls, kvs, infer_missing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\PyProjects3\megogo-tiktok\.venv\Lib\site-packages\dataclasses_json\core.py", line 163, in _decode_dataclass
    kvs = {decode_names.get(k, k): v for k, v in kvs.items()}
                                                 ^^^^^^^^^

@Viamo
Copy link
Author

Viamo commented Jan 24, 2025

The issue is still not resolved.
Previously, the error was [AttributeError] 'NoneType' object has no attribute 'items'. Now, in the latest version of deepgram-sdk, it has changed to [AttributeError] 'NoneType' object has no attribute 'get'.

@Viamo
Copy link
Author

Viamo commented Jan 24, 2025

We are considering switching to another service, AssemblyAI, because you are unable to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants