add the API key input

pull/58/head
Steve Ruiz 3 years ago
parent 2bee77bd17
commit 87ced25580

@ -14,7 +14,7 @@ Use JavaScript modules and unkpkg to import any necessary dependencies.
Respond ONLY with the contents of the html file.`
export async function POST(request: Request) {
const { image, html } = await request.json()
const { image, html, apiKey } = await request.json()
const body: GPT4VCompletionRequest = {
model: 'gpt-4-vision-preview',
max_tokens: 4096,
@ -53,7 +53,7 @@ export async function POST(request: Request) {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
Authorization: `Bearer ${apiKey ?? process.env.OPENAI_API_KEY}`,
},
body: JSON.stringify(body),
})

@ -0,0 +1,44 @@
import { Input } from '@tldraw/tldraw'
export function APIKeyInput() {
return (
<div
style={{
position: 'absolute',
bottom: 100,
width: '100%',
height: 50,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 99999,
}}
>
<div
style={{
background: 'var(--color-low)',
padding: 12,
borderRadius: 12,
display: 'flex',
gap: 8,
flexDirection: 'column',
}}
>
<div>
Have your own OpenAI API key? Use it instead. (Risky but cool)
</div>
<input
id="openai_key_risky_but_cool"
placeholder="OpenAPI Key"
style={{
width: '100%',
padding: 12,
fontSize: 'inherit',
fontFamily: 'inherit',
borderRadius: 8,
}}
/>
</div>
</div>
)
}

@ -83,6 +83,12 @@ export function ExportButton() {
body: JSON.stringify({
image: dataUrl,
html: previousHtml,
apiKey:
(
document.getElementById(
'openai_key_risky_but_cool'
) as HTMLInputElement
)?.value ?? null,
}),
})

@ -8,6 +8,7 @@ import React, { useEffect, useState } from 'react'
import { PreviewShapeUtil } from './PreviewShape/PreviewShape'
import { ExportButton } from './components/ExportButton'
import { useDialogs, useEditor } from '@tldraw/tldraw'
import { APIKeyInput } from './components/APIKeyInput'
const Tldraw = dynamic(async () => (await import('@tldraw/tldraw')).Tldraw, {
ssr: false,
@ -42,6 +43,7 @@ export default function Home() {
{/* <img src={lockup} style={{ height: 40, width: 'auto' }} /> */}
</a>
<DialogWarning />
<APIKeyInput />
</Tldraw>
</div>
</>

Loading…
Cancel
Save