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

Add default model for the nvidia classes in local NIM mode #14652

Merged
merged 28 commits into from
Aug 29, 2024

Conversation

raspawar
Copy link
Contributor

@raspawar raspawar commented Jul 9, 2024

Description

Provide default model using the first available model if none is provided for local NIM, e.g.
Settings.llm = NVIDIA(base_url="http://localhost:1234/v1")
query_engine = index.as_query_engine(similarity_top_k=20)
response = query_engine.query(
"How many new housing units were built in San Francisco in 2021?"
)
llm._client.model => default model => first available model in local NIM
Fixes # (issue)

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added new unit/integration tests
  • Added new notebook (that tests end-to-end)
  • I stared at the code and made sure it makes sense

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran make format; make lint to appease the lint gods

@sumitkbh

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 9, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@raspawar
Copy link
Contributor Author

raspawar commented Jul 9, 2024

@mattf please have a look

@logan-markewich
Copy link
Collaborator

Looks like this maybe broke tests?

Copy link
Contributor

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raspawar Logan is right. i just checked main vs this PR. main passes and PR fails -

FAILED tests/test_api_key.py::test_missing_api_key_error - AssertionError: assert '401' in '404 page not found'
FAILED tests/test_api_key.py::test_bogus_api_key_error - AssertionError: assert '401' in '404 page not found'
FAILED tests/test_embeddings_nvidia.py::test_nvidia_embedding_callback - openai.NotFoundError: 404 page not found
FAILED tests/test_embeddings_nvidia.py::test_nvidia_embedding_throws_with_invalid_key - openai.NotFoundError: 404 page not found

the 404 suggests the model name is being mangled, but in my testing it may be an issue w/ using the openai client.

>>> import os
>>> from openai import OpenAI
>>> client = OpenAI(api_key=os.environ["NVIDIA_API_KEY"], base_url="https://integrate.api.nvidia.com/v1")
>>> x = client.embeddings.create(input=['hello'], model="NV-Embed-QA", extra_body={"input_type": "query"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/resources/embeddings.py", line 114, in create
    return self._post(
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/_base_client.py", line 1266, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/_base_client.py", line 942, in request
    return self._request(
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/_base_client.py", line 1046, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: 404 page not found

@@ -146,14 +145,44 @@ def __init__(
)
self._aclient._custom_headers = {"User-Agent": "llama-index-embeddings-nvidia"}

if not model:
self.__set_default_model()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style comment, avoid side-effects: self.model = self.__get_default_model()

@raspawar
Copy link
Contributor Author

@raspawar Logan is right. i just checked main vs this PR. main passes and PR fails -

FAILED tests/test_api_key.py::test_missing_api_key_error - AssertionError: assert '401' in '404 page not found'
FAILED tests/test_api_key.py::test_bogus_api_key_error - AssertionError: assert '401' in '404 page not found'
FAILED tests/test_embeddings_nvidia.py::test_nvidia_embedding_callback - openai.NotFoundError: 404 page not found
FAILED tests/test_embeddings_nvidia.py::test_nvidia_embedding_throws_with_invalid_key - openai.NotFoundError: 404 page not found

the 404 suggests the model name is being mangled, but in my testing it may be an issue w/ using the openai client.

>>> import os
>>> from openai import OpenAI
>>> client = OpenAI(api_key=os.environ["NVIDIA_API_KEY"], base_url="https://integrate.api.nvidia.com/v1")
>>> x = client.embeddings.create(input=['hello'], model="NV-Embed-QA", extra_body={"input_type": "query"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/resources/embeddings.py", line 114, in create
    return self._post(
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/_base_client.py", line 1266, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/_base_client.py", line 942, in request
    return self._request(
  File "/home/matt/.cache/pypoetry/virtualenvs/llama-index-embeddings-nvidia-LEYbhevy-py3.10/lib/python3.10/site-packages/openai/_base_client.py", line 1046, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: 404 page not found

I will investigate this

@raspawar
Copy link
Contributor Author

@logan-markewich I have mocked the failing test case API calls, can you ptal?

Copy link
Contributor

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test for the embedding interface, then ok to merge

@mattf
Copy link
Contributor

mattf commented Jul 22, 2024

👍

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 24, 2024
@logan-markewich logan-markewich enabled auto-merge (squash) July 24, 2024 15:01
auto-merge was automatically disabled August 6, 2024 12:50

Head branch was pushed to by a user without write access

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't commit the lock files, they just take up space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, will remove it

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Aug 22, 2024
@raspawar raspawar force-pushed the raspawar/default-model branch 2 times, most recently from e154a39 to 528215d Compare August 22, 2024 17:00
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Aug 22, 2024
@logan-markewich
Copy link
Collaborator

Ok @raspawar fixed one issue with tests, now it's up to you :)

@logan-markewich logan-markewich merged commit d4c058b into run-llama:main Aug 29, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants