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

Get an error when calling run from the model object #34

Open
EdikxXx opened this issue Nov 25, 2024 · 3 comments
Open

Get an error when calling run from the model object #34

EdikxXx opened this issue Nov 25, 2024 · 3 comments

Comments

@EdikxXx
Copy link

EdikxXx commented Nov 25, 2024

I sometimes get a TypeError: list indices must be integers or slices, not str when I call run from model object.
This is my code:

def get_text_embeddings(text: str, model_name: str = "doc") -> list[float]:
    sdk = YCloudML(folder_id=settings.YANDEX_CLOUD_API_ID, auth=settings.YANDEX_CLOUD_API_KEY)
    model = sdk.models.text_embeddings(model_name)
    result = model.run(text)

    return list(result)

From the traceback I see that the error is called from the run method.
For example, I call get_text_embeddings with text = "Станки зубообрабатывающие" and model_name = "query", and I get the following traceback:"

TypeError: list indices must be integers or slices, not str
  File "django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "contextlib.py", line 81, in inner
    return func(*args, **kwds)
  File "contextlib.py", line 81, in inner
    return func(*args, **kwds)
  File "contextlib.py", line 81, in inner
    return func(*args, **kwds)
  File "django/views/decorators/cache.py", line 40, in _cache_controlled
    response = viewfunc(request, *args, **kw)
  File "django/views/decorators/csrf.py", line 55, in wrapped_view
    return view_func(*args, **kwargs)
  File "django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "rest_framework/decorators.py", line 50, in handler
    return func(*args, **kwargs)
  File "elec/contrib/doska/views/api.py", line 77, in posts_search_by_text_vector
    get_text_embeddings(post.title, "query"),
  File "elec/contrib/doska/embedding.py", line 34, in get_text_embeddings
    result = model.run(text)
  File "yandex_cloud_ml_sdk/_utils/sync.py", line 62, in wrapped
    return run_sync_impl(inner, self._sdk)
  File "yandex_cloud_ml_sdk/_utils/sync.py", line 39, in run_sync_impl
    result: T = _runner_map[key].run(coro)
  File "yandex_cloud_ml_sdk/_utils/sync.py", line 27, in run
    return fut.result(None)
  File "concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
  File "concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "yandex_cloud_ml_sdk/_models/text_embeddings/model.py", line 44, in _run
    async with self._client.get_service_stub(EmbeddingsServiceStub, timeout=timeout) as stub:
  File "contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
  File "yandex_cloud_ml_sdk/_client.py", line 142, in get_service_stub
    channel = await self._get_channel(stub_class, timeout)
  File "yandex_cloud_ml_sdk/_client.py", line 129, in _get_channel
    await self._init_service_map(timeout=timeout)
  File "yandex_cloud_ml_sdk/_client.py", line 67, in _init_service_map
    response = await stub.List(
  File "grpc/aio/_interceptor.py", line 471, in __await__
    call = yield from self._interceptors_task.__await__()
  File "grpc/aio/_interceptor.py", line 701, in _invoke
    return await _run_interceptor(
  File "grpc/aio/_interceptor.py", line 675, in _run_interceptor
    call_or_response = await interceptors[0].intercept_unary_unary(
  File "grpc/aio/_interceptor.py", line 675, in _run_interceptor
    call_or_response = await interceptors[0].intercept_unary_unary(
  File "yandex_cloud_ml_sdk/_retry.py", line 274, in intercept_unary_unary
    retry_type = client_call_details.metadata[RETRY_KIND_METADATA_KEY]

I think it relates to the calling of metadata attributes through the variable RETRY_KIND_METADATA_KEY. Since RETRY_KIND_METADATA_KEY is a string, it could be causing this error.

@vhaldemar
Copy link
Collaborator

Hey!
This is extremely interesting, especially about "sometimes".
The catch is, client_call_details.metadata is a special Metadata object and should be never be a list.
But from your traceback I can see that there is calling of two grpc interceptors.
Is that possible you have added some kind of interceptor that is interfering with ours?
If not, I need some more context to repoduce.

@EdikxXx
Copy link
Author

EdikxXx commented Nov 26, 2024

Yes, I use the Sentry SDK, and it is possible that an interceptor from the Sentry SDK could be causing the issue.

@vhaldemar
Copy link
Collaborator

yeah, I can see https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/grpc/aio/client.py#L23

I think I will fix this problem in week or two, after I will finish with some product features.
For now I could only recommend do not use gprc integration of sentry.

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