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 7, 2024
1 parent 34df76a commit 94ab18b
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 71 deletions.
88 changes: 88 additions & 0 deletions static/chat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Warp</title>
</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>

<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
}

const decodedValue = decoder.decode(value)
const lines = decodedValue.split('\n')

let i = 0
while (i < lines.length) {
const line = lines[i]
if (line.length === 0) {
i++
continue
}

if (!line.startsWith('event: ')) {
responseText.innerHTML = `Unexpected event type line: ${line}`
return
}

const dataLine = lines[i + 1]
if (!dataLine.startsWith('data: ')) {
responseText.innerHTML = `Unexpected data line: ${dataLine}`
return
}

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})`
}

i += 2
}
}
}
</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.
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.
147 changes: 76 additions & 71 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,90 @@
<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
}

const decodedValue = decoder.decode(value)
const lines = decodedValue.split('\n')
<div id="main-illustration">
<img src="/images/main-illustration.svg" alt="Main Illustration" />
</div>

let i = 0
while (i < lines.length) {
const line = lines[i]
if (line.length === 0) {
i++
continue
}
<div id="greeting">
<h1>Welcome to</h1>
<h1>Platformatic Ai-Warp</h1>
</div>

if (!line.startsWith('event: ')) {
responseText.innerHTML = `Unexpected event type line: ${line}`
return
}
<div id="prompt-suggestions">
<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Prompt suggestion 1</p>
<p class="prompt-suggestion-subtitle">
Platformatic suggested prompt example 1
<span>
<a href="/chat.html?prompt=Prompt%20suggestion%201">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>
<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Prompt suggestion 2</p>
<p class="prompt-suggestion-subtitle">
Platformatic suggested prompt example 2
<span>
<a href="/chat.html?prompt=Prompt%20suggestion%202">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>
<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Prompt suggestion 3</p>
<p class="prompt-suggestion-subtitle">
Platformatic suggested prompt example 3
<span>
<a href="/chat.html?prompt=Prompt%20suggestion%203">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>
<div class="prompt-suggestion">
<p class="prompt-suggestion-title">Prompt suggestion 4</p>
<p class="prompt-suggestion-subtitle">
Platformatic suggested prompt example 4
<span>
<a href="/chat.html?prompt=Prompt%20suggestion%204">
<img src="/images/icons/arrow-long-right.svg" />
</a>
</span>
</p>
</div>
</div>

const dataLine = lines[i + 1]
if (!dataLine.startsWith('data: ')) {
responseText.innerHTML = `Unexpected data line: ${dataLine}`
return
}
<div id="prompt-input">
<input type="text" placeholder="Enter your prompt to Platformatic Ai Warp" />
</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})`
}
<div id="see-docs">
<a href="/documentation">View OpenAPI Documentation</a>
</div>

i += 2
}
}
}
</script>
<h1>icons</h1>
<img src="/images/icons/arrow-long-right.svg" />
<img src="/images/icons/checkmark.svg" />
<img src="/images/icons/copy.svg" />
<img src="/images/icons/edit.svg" />
<img src="/images/icons/regenerate.svg" />
<h1>avatars</h1>

<img src="/images/avatars/platformaticii.svg" />
<img src="/images/avatars/you.svg" />
</body>
</html>
17 changes: 17 additions & 0 deletions static/styles/common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
body {
background-color: #00050B;
padding: 0;
margin: 0;
color: white;
}

#navbar {
padding-top: 5px;
padding-bottom: 5px;
width: 100%;
border-bottom: 2px solid #FFFFFF26;
}

#navbar-logo {
padding-left: 60px;
}
79 changes: 79 additions & 0 deletions static/styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#main-illustration {
margin-top: 60px;
width: 100%;
text-align: center;
position: absolute;
}

#greeting {
padding-top: 450px;
text-align: center;
}

#prompt-suggestions {
width: 50%;
margin-left: 25%;
padding-top: 100px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}

.prompt-suggestion {
border: 1px solid #FFFFFF4D;
border-radius: 4px;
margin: 8px;
margin-left: 12px;
width: 45%;
}

.prompt-suggestion p {
margin-left: 8px;
margin-right: 8px;
}

.prompt-suggestion-title {
margin-top: 8px;
}

.prompt-suggestion-subtitle {
color: #FFFFFFB2;
margin-bottom: 8px;
}

.prompt-suggestion-subtitle a {
float: right;
}

#prompt-input {
width: 50%;
display: flex;
margin-top: 50px;
margin-left: 25%;
justify-content: center;
}

#prompt-input input {
width: 90%;
background-color: rgba(0, 0, 0, 0);
color: #FFFFFF;
padding: 10px;
border: 1px solid #FFFFFFB2;
border-radius: 4px;
}

#see-docs {
margin-top: 30px;
text-align: center;
}

#see-docs a {
padding-top: 12px;
padding-bottom: 12px;
padding-left: 8px;
padding-right: 8px;
border: 1px solid #FFFFFFB2;
border-radius: 4px;
text-decoration: none;
color: #FFFFFF;
}

0 comments on commit 94ab18b

Please sign in to comment.