Skip to content

Commit

Permalink
Add designed index page
Browse files Browse the repository at this point in the history
  • Loading branch information
flakey5 committed May 9, 2024
1 parent cdb4bd4 commit 0472cb2
Show file tree
Hide file tree
Showing 16 changed files with 916 additions and 67 deletions.
34 changes: 34 additions & 0 deletions static/chat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat - AI Warp</title>

<link rel="stylesheet" href="/styles/common.css">
<link rel="stylesheet" href="/styles/chat.css">
</head>
<body>
<div id="navbar">
<a href="https://platformatic.dev">
<img id="navbar-logo" src="/images/platformatic-logo.svg" alt="Platformatic">
</a>
</div>

<div id="messages"></div>

<div id="prompt">
<input id="prompt-input" type="text" placeholder="Enter your prompt to Platformatic Ai-Warp" />
<button id="prompt-button" type="button">
<img src="/images/icons/arrow-long-right.svg" />
</button>
</div>

<div id="bottom-links">
<a href="/chat.html">Start a new chat</a>
<a href="/documentation">View OpenAPI Documentation</a>
</div>

<script src="/scripts/chat.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions static/images/avatars/platformatic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions static/images/avatars/you.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions static/images/icons/arrow-long-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions static/images/icons/checkmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions static/images/icons/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions static/images/icons/edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions static/images/icons/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions static/images/icons/regenerate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
246 changes: 246 additions & 0 deletions static/images/main-illustration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions static/images/platformatic-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 86 additions & 67 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,102 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Warp</title>

<link rel="stylesheet" href="/styles/common.css">
<link rel="stylesheet" href="/styles/index.css">
</head>
<body>
<div>
<label for="prompt-text">Prompt: </label>
<textarea name="prompt text" id="prompt-text" cols="60" rows="1"></textarea>
<button id="prompt-button">Prompt</button>
<div id="navbar">
<a href="https://platformatic.dev">
<img id="navbar-logo" src="/images/platformatic-logo.svg" alt="Platformatic">
</a>
</div>

<p id="response"></p>

<script>
const promptText = document.getElementById('prompt-text')
const responseText = document.getElementById('response')

const promptButton = document.getElementById('prompt-button')
promptButton.onclick = async () => {
const res = await fetch('/api/v1/stream', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
prompt: promptText.value
})
})

if (res.status !== 200) {
const { message, code } = await res.json()
responseText.innerHTML = `Error: ${message} (${code})`
return
}

responseText.innerHTML = ''

const reader = res.body.getReader()
const decoder = new TextDecoder()
while (true) {
const { done, value } = await reader.read()
if (done) {
break
}
<div id="main-illustration">
<img src="/images/main-illustration.svg" alt="Main Illustration" />
</div>

const decodedValue = decoder.decode(value)
const lines = decodedValue.split('\n')
<div id="greeting">
<h1>Welcome to</h1>
<h1>Platformatic Ai-Warp</h1>
</div>

let i = 0
while (i < lines.length) {
const line = lines[i]
if (line.length === 0) {
i++
continue
}
<div id="prompt-suggestions">
<div class="prompt-suggestion-column">
<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Generate SQL</p>
<p class="prompt-suggestion-subtitle">
for an ecommerce's online store
<span>
<a href="/chat.html?prompt=Please%20generate%20SQL%20for%20an%20ecommerce's%20online%20store">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>
<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Calculate</p>
<p class="prompt-suggestion-subtitle">
a mathematical formula
<span>
<a href="/chat.html?prompt=Please%20calculate%20the%20square%20root%20of%2016">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>
</div>

<div class="prompt-suggestion-column">
<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Generate a Fastify plugin</p>
<p class="prompt-suggestion-subtitle">
that provides a route for users to sign up with
<span>
<a href="/chat.html?prompt=Please%20generate%20Typescript%20for%20a%20Fastify%20plugin%20that%20provides%20a%20basic%20user%20signin%20route.">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>

<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Decode</p>
<p class="prompt-suggestion-subtitle">
a base64 string
<span>
<a href="/chat.html?prompt=Please%20decode%20this%20base64%20string%3A%20SGVsbG8gV29ybGQ%3D">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>
</div>
</div>

if (!line.startsWith('event: ')) {
responseText.innerHTML = `Unexpected event type line: ${line}`
return
}
<div id="custom-prompt">
<input id="custom-prompt-input" type="text" placeholder="Enter your prompt to Platformatic Ai Warp" />
<button id="custom-prompt-button" type="button">
<img src="/images/icons/arrow-long-right.svg" />
</button>
</div>

const dataLine = lines[i + 1]
if (!dataLine.startsWith('data: ')) {
responseText.innerHTML = `Unexpected data line: ${dataLine}`
return
}
<div id="bottom-links">
<a href="/documentation">View OpenAPI Documentation</a>
</div>

const eventType = line.substring('event: '.length)
const data = dataLine.substring('data: '.length)
const json = JSON.parse(data)
if (eventType === 'content') {
const { response } = json
responseText.innerHTML += response
} else if (eventType === 'error') {
const { message, code } = data
responseText.innerHTML = `Error: ${message} (${code})`
}
<script>
const promptInput = document.getElementById('custom-prompt-input')
const promptButton = document.getElementById('custom-prompt-button')
promptButton.onclick = () => {
if (promptInput.value !== '') {
document.location = `/chat.html?prompt=${encodeURIComponent(promptInput.value)}`
}
}

i += 2
}
promptInput.onkeydown = (event) => {
if (event.key === 'Enter') {
promptButton.onclick()
}
}
</script>
Expand Down
Loading

0 comments on commit 0472cb2

Please sign in to comment.