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

feat: support image_input for image embeddings #12

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ You may use `/run` (asynchronous, start job and return job ID) or `/runsync` (sy
Inputs:
* `model`: name of one of the deployed models.
* `input`: single text string or list of texts to embed
* `image_input`: single url or list of urls to embed (for use with CLIP models)

### Reranking
Inputs:
Expand Down
22 changes: 22 additions & 0 deletions src/embedding_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ async def route_openai_get_embeddings(
embeddings, model=model_name, usage=usage
)

async def route_get_image_embeddings(
self,
image_input: str | list[str],
model_name: str,
return_as_list: bool = False,
):
"""returns embeddings for the input image urls"""
if not self.is_running:
await self.start()
if not isinstance(image_input, list):
image_input = [image_input]

embeddings, usage = await self.engine_array[model_name].image_embed(image_input)
Copy link

@Anzanda Anzanda Jan 16, 2025

Choose a reason for hiding this comment

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

This doesn't seem to work for me. Chainging the argument to images=image_input resolves the issue on my end.

if return_as_list:
return [
list_embeddings_to_response(embeddings, model=model_name, usage=usage)
]
else:
return list_embeddings_to_response(
embeddings, model=model_name, usage=usage
)

async def infinity_rerank(
self, query: str, docs: str, return_docs: str, model_name: str
):
Expand Down
6 changes: 6 additions & 0 deletions src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ async def async_generator_handler(job: dict[str, Any]):
"embedding_input": job_input.get("input"),
"model_name": job_input.get("model"),
}
# handle image urls (for image embeddings)
elif job_input.get("image_input"):
call_fn, kwargs = embedding_service.route_get_image_embeddings, {
"image_input": job_input.get("image_input"),
"model_name": job_input.get("model"),
}
else:
return create_error_response(f"Invalid input: {job}").model_dump()
try:
Expand Down