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

[Bug]: validation context fails when underlying exception has keyword-only args #3233

Open
JuliusDegesys opened this issue Dec 3, 2024 · 0 comments · May be fixed by #3235
Open

[Bug]: validation context fails when underlying exception has keyword-only args #3233

JuliusDegesys opened this issue Dec 3, 2024 · 0 comments · May be fixed by #3235
Labels
bug Something isn't working

Comments

@JuliusDegesys
Copy link

What happened?

The following code throws a TypeError when validation_context tries to add context to the exception:

import chromadb
from chromadb.utils import embedding_functions

client = chromadb.HttpClient()
embedding_function = embedding_functions.OpenAIEmbeddingFunction(
    api_key="This is a bad key!",
    model_name="text-embedding-3-small",
)

client.delete_collection("test")
collection = client.create_collection("test", embedding_function=embedding_function)
collection.add(
    documents=["Hello, world!"],
    ids=["id1"],
)

Instead, it should throw an APIStatusError

Versions

Chroma version: 0.5.21
OpenAI version: 1.56.1
Python version: 3.12.7 (main, Oct 19 2024, 03:00:35) [GCC 12.2.0]
Operating System: linux
OS Version: #1 SMP Thu Oct 3 10:17:28 UTC 2024
OS Release: 6.10.11-linuxkit
Machine Architecture: aarch64

Relevant log output

Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 90, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 213, in _validate_and_prepare_add_request
    add_embeddings = self._embed_record_set(record_set=add_records)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 526, in _embed_record_set
    return self._embed(input=record_set[field])  # type: ignore[literal-required]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 539, in _embed
    return self._embedding_function(input=input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/chromadb/api/types.py", line 466, in __call__
    result = call(self, input)
             ^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/chromadb/utils/embedding_functions/openai_embedding_function.py", line 113, in __call__
    embeddings = self._client.create(
                 ^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/openai/resources/embeddings.py", line 124, in create
    return self._post(
           ^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1280, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 957, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1061, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: This is ******key!. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/debug.py", line 11, in <module>
    collection.add(
  File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/Collection.py", line 81, in add
    add_request = self._validate_and_prepare_add_request(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 93, in wrapper
    raise type(e)(msg).with_traceback(e.__traceback__)
          ^^^^^^^^^^^^
TypeError: APIStatusError.__init__() missing 2 required keyword-only arguments: 'response' and 'body'
@JuliusDegesys JuliusDegesys added the bug Something isn't working label Dec 3, 2024
@JuliusDegesys JuliusDegesys changed the title [Bug]: validation context fails when underlying exception is has keyword-only args [Bug]: validation context fails when underlying exception has keyword-only args Dec 3, 2024
JuliusDegesys added a commit to JuliusDegesys/chroma that referenced this issue Dec 3, 2024
When the type e has kwarg-only arguments, then the previous code fails.
@JuliusDegesys JuliusDegesys linked a pull request Dec 3, 2024 that will close this issue
1 task
JuliusDegesys added a commit to JuliusDegesys/chroma that referenced this issue Dec 3, 2024
When the embedding function raises an error with a kwarg-only constructor
arguments, then the validation_context wrapper code fails and raises a
TypeError.
JuliusDegesys added a commit to JuliusDegesys/chroma that referenced this issue Dec 3, 2024
When the embedding function raises an error with a kwarg-only constructor
arguments, then the validation_context wrapper code fails and raises a
TypeError.
JuliusDegesys added a commit to JuliusDegesys/chroma that referenced this issue Dec 3, 2024
When the embedding function raises an error with a kwarg-only constructor
arguments, then the validation_context wrapper code fails and raises a
TypeError.
JuliusDegesys added a commit to JuliusDegesys/chroma that referenced this issue Dec 3, 2024
When the embedding function raises an error with a kwarg-only constructor
arguments, then the validation_context wrapper code fails and raises a
TypeError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant