Skip to content

Commit af7f303

Browse files
committed
feat: add optional envvar for checking Ollama model
1 parent b11d6b4 commit af7f303

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

examples/image_search/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ We appreciate a star ⭐ at [CocoIndex Github](https://github.com/cocoindex-io/c
2828
```
2929
ollama pull gemma3
3030
ollama serve
31+
export OLLAMA_MODEL="gemma3" # Optional, for caption generation
3132
```
3233

3334
## Run the App

examples/image_search/main.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Any, Literal
77

88
import cocoindex
9-
import requests
109
import torch
1110
from dotenv import load_dotenv
1211
from fastapi import FastAPI, Query
@@ -24,15 +23,6 @@
2423
CLIP_MODEL_DIMENSION = 768
2524

2625

27-
def ollama_has_model(model) -> bool:
28-
try:
29-
r = requests.get(f"{OLLAMA_URL}/api/tags", timeout=1)
30-
r.raise_for_status()
31-
return any(m.get("name") == model for m in r.json().get("models", []))
32-
except Exception:
33-
return False
34-
35-
3626
@functools.cache
3727
def get_clip_model() -> tuple[CLIPModel, CLIPProcessor]:
3828
model = CLIPModel.from_pretrained(CLIP_MODEL_NAME)
@@ -81,8 +71,8 @@ def image_object_embedding_flow(
8171
)
8272
img_embeddings = data_scope.add_collector()
8373
with data_scope["images"].row() as img:
84-
has_gemma3 = ollama_has_model(OLLAMA_MODEL)
85-
if has_gemma3:
74+
has_ollama_model = os.getenv("OLLAMA_MODEL") == OLLAMA_MODEL
75+
if has_ollama_model:
8676
img["caption"] = flow_builder.transform(
8777
cocoindex.functions.ExtractByLlm(
8878
llm_spec=cocoindex.llm.LlmSpec(
@@ -115,7 +105,7 @@ def image_object_embedding_flow(
115105
"embedding": img["embedding"],
116106
}
117107

118-
if has_gemma3:
108+
if has_ollama_model:
119109
print(
120110
f"Ollama model '{OLLAMA_MODEL}' is available — captions will be extracted."
121111
)

examples/image_search/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies = [
1111
"transformers>=4.29.0",
1212
"qdrant-client>=1.14.2",
1313
"uvicorn>=0.34.3",
14-
"requests>=2.32.4",
1514
]
1615

1716
[tool.setuptools]

0 commit comments

Comments
 (0)