Spaces:
Running
Running
Commit
·
a54215e
1
Parent(s):
8919651
update edit entities
Browse files
src/app/api/parsers/parseEntityPrompts.ts
CHANGED
@@ -2,7 +2,14 @@ import { ClapEntityPrompt } from "@aitube/client"
|
|
2 |
import { decode } from "js-base64"
|
3 |
|
4 |
export function parseClapEntityPrompts(input?: any): ClapEntityPrompt[] {
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
if (Array.isArray(basicResult)) {
|
7 |
return basicResult as ClapEntityPrompt[]
|
8 |
} else {
|
|
|
2 |
import { decode } from "js-base64"
|
3 |
|
4 |
export function parseClapEntityPrompts(input?: any): ClapEntityPrompt[] {
|
5 |
+
const inputStr = `${input || ""}`.trim()
|
6 |
+
|
7 |
+
// an empty string is a valid thing
|
8 |
+
if (!inputStr) {
|
9 |
+
return []
|
10 |
+
}
|
11 |
+
|
12 |
+
let basicResult = JSON.parse(decode(inputStr))
|
13 |
if (Array.isArray(basicResult)) {
|
14 |
return basicResult as ClapEntityPrompt[]
|
15 |
} else {
|
src/app/api/v1/edit/entities/index.ts
CHANGED
@@ -30,14 +30,17 @@ export async function editEntities({
|
|
30 |
// if we don't have existing entities, and user passed none,
|
31 |
// then we need to hallucinate them
|
32 |
if (existingClap.entities.length === 0 && entityPrompts.length === 0) {
|
|
|
33 |
const entityPromptsWithShots = await generateEntityPrompts({
|
34 |
prompt: existingClap.meta.description,
|
35 |
latentStory: await clapToLatentStory(existingClap)
|
36 |
})
|
37 |
|
|
|
|
|
38 |
for (const {
|
39 |
entityPrompt: { name, category, age, variant, region, identityImage, identityVoice },
|
40 |
-
shots
|
41 |
} of entityPromptsWithShots) {
|
42 |
const newEnt = newEntity({
|
43 |
category,
|
@@ -68,6 +71,18 @@ export async function editEntities({
|
|
68 |
})
|
69 |
|
70 |
existingClap.entities.push(newEnt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
}
|
73 |
|
|
|
30 |
// if we don't have existing entities, and user passed none,
|
31 |
// then we need to hallucinate them
|
32 |
if (existingClap.entities.length === 0 && entityPrompts.length === 0) {
|
33 |
+
|
34 |
const entityPromptsWithShots = await generateEntityPrompts({
|
35 |
prompt: existingClap.meta.description,
|
36 |
latentStory: await clapToLatentStory(existingClap)
|
37 |
})
|
38 |
|
39 |
+
const allShots = existingClap.segments.filter(s => s.category === "camera")
|
40 |
+
|
41 |
for (const {
|
42 |
entityPrompt: { name, category, age, variant, region, identityImage, identityVoice },
|
43 |
+
shots: entityShots
|
44 |
} of entityPromptsWithShots) {
|
45 |
const newEnt = newEntity({
|
46 |
category,
|
|
|
71 |
})
|
72 |
|
73 |
existingClap.entities.push(newEnt)
|
74 |
+
|
75 |
+
// now let's assign our entity to shots!
|
76 |
+
//
|
77 |
+
// warning: the shot assignment is the responsibility of the LLM.
|
78 |
+
// if the LLM hallucinates non-existing shot ids, it will cause trouble!
|
79 |
+
for (const shotId of entityShots) {
|
80 |
+
if (allShots[shotId]) {
|
81 |
+
allShots[shotId].entityId = newEnt.id
|
82 |
+
} else {
|
83 |
+
console.log(`[api/v1/edit/entities] warning: the LLM generated a non-existing shot (shot "${shotId}", but we only have ${allShots.length} shots)`)
|
84 |
+
}
|
85 |
+
}
|
86 |
}
|
87 |
}
|
88 |
|
src/app/api/v1/edit/entities/route.ts
CHANGED
@@ -10,8 +10,9 @@ import { editEntities } from "."
|
|
10 |
import { ClapCompletionMode } from "@aitube/client"
|
11 |
|
12 |
export async function POST(req: NextRequest) {
|
|
|
13 |
await throwIfInvalidToken(req.headers.get("Authorization"))
|
14 |
-
|
15 |
const qs = queryString.parseUrl(req.url || "")
|
16 |
const query = (qs || {}).query
|
17 |
|
|
|
10 |
import { ClapCompletionMode } from "@aitube/client"
|
11 |
|
12 |
export async function POST(req: NextRequest) {
|
13 |
+
console.log("Hello!")
|
14 |
await throwIfInvalidToken(req.headers.get("Authorization"))
|
15 |
+
console.log("world!")
|
16 |
const qs = queryString.parseUrl(req.url || "")
|
17 |
const query = (qs || {}).query
|
18 |
|