-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Flow-Works/liquid-env
✨ feature: FlowGPT
- Loading branch information
Showing
11 changed files
with
198 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
API_KEY=fTAHXJ2_JgRsP9nVSnpZPQgoOIfQlmG7G5Br5A9SbKU |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
|
||
<link rel="stylesheet" href="/styles/style.css" /> | ||
<link rel="stylesheet" href="/styles/window.css" /> | ||
|
||
<link rel="stylesheet" href="/builtin/apps/styles/flowgpt.css" /> | ||
</head> | ||
|
||
<body> | ||
<div class="flowgpt"> | ||
<div class="fill"> | ||
</div> | ||
<form> | ||
<input/> | ||
<button>Send</button> | ||
</form> | ||
</div> | ||
|
||
<script src="/scripts/app.js" defer type="module"></script> | ||
<script src="/builtin/apps/scripts/flowgpt.js" defer type="module"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-env browser */ | ||
|
||
import { marked } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; | ||
|
||
const logs = []; | ||
document.querySelector('form').onsubmit = async (e) => { | ||
e.preventDefault(); | ||
|
||
const you = new ChatLog('You'); | ||
const gpt = new ChatLog('FlowGPT'); | ||
|
||
const value = document.querySelector('input').value; | ||
document.querySelector('input').value = ''; | ||
|
||
document.querySelector('button').disabled = true; | ||
logs.push({ role: 'user', content: value }); | ||
you.set(value); | ||
|
||
const res = await fetch('http://localhost:3000' + '/ai/chat', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ logs: [ ...logs, { role: 'user', content: value } ] }) | ||
}); | ||
|
||
const data = await res.json(); | ||
|
||
logs.push(data); | ||
gpt.set(data.content); | ||
document.querySelector('button').disabled = false; | ||
}; | ||
|
||
class ChatLog { | ||
constructor(name) { | ||
this.name = name; | ||
this.div = document.createElement('div'); | ||
this.div.innerHTML += `<b>${name}</b>: <img src="/assets/loading.gif" style="position:relative;top:2.5px;" width="15px"/><br/><br/>`; | ||
document.querySelector('.fill').appendChild(this.div); | ||
} | ||
|
||
set = (content) => { | ||
this.div.innerHTML = `<b>${this.name}</b>: ${marked.parse(content)}<br/><br/>`; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.flowgpt { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.fill { | ||
flex: 1; | ||
} | ||
|
||
form { | ||
display: flex; | ||
gap: 10px; | ||
} | ||
|
||
form textarea { | ||
flex: 1; | ||
} | ||
|
||
form button { | ||
width: unset; | ||
} | ||
|
||
p { | ||
display: inline; | ||
} | ||
|
||
code { | ||
background: var(--surface-bg); | ||
padding: 2px; | ||
border-radius: 2px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Configuration, OpenAIApi } from 'openai'; | ||
import 'dotenv/config'; | ||
|
||
const configuration = new Configuration({ | ||
apiKey: process.env.API_KEY, | ||
basePath: 'https://chimeragpt.adventblocks.cc/v1' | ||
}); | ||
|
||
const openai = new OpenAIApi(configuration); | ||
|
||
const ai = (app, opts, done) => { | ||
app.addContentTypeParser('application/json', { parseAs: 'string' }, (req, body, done) => { | ||
try { | ||
const json = JSON.parse(body); | ||
done(null, json); | ||
} catch (err) { | ||
err.statusCode = 400; | ||
done(err, undefined); | ||
} | ||
}); | ||
|
||
app.post('/chat', async (req, res) => { | ||
const chatCompletion = await openai.createChatCompletion({ | ||
model: 'gpt-3.5-turbo', | ||
messages: req.body.logs, | ||
}); | ||
return res.send(chatCompletion.data.choices[0].message); | ||
}); | ||
|
||
done(); | ||
}; | ||
|
||
export default ai; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -527,6 +527,11 @@ async-exit-hook@^2.0.1: | |
resolved "https://registry.npmjs.org/async-exit-hook/-/async-exit-hook-2.0.1.tgz" | ||
integrity sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw== | ||
|
||
asynckit@^0.4.0: | ||
version "0.4.0" | ||
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" | ||
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== | ||
|
||
at-least-node@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz" | ||
|
@@ -546,6 +551,13 @@ avvio@^8.2.1: | |
debug "^4.0.0" | ||
fastq "^1.6.1" | ||
|
||
axios@^0.26.0: | ||
version "0.26.1" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9" | ||
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA== | ||
dependencies: | ||
follow-redirects "^1.14.8" | ||
|
||
balanced-match@^1.0.0: | ||
version "1.0.2" | ||
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" | ||
|
@@ -777,6 +789,13 @@ color-name@~1.1.4: | |
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" | ||
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== | ||
|
||
combined-stream@^1.0.8: | ||
version "1.0.8" | ||
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" | ||
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== | ||
dependencies: | ||
delayed-stream "~1.0.0" | ||
|
||
commander@^10.0.1: | ||
version "10.0.1" | ||
resolved "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz" | ||
|
@@ -949,6 +968,11 @@ defaults@^1.0.3: | |
dependencies: | ||
clone "^1.0.2" | ||
|
||
delayed-stream@~1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" | ||
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz" | ||
|
@@ -986,6 +1010,11 @@ dotenv@^16.0.3: | |
resolved "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz" | ||
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== | ||
|
||
dotenv@^16.3.1: | ||
version "16.3.1" | ||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" | ||
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== | ||
|
||
duplexify@^3.5.0: | ||
version "3.7.1" | ||
resolved "https://registry.npmjs.org/duplexify/-/duplexify-3.7.1.tgz" | ||
|
@@ -1428,6 +1457,20 @@ flatted@^3.1.0: | |
resolved "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz" | ||
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== | ||
|
||
follow-redirects@^1.14.8: | ||
version "1.15.2" | ||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" | ||
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== | ||
|
||
form-data@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" | ||
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== | ||
dependencies: | ||
asynckit "^0.4.0" | ||
combined-stream "^1.0.8" | ||
mime-types "^2.1.12" | ||
|
||
[email protected]: | ||
version "0.2.0" | ||
resolved "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz" | ||
|
@@ -2095,7 +2138,7 @@ [email protected], mime-db@^1.51.0: | |
resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz" | ||
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== | ||
|
||
mime-types@~2.1.24, mime-types@~2.1.34: | ||
mime-types@^2.1.12, mime-types@~2.1.24, mime-types@~2.1.34: | ||
version "2.1.35" | ||
resolved "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz" | ||
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== | ||
|
@@ -2269,6 +2312,14 @@ onetime@^5.1.0: | |
dependencies: | ||
mimic-fn "^2.1.0" | ||
|
||
openai@^3.3.0: | ||
version "3.3.0" | ||
resolved "https://registry.yarnpkg.com/openai/-/openai-3.3.0.tgz#a6408016ad0945738e1febf43f2fccca83a3f532" | ||
integrity sha512-uqxI/Au+aPRnsaQRe8CojU0eCR7I0mBiKjD3sNMzY6DaC1ZVrc85u98mtJW6voDug8fgGN+DIZmTDxTthxb7dQ== | ||
dependencies: | ||
axios "^0.26.0" | ||
form-data "^4.0.0" | ||
|
||
optionator@^0.8.1: | ||
version "0.8.3" | ||
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" | ||
|