s2 / src /http /openai /image-generation.ts
xjackkx's picture
Upload 151 files
e81f4e4 verified
Raw History Blame Contribute Delete
811 Bytes
import { isRecord, type UnknownRecord } from "../../shared/types";
export type ImageGenerationMode = {
enabled: boolean;
forced: boolean;
tool: UnknownRecord | null;
};
export function imageGenerationMode(req: UnknownRecord): ImageGenerationMode {
const choice = isRecord(req.tool_choice) ? req.tool_choice : null;
if (choice && choice.type === "image_generation") {
return { enabled: true, forced: true, tool: choice };
}
const tools = Array.isArray(req.tools) ? req.tools : [];
for (const tool of tools) {
if (isRecord(tool) && tool.type === "image_generation") {
return { enabled: true, forced: false, tool };
}
}
return { enabled: false, forced: false, tool: null };
}
export function isImageGenerationRequest(req: UnknownRecord): boolean {
return imageGenerationMode(req).enabled;
}