Download src/http/openai/image-generation.ts from xjackkx/s2: direct link, hf CLI and curl.
- Browser
- Download file 811 Bytes
-
https://huggingface.co/spaces/xjackkx/s2/resolve/main/src/http/openai/image-generation.ts
- Command line
-
hf download hf://spaces/xjackkx/s2/src/http/openai/image-generation.ts
-
curl -L -o image-generation.ts https://huggingface.co/spaces/xjackkx/s2/resolve/main/src/http/openai/image-generation.ts
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; | |
| } | |