Skip to content

Commit

Permalink
Dependencies: Fix OpenAPI generation
Browse files Browse the repository at this point in the history
The vision module from the ExllamaV2 backend is used in files outside
the backends contained folder. Therefore, import ExllamaV2 as an
optional dependency here.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
bdashore3 committed Nov 22, 2024
1 parent 9cd7fca commit 242ff4f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backends/exllamav2/vision.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
"""Vision utilities for ExLlamaV2."""

import io
import aiohttp
import base64
import io
import re
from async_lru import alru_cache
from fastapi import HTTPException
from PIL import Image

from common import model
import aiohttp
from common.networking import (
handle_request_error,
)
from common.optional_dependencies import dependencies
from common.tabby_config import config
from fastapi import HTTPException
from exllamav2.generator import ExLlamaV2MMEmbedding
from async_lru import alru_cache

# Since this is used outside the Exl2 backend, the dependency
# may be optional
if dependencies.exllamav2:
from exllamav2.generator import ExLlamaV2MMEmbedding


async def get_image(url: str) -> Image:
Expand Down Expand Up @@ -55,8 +61,9 @@ async def get_image(url: str) -> Image:
return Image.open(io.BytesIO(bytes_image))


# Fetch the return type on runtime
@alru_cache(20)
async def get_image_embedding(url: str) -> ExLlamaV2MMEmbedding:
async def get_image_embedding(url: str) -> "ExLlamaV2MMEmbedding":
image = await get_image(url)
return model.container.vision_model.get_image_embeddings(
model=model.container.model,
Expand Down

0 comments on commit 242ff4f

Please sign in to comment.