Skip to content

Commit

Permalink
1.3.2 - accept all valid samplers and schedulers
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnrushefsky committed Aug 30, 2024
1 parent 34f909f commit b311896
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"build-binary": "tsc && pkg -t node18-linux-x64 --out-path bin . && cp src/*.py bin/"
"build-binary": "tsc && pkg -t node18-linux-x64 --out-path bin ."
},
"author": "Shawn Rushefsky",
"license": "MIT",
Expand Down
44 changes: 39 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,32 @@ interface ComfyDescription {
schedulers: string[];
}

function getPythonCommand(): string {
let pythonCommand = execSync(
"source /opt/ai-dock/etc/environment.sh && which python3",
{
encoding: "utf-8",
}
).trim();
if (!pythonCommand) {
pythonCommand = execSync(
"source /opt/ai-dock/etc/environment.sh && which python",
{
encoding: "utf-8",
}
).trim();
}
if (!pythonCommand) {
throw new Error("Python not found");
}
return pythonCommand;
}

function getComfyUIDescription(): ComfyDescription {
const temptComfyFilePath = path.join(
"/opt/ComfyUI",
"temp_comfy_description.json"
);
const pythonCode = `
import comfy.samplers
import json
Expand All @@ -59,23 +84,32 @@ comfy_description = {
"schedulers": comfy.samplers.KSampler.SCHEDULERS,
}
print(json.dumps(comfy_description, indent=2))
with open("${temptComfyFilePath}", "w") as f:
json.dump(comfy_description, f)
`;

const tempFilePath = path.join("/opt/ComfyUI", "temp_comfy_description.py");
const command = `
source /opt/ai-dock/etc/environment.sh \
&& source /opt/ai-dock/bin/venv-set.sh comfyui \
&& source "$COMFYUI_VENV/bin/activate" \
&& python ${tempFilePath}`;

try {
// Write the Python code to a temporary file
fs.writeFileSync(tempFilePath, pythonCode);

// Execute the Python script synchronously
const output = execSync(`python ${tempFilePath}`, {
execSync(command, {
cwd: "/opt/ComfyUI",
encoding: "utf-8",
shell: process.env.SHELL,
env: {
...process.env,
},
});

// Parse and return the JSON output
return JSON.parse(output) as ComfyDescription;
const output = fs.readFileSync(temptComfyFilePath, { encoding: "utf-8" });
return JSON.parse(output.trim()) as ComfyDescription;
} catch (error: any) {
throw new Error(`Failed to get ComfyUI description: ${error.message}`);
} finally {
Expand Down
6 changes: 6 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ server.register(fastifySwagger, {
});
server.register(fastifySwaggerUI, {
routePrefix: "/docs",
uiConfig: {
deepLinking: true,
},
});

server.after(() => {
Expand Down Expand Up @@ -340,6 +343,9 @@ export async function start() {

// Start the server
await server.listen({ port: config.wrapperPort, host: config.wrapperHost });
server.log.info(
`ComfyUI API ${version} listening on ${server.server.address}`
);
await warmupComfyUI();
warm = true;
const warmupTime = Date.now() - start;
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { FastifyBaseLogger } from "fastify";
import { CommandExecutor } from "./commands";
import fs from "fs";
import fsPromises from "fs/promises";
import { spawn } from "child_process";
import * as readline from "readline";
import { Readable } from "stream";
import path from "path";
import { randomUUID } from "crypto";
Expand Down

0 comments on commit b311896

Please sign in to comment.