mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-28 17:34:41 +03:00
Enable ability to toggle thinking for local models genai review
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Review GenAI thinking toggle tests -- MEDIUM tier.
|
||||
*
|
||||
* Thinking can only be switched per request by providers that expose a
|
||||
* toggle, so the option is shown only when one of those providers holds the
|
||||
* descriptions role.
|
||||
*/
|
||||
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { test, expect } from "../../fixtures/frigate-test";
|
||||
import type { Page } from "@playwright/test";
|
||||
import { configFactory } from "../../fixtures/mock-data/config";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const CONFIG_SCHEMA = JSON.parse(
|
||||
readFileSync(
|
||||
resolve(__dirname, "../../fixtures/mock-data/config-schema.json"),
|
||||
"utf-8",
|
||||
),
|
||||
);
|
||||
|
||||
const SETTINGS_URL = "/settings?page=globalReview";
|
||||
|
||||
async function installRoutes(
|
||||
page: Page,
|
||||
genai: Record<string, { provider: string; model: string; roles: string[] }>,
|
||||
) {
|
||||
const config = configFactory({ genai } as never);
|
||||
|
||||
await page.route("**/api/config/schema.json", (route) =>
|
||||
route.fulfill({ json: CONFIG_SCHEMA }),
|
||||
);
|
||||
await page.route("**/api/config", (route) =>
|
||||
route.request().method() === "GET"
|
||||
? route.fulfill({ json: config })
|
||||
: route.fulfill({ json: { success: true } }),
|
||||
);
|
||||
await page.route("**/api/config/raw_paths", (route) =>
|
||||
route.fulfill({ json: {} }),
|
||||
);
|
||||
}
|
||||
|
||||
async function openGenAIConfig(page: Page) {
|
||||
await page.getByText("GenAI config", { exact: true }).click();
|
||||
await expect(page.locator("#pageRoot")).toContainText("Response style");
|
||||
}
|
||||
|
||||
test.describe("review genai thinking @medium", () => {
|
||||
test("is shown when the descriptions provider has a thinking toggle", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
await installRoutes(frigateApp.page, {
|
||||
local: { provider: "llamacpp", model: "m", roles: ["descriptions"] },
|
||||
});
|
||||
await frigateApp.goto(SETTINGS_URL);
|
||||
await openGenAIConfig(frigateApp.page);
|
||||
|
||||
await expect(frigateApp.page.locator("#pageRoot")).toContainText(
|
||||
"Enable thinking",
|
||||
);
|
||||
});
|
||||
|
||||
test("is hidden when the descriptions provider has no thinking toggle", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
// the chat provider supports the toggle, but descriptions go elsewhere
|
||||
await installRoutes(frigateApp.page, {
|
||||
local: { provider: "ollama", model: "m", roles: ["chat"] },
|
||||
cloud: { provider: "gemini", model: "m", roles: ["descriptions"] },
|
||||
});
|
||||
await frigateApp.goto(SETTINGS_URL);
|
||||
await openGenAIConfig(frigateApp.page);
|
||||
|
||||
await expect(frigateApp.page.locator("#pageRoot")).not.toContainText(
|
||||
"Enable thinking",
|
||||
);
|
||||
});
|
||||
|
||||
test("is hidden when no provider is configured", async ({ frigateApp }) => {
|
||||
await installRoutes(frigateApp.page, {});
|
||||
await frigateApp.goto(SETTINGS_URL);
|
||||
await openGenAIConfig(frigateApp.page);
|
||||
|
||||
await expect(frigateApp.page.locator("#pageRoot")).not.toContainText(
|
||||
"Enable thinking",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -689,6 +689,10 @@
|
||||
"label": "Response style",
|
||||
"description": "Writing style preset for generated review descriptions. Presets adjust the tone and level of detail of the user-facing title, summary, and scene description; 'default' leaves the built-in prompt unchanged."
|
||||
},
|
||||
"enable_thinking": {
|
||||
"label": "Enable thinking",
|
||||
"description": "Let the model reason before writing the review description. Only applies to models with a per-request thinking toggle (Ollama and llama.cpp providers); other models keep their default behavior. Thinking increases response time and token usage. When thumbnail saving is enabled, the reasoning is saved alongside the response."
|
||||
},
|
||||
"activity_context_prompt": {
|
||||
"label": "Activity context prompt",
|
||||
"description": "Custom prompt describing what is and is not suspicious activity to provide context for GenAI summaries."
|
||||
|
||||
@@ -1060,6 +1060,10 @@
|
||||
"label": "Response style",
|
||||
"description": "Writing style preset for generated review descriptions. Presets adjust the tone and level of detail of the user-facing title, summary, and scene description; 'default' leaves the built-in prompt unchanged."
|
||||
},
|
||||
"enable_thinking": {
|
||||
"label": "Enable thinking",
|
||||
"description": "Let the model reason before writing the review description. Only applies to models with a per-request thinking toggle (Ollama and llama.cpp providers); other models keep their default behavior. Thinking increases response time and token usage. When thumbnail saving is enabled, the reasoning is saved alongside the response."
|
||||
},
|
||||
"activity_context_prompt": {
|
||||
"label": "Activity context prompt",
|
||||
"description": "Custom prompt describing what is and is not suspicious activity to provide context for GenAI summaries."
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
import type { HiddenFieldContext } from "@/types/configForm";
|
||||
import type { SectionConfigOverrides } from "./types";
|
||||
|
||||
// Only these providers expose a per-request thinking toggle, so the option
|
||||
// has no effect when any other provider holds the descriptions role
|
||||
const THINKING_TOGGLE_PROVIDERS = new Set(["ollama", "llamacpp"]);
|
||||
|
||||
const hideThinkingWithoutToggle = (ctx: HiddenFieldContext): string[] => {
|
||||
const provider = Object.values(ctx.fullConfig.genai ?? {}).find((agent) =>
|
||||
agent.roles?.includes("descriptions"),
|
||||
)?.provider;
|
||||
return provider && THINKING_TOGGLE_PROVIDERS.has(provider)
|
||||
? []
|
||||
: ["genai.enable_thinking"];
|
||||
};
|
||||
|
||||
const review: SectionConfigOverrides = {
|
||||
base: {
|
||||
sectionDocs: "/configuration/review",
|
||||
@@ -98,6 +112,7 @@ const review: SectionConfigOverrides = {
|
||||
"genai.frame_mode": "/configuration/genai/genai_review#frame-mode",
|
||||
"genai.additional_concerns":
|
||||
"/configuration/genai/genai_review#additional-concerns",
|
||||
"genai.enable_thinking": "/configuration/genai/genai_review#thinking",
|
||||
},
|
||||
restartRequired: [],
|
||||
fieldOrder: ["alerts", "detections", "genai", "genai.enabled"],
|
||||
@@ -107,6 +122,7 @@ const review: SectionConfigOverrides = {
|
||||
"alerts.enabled_in_config",
|
||||
"detections.enabled_in_config",
|
||||
"genai.enabled_in_config",
|
||||
hideThinkingWithoutToggle,
|
||||
],
|
||||
advancedFields: [],
|
||||
uiSchema: {
|
||||
|
||||
Reference in New Issue
Block a user