mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-18 07:51:27 +00:00
Support specialist prompts and model unloads
This commit is contained in:
@@ -7,6 +7,7 @@ import requests
|
||||
|
||||
|
||||
DEFAULT_CAPTION_PROMPT_PATH = Path(__file__).parent / "prompts" / "caption.txt"
|
||||
DEFAULT_SPECIALIST_PROMPT_PATH = Path(__file__).parent / "prompts" / "caption_specialist.txt"
|
||||
|
||||
|
||||
def load_default_caption_prompt() -> str:
|
||||
@@ -16,11 +17,14 @@ def load_default_caption_prompt() -> str:
|
||||
return prompt
|
||||
|
||||
|
||||
def ensure_caption_prompt_file(prompt_path: Path) -> str:
|
||||
def ensure_prompt_file(prompt_path: Path, default_path: Path) -> str:
|
||||
prompt_path = prompt_path.expanduser().resolve()
|
||||
if not prompt_path.exists():
|
||||
prompt_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path.write_text(load_default_caption_prompt() + "\n", encoding="utf-8")
|
||||
prompt_path.write_text(
|
||||
default_path.read_text(encoding="utf-8").strip() + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
prompt = prompt_path.read_text(encoding="utf-8").strip()
|
||||
if not prompt:
|
||||
@@ -28,6 +32,14 @@ def ensure_caption_prompt_file(prompt_path: Path) -> str:
|
||||
return prompt
|
||||
|
||||
|
||||
def ensure_caption_prompt_file(prompt_path: Path) -> str:
|
||||
return ensure_prompt_file(prompt_path, DEFAULT_CAPTION_PROMPT_PATH)
|
||||
|
||||
|
||||
def ensure_specialist_prompt_file(prompt_path: Path) -> str:
|
||||
return ensure_prompt_file(prompt_path, DEFAULT_SPECIALIST_PROMPT_PATH)
|
||||
|
||||
|
||||
class OllamaCaptioner:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -76,3 +88,17 @@ class OllamaCaptioner:
|
||||
raise RuntimeError(f"Ollama returned no caption: {data}")
|
||||
|
||||
return " ".join(content.strip().split())
|
||||
|
||||
def unload(self) -> None:
|
||||
response = self.session.post(
|
||||
f"{self.url}/api/generate",
|
||||
json={
|
||||
"model": self.model,
|
||||
"keep_alive": 0,
|
||||
},
|
||||
timeout=self.timeout_seconds,
|
||||
)
|
||||
if not response.ok:
|
||||
raise RuntimeError(
|
||||
f"Ollama unload {response.status_code}: {response.text[:500]}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user