mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 14:47:40 +03:00
Remove extra details from ollama schema
This commit is contained in:
parent
b0819f09f4
commit
2f05ff2a96
@ -53,6 +53,39 @@ class OllamaClient(GenAIClient):
|
|||||||
logger.warning("Error initializing Ollama: %s", str(e))
|
logger.warning("Error initializing Ollama: %s", str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _clean_schema_for_ollama(schema: dict) -> dict:
|
||||||
|
"""Strip Pydantic metadata from a JSON schema for Ollama compatibility.
|
||||||
|
|
||||||
|
Ollama's grammar-based constrained generation works best with minimal
|
||||||
|
schemas. Pydantic adds title/description/constraint fields that can
|
||||||
|
cause the grammar generator to silently skip required fields.
|
||||||
|
"""
|
||||||
|
STRIP_KEYS = {
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"minimum",
|
||||||
|
"maximum",
|
||||||
|
"exclusiveMinimum",
|
||||||
|
"exclusiveMaximum",
|
||||||
|
}
|
||||||
|
result = {}
|
||||||
|
for key, value in schema.items():
|
||||||
|
if key in STRIP_KEYS:
|
||||||
|
continue
|
||||||
|
if isinstance(value, dict):
|
||||||
|
result[key] = OllamaClient._clean_schema_for_ollama(value)
|
||||||
|
elif isinstance(value, list):
|
||||||
|
result[key] = [
|
||||||
|
OllamaClient._clean_schema_for_ollama(item)
|
||||||
|
if isinstance(item, dict)
|
||||||
|
else item
|
||||||
|
for item in value
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
result[key] = value
|
||||||
|
return result
|
||||||
|
|
||||||
def _send(
|
def _send(
|
||||||
self,
|
self,
|
||||||
prompt: str,
|
prompt: str,
|
||||||
@ -73,7 +106,9 @@ class OllamaClient(GenAIClient):
|
|||||||
if response_format and response_format.get("type") == "json_schema":
|
if response_format and response_format.get("type") == "json_schema":
|
||||||
schema = response_format.get("json_schema", {}).get("schema")
|
schema = response_format.get("json_schema", {}).get("schema")
|
||||||
if schema:
|
if schema:
|
||||||
ollama_options["format"] = schema
|
ollama_options["format"] = self._clean_schema_for_ollama(
|
||||||
|
schema
|
||||||
|
)
|
||||||
result = self.provider.generate(
|
result = self.provider.generate(
|
||||||
self.genai_config.model,
|
self.genai_config.model,
|
||||||
prompt,
|
prompt,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user