Fraser commited on
Commit
5c6b653
·
1 Parent(s): 0959fa0

try md block

Browse files
src/lib/components/PicletGenerator/PicletGenerator.svelte CHANGED
@@ -330,7 +330,7 @@ Guidelines:
330
  - Add creature elements like tail, fins, claws, horns, etc where fitting
331
 
332
  Format your response exactly as follows:
333
-
334
  # Object Rarity
335
  {Assess how rare the object is based on real-world availability and value. Rare objects give strong monsters while common objects give weak ones. Use: common, uncommon, rare, or legendary}
336
 
@@ -338,7 +338,8 @@ Format your response exactly as follows:
338
  {Creative name that hints at the original object}
339
 
340
  ## Monster Visual Description
341
- {Detailed physical description showing how the object becomes a creature. Ensure the creature uses all the unique attributes of the object. Include colors, shapes, materials, eyes, limbs, mouth, and distinctive features. This section should be comprehensive as it will be used for both stats generation and image creation.}`;
 
342
 
343
  try {
344
  const responseText = await generateText(conceptPrompt);
@@ -347,8 +348,35 @@ Format your response exactly as follows:
347
  throw new Error('Failed to generate monster concept');
348
  }
349
 
350
- workflowState.picletConcept = responseText;
351
- console.log('Monster concept generated:', responseText);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  } catch (error) {
353
  handleAPIError(error);
354
  }
 
330
  - Add creature elements like tail, fins, claws, horns, etc where fitting
331
 
332
  Format your response exactly as follows:
333
+ \`\`\`md
334
  # Object Rarity
335
  {Assess how rare the object is based on real-world availability and value. Rare objects give strong monsters while common objects give weak ones. Use: common, uncommon, rare, or legendary}
336
 
 
338
  {Creative name that hints at the original object}
339
 
340
  ## Monster Visual Description
341
+ {Detailed physical description showing how the object becomes a creature. Ensure the creature uses all the unique attributes of the object. Include colors, shapes, materials, eyes, limbs, mouth, and distinctive features. This section should be comprehensive as it will be used for both stats generation and image creation.}
342
+ \`\`\``;
343
 
344
  try {
345
  const responseText = await generateText(conceptPrompt);
 
348
  throw new Error('Failed to generate monster concept');
349
  }
350
 
351
+ // Parse markdown code block response
352
+ let cleanedResponse = responseText.trim();
353
+
354
+ // Check if response is wrapped in markdown code blocks
355
+ if (cleanedResponse.includes('```')) {
356
+ // Handle different code block formats: ```md, ```, ```markdown
357
+ const codeBlockRegex = /```(?:md|markdown)?\s*\n([\s\S]*?)```/;
358
+ const match = cleanedResponse.match(codeBlockRegex);
359
+
360
+ if (match && match[1]) {
361
+ cleanedResponse = match[1].trim();
362
+ console.log('Extracted content from markdown code block');
363
+ } else {
364
+ // Fallback: try to extract content between any ``` blocks
365
+ const simpleMatch = cleanedResponse.match(/```([\s\S]*?)```/);
366
+ if (simpleMatch && simpleMatch[1]) {
367
+ cleanedResponse = simpleMatch[1].trim();
368
+ console.log('Extracted content from generic code block');
369
+ }
370
+ }
371
+ }
372
+
373
+ // Ensure the response starts with expected markdown headers
374
+ if (!cleanedResponse.includes('# Object Rarity') || !cleanedResponse.includes('# Monster Name')) {
375
+ console.warn('Response does not contain expected markdown structure');
376
+ }
377
+
378
+ workflowState.picletConcept = cleanedResponse;
379
+ console.log('Monster concept generated:', cleanedResponse);
380
  } catch (error) {
381
  handleAPIError(error);
382
  }