varg.ai-sdk 0.1.1 → 0.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +1 -1
- package/.env.example +3 -0
- package/.github/workflows/ci.yml +23 -0
- package/.husky/README.md +102 -0
- package/.husky/commit-msg +6 -0
- package/.husky/pre-commit +9 -0
- package/.husky/pre-push +6 -0
- package/.size-limit.json +8 -0
- package/.test-hooks.ts +5 -0
- package/CLAUDE.md +10 -3
- package/CONTRIBUTING.md +150 -0
- package/LICENSE.md +53 -0
- package/README.md +56 -209
- package/SKILLS.md +26 -10
- package/biome.json +7 -1
- package/bun.lock +1286 -0
- package/commitlint.config.js +22 -0
- package/docs/index.html +1130 -0
- package/docs/prompting.md +326 -0
- package/docs/react.md +834 -0
- package/docs/sdk.md +812 -0
- package/ffmpeg/CLAUDE.md +68 -0
- package/package.json +43 -10
- package/pipeline/cookbooks/scripts/animate-frames-parallel.ts +84 -0
- package/pipeline/cookbooks/scripts/combine-scenes.sh +53 -0
- package/pipeline/cookbooks/scripts/generate-frames-parallel.ts +99 -0
- package/pipeline/cookbooks/scripts/still-to-video.sh +37 -0
- package/pipeline/cookbooks/text-to-tiktok.md +669 -0
- package/pipeline/cookbooks/trendwatching.md +156 -0
- package/plan.md +281 -0
- package/scripts/.gitkeep +0 -0
- package/src/ai-sdk/cache.ts +142 -0
- package/src/ai-sdk/examples/cached-generation.ts +53 -0
- package/src/ai-sdk/examples/duet-scene-4.ts +53 -0
- package/src/ai-sdk/examples/duet-scene-5-audio.ts +32 -0
- package/src/ai-sdk/examples/duet-video.ts +56 -0
- package/src/ai-sdk/examples/editly-composition.ts +63 -0
- package/src/ai-sdk/examples/editly-test.ts +57 -0
- package/src/ai-sdk/examples/editly-video-test.ts +52 -0
- package/src/ai-sdk/examples/fal-lipsync.ts +43 -0
- package/src/ai-sdk/examples/higgsfield-image.ts +61 -0
- package/src/ai-sdk/examples/music-generation.ts +19 -0
- package/src/ai-sdk/examples/openai-sora.ts +34 -0
- package/src/ai-sdk/examples/replicate-bg-removal.ts +52 -0
- package/src/ai-sdk/examples/simpsons-scene.ts +61 -0
- package/src/ai-sdk/examples/talking-lion.ts +55 -0
- package/src/ai-sdk/examples/video-generation.ts +39 -0
- package/src/ai-sdk/examples/workflow-animated-girl.ts +104 -0
- package/src/ai-sdk/examples/workflow-before-after.ts +114 -0
- package/src/ai-sdk/examples/workflow-character-grid.ts +112 -0
- package/src/ai-sdk/examples/workflow-slideshow.ts +161 -0
- package/src/ai-sdk/file-cache.ts +112 -0
- package/src/ai-sdk/file.ts +238 -0
- package/src/ai-sdk/generate-element.ts +92 -0
- package/src/ai-sdk/generate-music.ts +46 -0
- package/src/ai-sdk/generate-video.ts +165 -0
- package/src/ai-sdk/index.ts +72 -0
- package/src/ai-sdk/music-model.ts +110 -0
- package/src/ai-sdk/providers/editly/editly.test.ts +1108 -0
- package/src/ai-sdk/providers/editly/ffmpeg.ts +60 -0
- package/src/ai-sdk/providers/editly/index.ts +817 -0
- package/src/ai-sdk/providers/editly/layers.ts +776 -0
- package/src/ai-sdk/providers/editly/plan.md +144 -0
- package/src/ai-sdk/providers/editly/types.ts +328 -0
- package/src/ai-sdk/providers/elevenlabs-provider.ts +255 -0
- package/src/ai-sdk/providers/fal-provider.ts +512 -0
- package/src/ai-sdk/providers/higgsfield.ts +379 -0
- package/src/ai-sdk/providers/openai.ts +251 -0
- package/src/ai-sdk/providers/replicate.ts +16 -0
- package/src/ai-sdk/video-model.ts +185 -0
- package/src/cli/commands/find.tsx +137 -0
- package/src/cli/commands/help.tsx +85 -0
- package/src/cli/commands/index.ts +6 -0
- package/src/cli/commands/list.tsx +238 -0
- package/src/cli/commands/render.tsx +71 -0
- package/src/cli/commands/run.tsx +511 -0
- package/src/cli/commands/which.tsx +253 -0
- package/src/cli/index.ts +114 -0
- package/src/cli/quiet.ts +44 -0
- package/src/cli/types.ts +32 -0
- package/src/cli/ui/components/Badge.tsx +29 -0
- package/src/cli/ui/components/DataTable.tsx +51 -0
- package/src/cli/ui/components/Header.tsx +23 -0
- package/src/cli/ui/components/HelpBlock.tsx +44 -0
- package/src/cli/ui/components/KeyValue.tsx +33 -0
- package/src/cli/ui/components/OptionRow.tsx +81 -0
- package/src/cli/ui/components/Separator.tsx +23 -0
- package/src/cli/ui/components/StatusBox.tsx +108 -0
- package/src/cli/ui/components/VargBox.tsx +51 -0
- package/src/cli/ui/components/VargProgress.tsx +36 -0
- package/src/cli/ui/components/VargSpinner.tsx +34 -0
- package/src/cli/ui/components/VargText.tsx +56 -0
- package/src/cli/ui/components/index.ts +19 -0
- package/src/cli/ui/index.ts +12 -0
- package/src/cli/ui/render.ts +35 -0
- package/src/cli/ui/theme.ts +63 -0
- package/src/cli/utils.ts +78 -0
- package/src/core/executor/executor.ts +201 -0
- package/src/core/executor/index.ts +13 -0
- package/src/core/executor/job.ts +214 -0
- package/src/core/executor/pipeline.ts +222 -0
- package/src/core/index.ts +11 -0
- package/src/core/registry/index.ts +9 -0
- package/src/core/registry/loader.ts +149 -0
- package/src/core/registry/registry.ts +221 -0
- package/src/core/registry/resolver.ts +206 -0
- package/src/core/schema/helpers.ts +134 -0
- package/src/core/schema/index.ts +8 -0
- package/src/core/schema/shared.ts +102 -0
- package/src/core/schema/types.ts +279 -0
- package/src/core/schema/validator.ts +92 -0
- package/src/definitions/actions/captions.ts +261 -0
- package/src/definitions/actions/edit.ts +298 -0
- package/src/definitions/actions/image.ts +125 -0
- package/src/definitions/actions/index.ts +114 -0
- package/src/definitions/actions/music.ts +205 -0
- package/src/definitions/actions/sync.ts +128 -0
- package/{action/transcribe/index.ts → src/definitions/actions/transcribe.ts} +58 -68
- package/src/definitions/actions/upload.ts +111 -0
- package/src/definitions/actions/video.ts +163 -0
- package/src/definitions/actions/voice.ts +119 -0
- package/src/definitions/index.ts +23 -0
- package/src/definitions/models/elevenlabs.ts +50 -0
- package/src/definitions/models/flux.ts +56 -0
- package/src/definitions/models/index.ts +36 -0
- package/src/definitions/models/kling.ts +56 -0
- package/src/definitions/models/llama.ts +54 -0
- package/src/definitions/models/nano-banana-pro.ts +102 -0
- package/src/definitions/models/sonauto.ts +68 -0
- package/src/definitions/models/soul.ts +65 -0
- package/src/definitions/models/wan.ts +54 -0
- package/src/definitions/models/whisper.ts +44 -0
- package/src/definitions/skills/index.ts +12 -0
- package/src/definitions/skills/talking-character.ts +87 -0
- package/src/definitions/skills/text-to-tiktok.ts +97 -0
- package/src/index.ts +118 -0
- package/src/providers/apify.ts +269 -0
- package/src/providers/base.ts +264 -0
- package/src/providers/elevenlabs.ts +217 -0
- package/src/providers/fal.ts +392 -0
- package/src/providers/ffmpeg.ts +544 -0
- package/src/providers/fireworks.ts +193 -0
- package/src/providers/groq.ts +149 -0
- package/src/providers/higgsfield.ts +145 -0
- package/src/providers/index.ts +143 -0
- package/src/providers/replicate.ts +147 -0
- package/src/providers/storage.ts +206 -0
- package/src/react/cli.ts +52 -0
- package/src/react/elements.ts +146 -0
- package/src/react/examples/branching.tsx +66 -0
- package/src/react/examples/captions-demo.tsx +37 -0
- package/src/react/examples/character-video.tsx +84 -0
- package/src/react/examples/grid.tsx +53 -0
- package/src/react/examples/layouts-demo.tsx +57 -0
- package/src/react/examples/madi.tsx +60 -0
- package/src/react/examples/music-test.tsx +35 -0
- package/src/react/examples/onlyfans-1m/workflow.tsx +88 -0
- package/src/react/examples/orange-portrait.tsx +41 -0
- package/src/react/examples/split-element-demo.tsx +60 -0
- package/src/react/examples/split-layout-demo.tsx +60 -0
- package/src/react/examples/split.tsx +41 -0
- package/src/react/examples/video-grid.tsx +46 -0
- package/src/react/index.ts +43 -0
- package/src/react/layouts/grid.tsx +28 -0
- package/src/react/layouts/index.ts +2 -0
- package/src/react/layouts/split.tsx +20 -0
- package/src/react/react.test.ts +309 -0
- package/src/react/render.ts +21 -0
- package/src/react/renderers/animate.ts +59 -0
- package/src/react/renderers/captions.ts +297 -0
- package/src/react/renderers/clip.ts +248 -0
- package/src/react/renderers/context.ts +17 -0
- package/src/react/renderers/image.ts +109 -0
- package/src/react/renderers/index.ts +22 -0
- package/src/react/renderers/music.ts +60 -0
- package/src/react/renderers/packshot.ts +84 -0
- package/src/react/renderers/progress.ts +173 -0
- package/src/react/renderers/render.ts +243 -0
- package/src/react/renderers/slider.ts +69 -0
- package/src/react/renderers/speech.ts +53 -0
- package/src/react/renderers/split.ts +91 -0
- package/src/react/renderers/subtitle.ts +16 -0
- package/src/react/renderers/swipe.ts +75 -0
- package/src/react/renderers/title.ts +17 -0
- package/src/react/renderers/utils.ts +124 -0
- package/src/react/renderers/video.ts +127 -0
- package/src/react/runtime/jsx-dev-runtime.ts +43 -0
- package/src/react/runtime/jsx-runtime.ts +35 -0
- package/src/react/types.ts +232 -0
- package/src/studio/index.ts +26 -0
- package/src/studio/scanner.ts +102 -0
- package/src/studio/server.ts +554 -0
- package/src/studio/stages.ts +251 -0
- package/src/studio/step-renderer.ts +279 -0
- package/src/studio/types.ts +60 -0
- package/src/studio/ui/cache.html +303 -0
- package/src/studio/ui/index.html +1820 -0
- package/src/tests/all.test.ts +509 -0
- package/src/tests/index.ts +33 -0
- package/src/tests/unit.test.ts +403 -0
- package/tsconfig.cli.json +8 -0
- package/tsconfig.json +21 -3
- package/TEST_RESULTS.md +0 -122
- package/action/captions/SKILL.md +0 -170
- package/action/captions/index.ts +0 -169
- package/action/edit/SKILL.md +0 -235
- package/action/edit/index.ts +0 -437
- package/action/image/SKILL.md +0 -140
- package/action/image/index.ts +0 -105
- package/action/sync/SKILL.md +0 -136
- package/action/sync/index.ts +0 -145
- package/action/transcribe/SKILL.md +0 -179
- package/action/video/SKILL.md +0 -116
- package/action/video/index.ts +0 -125
- package/action/voice/SKILL.md +0 -125
- package/action/voice/index.ts +0 -136
- package/cli/commands/find.ts +0 -58
- package/cli/commands/help.ts +0 -70
- package/cli/commands/list.ts +0 -49
- package/cli/commands/run.ts +0 -237
- package/cli/commands/which.ts +0 -66
- package/cli/discover.ts +0 -66
- package/cli/index.ts +0 -33
- package/cli/runner.ts +0 -65
- package/cli/types.ts +0 -49
- package/cli/ui.ts +0 -185
- package/index.ts +0 -75
- package/lib/README.md +0 -144
- package/lib/ai-sdk/fal.ts +0 -106
- package/lib/ai-sdk/replicate.ts +0 -107
- package/lib/elevenlabs.ts +0 -382
- package/lib/fal.ts +0 -467
- package/lib/ffmpeg.ts +0 -467
- package/lib/fireworks.ts +0 -235
- package/lib/groq.ts +0 -246
- package/lib/higgsfield.ts +0 -176
- package/lib/remotion/SKILL.md +0 -823
- package/lib/remotion/cli.ts +0 -115
- package/lib/remotion/functions.ts +0 -283
- package/lib/remotion/index.ts +0 -19
- package/lib/remotion/templates.ts +0 -73
- package/lib/replicate.ts +0 -304
- package/output.txt +0 -1
- package/test-import.ts +0 -7
- package/test-services.ts +0 -97
- package/utilities/s3.ts +0 -147
package/lib/groq.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* groq api wrapper for ultra-fast llm inference
|
|
5
|
-
* supports llama, mixtral, gemma models with blazing fast speeds
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import Groq from "groq-sdk";
|
|
9
|
-
import type { Uploadable } from "groq-sdk/uploads";
|
|
10
|
-
|
|
11
|
-
const groq = new Groq({
|
|
12
|
-
apiKey: process.env.GROQ_API_KEY || "",
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// types
|
|
16
|
-
export interface ChatCompletionOptions {
|
|
17
|
-
model?: string;
|
|
18
|
-
messages: Array<{
|
|
19
|
-
role: "system" | "user" | "assistant";
|
|
20
|
-
content: string;
|
|
21
|
-
}>;
|
|
22
|
-
temperature?: number;
|
|
23
|
-
maxTokens?: number;
|
|
24
|
-
stream?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface TranscriptionOptions {
|
|
28
|
-
file: Uploadable;
|
|
29
|
-
model?: string;
|
|
30
|
-
language?: string;
|
|
31
|
-
prompt?: string;
|
|
32
|
-
temperature?: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// popular models
|
|
36
|
-
export const GROQ_MODELS = {
|
|
37
|
-
// llama models (meta)
|
|
38
|
-
LLAMA_90B: "llama-3.3-70b-versatile",
|
|
39
|
-
LLAMA_8B: "llama-3.1-8b-instant",
|
|
40
|
-
LLAMA_70B: "llama-3.1-70b-versatile",
|
|
41
|
-
|
|
42
|
-
// mixtral models (mistral)
|
|
43
|
-
MIXTRAL_8X7B: "mixtral-8x7b-32768",
|
|
44
|
-
|
|
45
|
-
// gemma models (google)
|
|
46
|
-
GEMMA_7B: "gemma-7b-it",
|
|
47
|
-
GEMMA_2_9B: "gemma2-9b-it",
|
|
48
|
-
|
|
49
|
-
// whisper for audio transcription
|
|
50
|
-
WHISPER_LARGE: "whisper-large-v3",
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// core functions
|
|
54
|
-
export async function chatCompletion(options: ChatCompletionOptions) {
|
|
55
|
-
const {
|
|
56
|
-
model = GROQ_MODELS.LLAMA_90B,
|
|
57
|
-
messages,
|
|
58
|
-
temperature = 1,
|
|
59
|
-
maxTokens = 1024,
|
|
60
|
-
stream = false,
|
|
61
|
-
} = options;
|
|
62
|
-
|
|
63
|
-
if (!messages || messages.length === 0) {
|
|
64
|
-
throw new Error("messages array is required");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
console.log(`[groq] chat completion with ${model}...`);
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
if (stream) {
|
|
71
|
-
const streamResponse = await groq.chat.completions.create({
|
|
72
|
-
model,
|
|
73
|
-
messages,
|
|
74
|
-
temperature,
|
|
75
|
-
max_tokens: maxTokens,
|
|
76
|
-
stream: true,
|
|
77
|
-
});
|
|
78
|
-
console.log(`[groq] streaming response...`);
|
|
79
|
-
return streamResponse;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const response = await groq.chat.completions.create({
|
|
83
|
-
model,
|
|
84
|
-
messages,
|
|
85
|
-
temperature,
|
|
86
|
-
max_tokens: maxTokens,
|
|
87
|
-
stream: false,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const content = response.choices[0]?.message?.content || "";
|
|
91
|
-
console.log(`[groq] completed (${response.usage?.total_tokens} tokens)`);
|
|
92
|
-
return content;
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.error(`[groq] error:`, error);
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export async function transcribeAudio(options: TranscriptionOptions) {
|
|
100
|
-
const {
|
|
101
|
-
file,
|
|
102
|
-
model = GROQ_MODELS.WHISPER_LARGE,
|
|
103
|
-
language,
|
|
104
|
-
prompt,
|
|
105
|
-
temperature,
|
|
106
|
-
} = options;
|
|
107
|
-
|
|
108
|
-
if (!file) {
|
|
109
|
-
throw new Error("file is required");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
console.log(`[groq] transcribing audio with ${model}...`);
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
const response = await groq.audio.transcriptions.create({
|
|
116
|
-
file,
|
|
117
|
-
model,
|
|
118
|
-
language,
|
|
119
|
-
prompt,
|
|
120
|
-
temperature,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
console.log(`[groq] transcription completed`);
|
|
124
|
-
return response.text;
|
|
125
|
-
} catch (error) {
|
|
126
|
-
console.error(`[groq] error:`, error);
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export async function listModels() {
|
|
132
|
-
console.log(`[groq] fetching available models...`);
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
const response = await groq.models.list();
|
|
136
|
-
const models = Array.from(response.data);
|
|
137
|
-
console.log(`[groq] found ${models.length} models`);
|
|
138
|
-
return models;
|
|
139
|
-
} catch (error) {
|
|
140
|
-
console.error(`[groq] error:`, error);
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// cli
|
|
146
|
-
async function cli() {
|
|
147
|
-
const args = process.argv.slice(2);
|
|
148
|
-
const command = args[0];
|
|
149
|
-
|
|
150
|
-
if (!command || command === "help") {
|
|
151
|
-
console.log(`
|
|
152
|
-
usage:
|
|
153
|
-
bun run lib/groq.ts <command> [args]
|
|
154
|
-
|
|
155
|
-
commands:
|
|
156
|
-
chat <prompt> [model] chat completion
|
|
157
|
-
stream <prompt> [model] streaming chat completion
|
|
158
|
-
models list available models
|
|
159
|
-
help show this help
|
|
160
|
-
|
|
161
|
-
examples:
|
|
162
|
-
bun run lib/groq.ts chat "explain quantum computing"
|
|
163
|
-
bun run lib/groq.ts chat "write a haiku about cats" llama-3.1-8b-instant
|
|
164
|
-
bun run lib/groq.ts stream "tell me a story"
|
|
165
|
-
bun run lib/groq.ts models
|
|
166
|
-
|
|
167
|
-
popular models:
|
|
168
|
-
llama-3.3-70b-versatile - meta llama 3.3 70b (best quality)
|
|
169
|
-
llama-3.1-8b-instant - meta llama 3.1 8b (fastest)
|
|
170
|
-
llama-3.1-70b-versatile - meta llama 3.1 70b
|
|
171
|
-
mixtral-8x7b-32768 - mistral mixtral 8x7b
|
|
172
|
-
gemma2-9b-it - google gemma 2 9b
|
|
173
|
-
whisper-large-v3 - openai whisper (audio transcription)
|
|
174
|
-
|
|
175
|
-
environment:
|
|
176
|
-
GROQ_API_KEY - your groq api key
|
|
177
|
-
`);
|
|
178
|
-
process.exit(0);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
switch (command) {
|
|
183
|
-
case "chat": {
|
|
184
|
-
const prompt = args[1];
|
|
185
|
-
const model = args[2];
|
|
186
|
-
|
|
187
|
-
if (!prompt) {
|
|
188
|
-
throw new Error("prompt is required");
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const response = await chatCompletion({
|
|
192
|
-
model: model || GROQ_MODELS.LLAMA_90B,
|
|
193
|
-
messages: [{ role: "user", content: prompt }],
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
console.log(`\n${response}\n`);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
case "stream": {
|
|
201
|
-
const prompt = args[1];
|
|
202
|
-
const model = args[2];
|
|
203
|
-
|
|
204
|
-
if (!prompt) {
|
|
205
|
-
throw new Error("prompt is required");
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const stream = await chatCompletion({
|
|
209
|
-
model: model || GROQ_MODELS.LLAMA_90B,
|
|
210
|
-
messages: [{ role: "user", content: prompt }],
|
|
211
|
-
stream: true,
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
console.log("");
|
|
215
|
-
for await (const chunk of stream as AsyncIterable<{
|
|
216
|
-
choices: Array<{ delta: { content?: string } }>;
|
|
217
|
-
}>) {
|
|
218
|
-
const content = chunk.choices[0]?.delta?.content || "";
|
|
219
|
-
process.stdout.write(content);
|
|
220
|
-
}
|
|
221
|
-
console.log("\n");
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
case "models": {
|
|
226
|
-
const models = await listModels();
|
|
227
|
-
console.log(
|
|
228
|
-
`\navailable models:\n${models.map((m) => ` ${m.id} - ${m.owned_by}`).join("\n")}\n`,
|
|
229
|
-
);
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
default:
|
|
234
|
-
console.error(`unknown command: ${command}`);
|
|
235
|
-
console.log(`run 'bun run lib/groq.ts help' for usage`);
|
|
236
|
-
process.exit(1);
|
|
237
|
-
}
|
|
238
|
-
} catch (error) {
|
|
239
|
-
console.error(`[groq] error:`, error);
|
|
240
|
-
process.exit(1);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (import.meta.main) {
|
|
245
|
-
cli();
|
|
246
|
-
}
|
package/lib/higgsfield.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/**
|
|
3
|
-
* higgsfield client wrapper for soul image generation and character creation
|
|
4
|
-
* usage: bun run lib/higgsfield.ts <command> <args>
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
BatchSize,
|
|
9
|
-
HiggsfieldClient,
|
|
10
|
-
InputImageType,
|
|
11
|
-
SoulQuality,
|
|
12
|
-
SoulSize,
|
|
13
|
-
} from "@higgsfield/client";
|
|
14
|
-
|
|
15
|
-
const client = new HiggsfieldClient({
|
|
16
|
-
apiKey: process.env.HIGGSFIELD_API_KEY || process.env.HF_API_KEY,
|
|
17
|
-
apiSecret: process.env.HIGGSFIELD_SECRET || process.env.HF_API_SECRET,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export interface GenerateSoulArgs {
|
|
21
|
-
prompt: string;
|
|
22
|
-
widthAndHeight?: (typeof SoulSize)[keyof typeof SoulSize];
|
|
23
|
-
quality?: (typeof SoulQuality)[keyof typeof SoulQuality];
|
|
24
|
-
styleId?: string;
|
|
25
|
-
batchSize?: (typeof BatchSize)[keyof typeof BatchSize];
|
|
26
|
-
enhancePrompt?: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface CreateSoulIdArgs {
|
|
30
|
-
name: string;
|
|
31
|
-
imageUrls: string[];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function generateSoul(args: GenerateSoulArgs) {
|
|
35
|
-
console.log("[higgsfield] generating soul image");
|
|
36
|
-
console.log(`[higgsfield] prompt: ${args.prompt}`);
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const jobSet = await client.generate("/v1/text2image/soul", {
|
|
40
|
-
prompt: args.prompt,
|
|
41
|
-
width_and_height: args.widthAndHeight || SoulSize.PORTRAIT_1152x2048,
|
|
42
|
-
quality: args.quality || SoulQuality.HD,
|
|
43
|
-
style_id: args.styleId,
|
|
44
|
-
batch_size: args.batchSize || BatchSize.SINGLE,
|
|
45
|
-
enhance_prompt: args.enhancePrompt ?? false,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
console.log(`[higgsfield] job created: ${jobSet.id}`);
|
|
49
|
-
console.log(`[higgsfield] completed: ${jobSet.isCompleted}`);
|
|
50
|
-
|
|
51
|
-
return jobSet;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("[higgsfield] error:", error);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function listSoulStyles() {
|
|
59
|
-
console.log("[higgsfield] fetching soul styles");
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const styles = await client.getSoulStyles();
|
|
63
|
-
return styles;
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error("[higgsfield] error:", error);
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function createSoulId(args: CreateSoulIdArgs) {
|
|
71
|
-
console.log(`[higgsfield] creating soul id: ${args.name}`);
|
|
72
|
-
console.log(`[higgsfield] images: ${args.imageUrls.length}`);
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const soulId = await client.createSoulId({
|
|
76
|
-
name: args.name,
|
|
77
|
-
input_images: args.imageUrls.map((url) => ({
|
|
78
|
-
type: InputImageType.IMAGE_URL,
|
|
79
|
-
image_url: url,
|
|
80
|
-
})),
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
console.log(`[higgsfield] soul id created: ${soulId.id}`);
|
|
84
|
-
return soulId;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error("[higgsfield] error:", error);
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function listSoulIds(page = 1, pageSize = 20) {
|
|
92
|
-
console.log("[higgsfield] listing soul ids");
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const soulIds = await client.listSoulIds(page, pageSize);
|
|
96
|
-
return soulIds;
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error("[higgsfield] error:", error);
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// cli runner
|
|
104
|
-
if (import.meta.main) {
|
|
105
|
-
const [command, ...args] = process.argv.slice(2);
|
|
106
|
-
|
|
107
|
-
switch (command) {
|
|
108
|
-
case "generate_soul": {
|
|
109
|
-
if (!args[0]) {
|
|
110
|
-
console.log(`
|
|
111
|
-
usage:
|
|
112
|
-
bun run lib/higgsfield.ts generate_soul <prompt> [styleId]
|
|
113
|
-
`);
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
|
-
const soulResult = await generateSoul({
|
|
117
|
-
prompt: args[0],
|
|
118
|
-
styleId: args[1],
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// print job status and results
|
|
122
|
-
console.log(`\njob id: ${soulResult.id}`);
|
|
123
|
-
console.log(
|
|
124
|
-
`status: completed=${soulResult.isCompleted}, failed=${soulResult.isFailed}`,
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
if (soulResult.isCompleted && soulResult.jobs.length > 0) {
|
|
128
|
-
for (const job of soulResult.jobs) {
|
|
129
|
-
if (job.results) {
|
|
130
|
-
console.log(`\nimage url: ${job.results.raw.url}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
case "list_styles": {
|
|
138
|
-
const styles = await listSoulStyles();
|
|
139
|
-
console.log(JSON.stringify(styles, null, 2));
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
case "create_soul_id": {
|
|
144
|
-
if (!args[0] || !args[1]) {
|
|
145
|
-
console.log(`
|
|
146
|
-
usage:
|
|
147
|
-
bun run lib/higgsfield.ts create_soul_id <name> <imageUrl1> [imageUrl2...]
|
|
148
|
-
`);
|
|
149
|
-
process.exit(1);
|
|
150
|
-
}
|
|
151
|
-
const imageUrls = args.slice(1);
|
|
152
|
-
const soulIdResult = await createSoulId({
|
|
153
|
-
name: args[0],
|
|
154
|
-
imageUrls,
|
|
155
|
-
});
|
|
156
|
-
console.log(JSON.stringify(soulIdResult, null, 2));
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
case "list_soul_ids": {
|
|
161
|
-
const soulIds = await listSoulIds();
|
|
162
|
-
console.log(JSON.stringify(soulIds, null, 2));
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
default:
|
|
167
|
-
console.log(`
|
|
168
|
-
usage:
|
|
169
|
-
bun run lib/higgsfield.ts generate_soul <prompt> [styleId]
|
|
170
|
-
bun run lib/higgsfield.ts list_styles
|
|
171
|
-
bun run lib/higgsfield.ts create_soul_id <name> <imageUrl1> [imageUrl2...]
|
|
172
|
-
bun run lib/higgsfield.ts list_soul_ids
|
|
173
|
-
`);
|
|
174
|
-
process.exit(1);
|
|
175
|
-
}
|
|
176
|
-
}
|