Skip to content

Commit 89a159e

Browse files
committed
dont send empty strings
1 parent a999e3d commit 89a159e

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

app/makeReal.tsx

+15-20
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,17 @@ export async function makeReal(editor: Editor) {
4444
// It's okay if this is undefined—it will just mean that we'll use the
4545
// one in the .env file instead.
4646
const apiKeyFromDangerousApiKeyInput = (
47-
document.body.querySelector(
48-
'#openai_key_risky_but_cool'
49-
) as HTMLInputElement
47+
document.body.querySelector('#openai_key_risky_but_cool') as HTMLInputElement
5048
)?.value
5149

5250
// make a request to openai. `fetchFromOpenAi` is a next.js server action,
5351
// so our api key is hidden.
54-
const openAiResponse = await fetchFromOpenAi(
55-
apiKeyFromDangerousApiKeyInput,
56-
{
57-
model: 'gpt-4-vision-preview',
58-
max_tokens: 4096,
59-
temperature: 0,
60-
messages: prompt,
61-
}
62-
)
52+
const openAiResponse = await fetchFromOpenAi(apiKeyFromDangerousApiKeyInput, {
53+
model: 'gpt-4-vision-preview',
54+
max_tokens: 4096,
55+
temperature: 0,
56+
messages: prompt,
57+
})
6358

6459
// populate the response shape with the html we got back from openai.
6560
populateResponseShape(editor, responseShapeId, openAiResponse)
@@ -86,11 +81,11 @@ async function buildPromptForOpenAi(editor: Editor): Promise<GPT4VMessage[]> {
8681
type: 'text',
8782
text: 'Turn this into a single html file using tailwind.',
8883
},
89-
{
90-
// send the text of all selected shapes, so that GPT can use it as a reference (if anything is hard to see)
91-
type: 'text',
92-
text: getSelectionAsText(editor),
93-
}
84+
{
85+
// send the text of all selected shapes, so that GPT can use it as a reference (if anything is hard to see)
86+
type: 'text',
87+
text: getSelectionAsText(editor),
88+
},
9489
]
9590

9691
// if the user has selected a previous response from gpt-4, include that too. hopefully gpt-4 will
@@ -166,8 +161,7 @@ function getContentOfPreviousResponse(editor: Editor) {
166161

167162
function getSelectionAsText(editor: Editor) {
168163
const selectedShapeIds = editor.getSelectedShapeIds()
169-
const selectedShapeDescendantIds =
170-
editor.getShapeAndDescendantIds(selectedShapeIds)
164+
const selectedShapeDescendantIds = editor.getShapeAndDescendantIds(selectedShapeIds)
171165

172166
const texts = Array.from(selectedShapeDescendantIds)
173167
.map((id) => {
@@ -182,8 +176,9 @@ function getSelectionAsText(editor: Editor) {
182176
// @ts-expect-error
183177
return shape.props.text
184178
}
179+
return null
185180
})
186-
.filter((v) => v !== null)
181+
.filter((v) => v !== null && v !== '')
187182

188183
return texts.join('\n')
189184
}

0 commit comments

Comments
 (0)