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 and test cases #17127

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docs/docs/examples/multi_modal/nvidia_multi_modal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
"llm = NVIDIAMultiModal()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"## To get available models use available_models property\n",
"llm.available_models"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -482,8 +492,7 @@
" [\n",
" ChatMessage(\n",
" role=\"user\",\n",
" content=f\"\"\"<img src=\"data:image/jpg;\n",
" ,{asset_id}\"/>\"\"\",\n",
" content=f\"\"\"Describe the Image: <img src=\"data:image/jpg;asset_id,{asset_id}\"/>\"\"\",\n",
" )\n",
" ]\n",
")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from llama_index.multi_modal_llms.nvidia.utils import (
BASE_URL,
DEFAULT_MODEL,
KNOWN_URLS,
NVIDIA_MULTI_MODAL_MODELS,
generate_nvidia_multi_modal_chat_message,
Expand All @@ -38,6 +39,7 @@
)
import aiohttp
import json
import warnings

from llama_index.core.bridge.pydantic import BaseModel

Expand Down Expand Up @@ -154,7 +156,7 @@ class NVIDIAMultiModal(MultiModalLLM):

def __init__(
self,
model: str = "microsoft/phi-3-vision-128k-instruct",
model: str = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isnt this Optional[str] now?

temperature: float = DEFAULT_TEMPERATURE,
max_tokens: Optional[int] = 300,
nvidia_api_key: Optional[str] = None,
Expand All @@ -177,6 +179,16 @@ def __init__(
"An API key is required for the hosted NIM. This will become an error in 0.2.0."
)

## set default model
if not model:
model = DEFAULT_MODEL
warnings.warn(
f"Default model is set as: {model}. \n"
"Set model using model parameter. \n"
"To get available models use available_models property.",
UserWarning,
)

super().__init__(
model=model,
temperature=temperature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import urllib
from llama_index.core.base.llms.types import ChatMessage

DEFAULT_MODEL = "microsoft/phi-3-vision-128k-instruct"
DEFAULT_MODEL = "nvidia/neva-22b"
BASE_URL = "https://ai.api.nvidia.com/v1/"

KNOWN_URLS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ license = "MIT"
name = "llama-index-multi-modal-llms-nvidia"
packages = [{include = "llama_index/"}]
readme = "README.md"
version = "0.3.0"
version = "0.3.1"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from llama_index.multi_modal_llms.nvidia import NVIDIAMultiModal
from llama_index.multi_modal_llms.nvidia.utils import (
NVIDIA_MULTI_MODAL_MODELS,
DEFAULT_MODEL,
)
import base64
import os
Expand Down Expand Up @@ -434,3 +435,15 @@ async def test_vlm_chat_async_stream(vlm_model: str) -> None:
async for token in await llm.astream_chat(messages):
assert isinstance(token, ChatResponse)
assert isinstance(token.delta, str)


def test_default_known() -> None:
"""
Test that a model in the model table will be accepted.
"""
# check if default model is getting set
with pytest.warns(UserWarning) as record:
x = NVIDIAMultiModal()
assert x.model == DEFAULT_MODEL
assert len(record) == 1
assert f"Default model is set as: {DEFAULT_MODEL}" in str(record[0].message)
Loading