Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify parsing lifts
  • Loading branch information
anotherjesse committed Oct 8, 2024
commit f7dd266b44f0f60178a26a100f11a694efa498f6
24 changes: 8 additions & 16 deletions typescript/packages/lookslike-high-level/src/recipes/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ const prepText = lift(({ prompt }) => {
}
return {};
});
const grabText = lift(({ result, partial, pending }) => {
if (pending) {
return partial || ''
}
return result
})
const grabText = lift(({ partial }) => { return partial || '' })


const prepHTML = lift(({ prompt }) => {
Expand All @@ -35,21 +30,18 @@ const prepHTML = lift(({ prompt }) => {
}
return {};
});
const grabHtml = lift(({ result, partial, pending }) => {
if (pending) {
if (!partial) {
return ""
}
return partial.replace(/</g, "&lt;").replace(/>/g, "&gt;").slice(-1000);
const grabHtml = lift(({ partial, pending }) => {
if (!partial) {
return ""
}

if (!result) {
return "";
if (pending) {
return `<code>${partial.slice(-1000).replace(/</g, "&lt;").replace(/>/g, "&gt;").slice(-1000)}</code>`;
}

const html = result.match(/```html\n([\s\S]+?)```/)?.[1];
const html = partial.match(/```html\n([\s\S]+?)```/)?.[1];
if (!html) {
console.error("No HTML found in text", result);
console.error("No HTML found in text", partial);
return "";
}
return html
Expand Down