Skip to content

Commit

Permalink
Simple Landing Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Moikapy committed Feb 9, 2023
1 parent 7b06787 commit 8c836f3
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 50 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"apollo-server-core": "^3.10.0",
"apollo-server-micro": "^3.10.2",
"auto-bind": "^5.0.1",
"axios": "^1.2.3",
"bignumber.js": "^9.1.0",
"bootstrap": "^5.2.1",
"dotenv": "^16.0.2",
Expand All @@ -33,6 +34,7 @@
"mime": "^3.0.0",
"next": "12.3.1",
"next-pwa": "^5.5.4",
"openai": "^3.1.0",
"orbit-db": "^0.28.6",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
97 changes: 97 additions & 0 deletions pages/api/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {Configuration, OpenAIApi} from 'openai';

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const MAX_TOKEN_LENGTH = 2048;
function truncatePrompt(prompt: string) {
if (prompt.length <= MAX_TOKEN_LENGTH) {
return prompt;
} else {
return prompt.substring(prompt.length - MAX_TOKEN_LENGTH, prompt.length);
}
}

export default async function (
req: {
body: {
prompt: string;
context: any;
};
},
res: {
status: (arg0: number) => {
(): any;
new (): any;
json: {
(arg0: {
error?: {message: string} | {message: string} | {message: string};
result?: any;
}): void;
new (): any;
};
};
}
) {
if (!configuration.apiKey) {
res.status(500).json({
error: {
message:
'OpenAI API key not configured, please follow instructions in README.md',
},
});
return;
}

const _text = req.body.prompt || '';
if (_text.length === 0) {
res.status(400).json({
error: {
message: 'Please enter message',
},
});
return;
}

try {
const completion = await openai.createCompletion({
model: 'text-davinci-003',
prompt: generatePrompt(_text),
temperature: 0.9,
max_tokens: 3500,
});

console.log(completion.data);
res.status(200).json({result: completion.data.choices[0].text});
} catch (error: any) {
// Consider adjusting the error handling logic for your use case
if (error.response) {
console.error(error.response.status, error.response.data);
res.status(error.response.status).json(error.response.data);
} else {
console.error(`Error with OpenAI API request: ${error.message}`);
res.status(500).json({
error: {
message: 'An error occurred during your request.',
},
});
}
}
}

function generatePrompt(text: any) {
// const _t = truncatePrompt(text);
return [
'!Only Responds If prompt Includes @AI!',
'This is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly. Only Responds If prompt Includes @AI',

'Developer: Moikapy',
'Twitter: @moikapy_',
'Github: https://github.com/moikapy',
'Twitch: https://www.twitch.tv/moikapy',
`Today's Date: ${new Date().toLocaleDateString()}`,
...text,
'...awaiting response from bot...',
].join('\n');
}
54 changes: 5 additions & 49 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ import H from '../src/components/common/H';
import {runTime} from '../dabu/helpers';
import Web3 from 'web3';
import TwitchEmbed from '@/src/components/blocks/TwitchEmbed';
import Chatbot from '@/src/components/ui/Chatbot';
import MoiLinkTree from '@/src/components/ui/MoiLinkTree';
var BN: any = Web3.utils.hexToNumberString;
// export async function getStaticProps(context: any, dabu: any) {
// const getLatestListed = async () => {
// // INIT Dabu
// var dabu = new DABU(process.env.AKKORO_ENV);
// console.log('dabu', dabu, await dabu.get_latest_nft_listing());
// //Get Active Listings
// const latestListing: any = await dabu.get_latest_nft_listing();

// return latestListing;
// };
// const {scriptDuration: duration, res: latestListing} = await runTime(
// getLatestListed
// );
// return {
// props: {
// latestListing: JSON.stringify(latestListing),
// scriptDuration: duration,
// },
// // - At most once every 10 seconds
// revalidate: 15, // In seconds
// };
// }

export default function Dragon({latestListing}: any): JSX.Element {
export default function Index(): JSX.Element {
return (
<>
<style jsx global>
Expand Down Expand Up @@ -79,32 +59,8 @@ export default function Dragon({latestListing}: any): JSX.Element {
twitter='moikaslookout'
keywords='gaming, nfts, web3'
/>
<div className='wrapper d-flex flex-column position-relative'>
<h1 className='mt-5'>Welcome!</h1>
{/* Our Contract Section */}
<div className=' mb-5'>
<h4>
<span className='border-bottom border-dark pe-5'>
Our Contracts
</span>
</h4>
<p className='fs-6'>
Ethereum Exchange Contract:{' '}
<a
target='_blank'
href='https://etherscan.com/address/0x61f46e5835434DC2990492336dF84C3Fbd1ac468'>
0x61f46e5835434DC2990492336dF84C3Fbd1ac468
</a>
</p>
<p className='fs-6'>
Polygon Exchange Contract:{' '}
<a
target={'_blank'}
href='https://polygonscan.com/address/0x342a4abec68e1cdd917d6f33fbf9665a39b14ded'>
0x342a4aBEc68E1cdD917D6f33fBF9665a39B14ded
</a>
</p>
</div>
<div className='wrapper d-flex flex-column justify-content-center align-items-center'>
<MoiLinkTree/>
</div>
</>
);
Expand Down
65 changes: 65 additions & 0 deletions src/components/ui/Chatbot/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, {useEffect, useState} from 'react';
import axios from 'axios';

function Chatbot() {
const [input, setInput] = useState('');
const [response, setResponse] = useState('');
const [pageText, setPageText] = useState('');
const [prompts, setPrompts] = useState<any>([]);
useEffect(() => {
setPageText(document.body.innerText);
}, []);
const handleInput = (event: {
target: {value: React.SetStateAction<string>};
}) => {
setInput(event.target.value);
};

const handleSubmit = async (event: {preventDefault: () => void}) => {
event.preventDefault();
prompts.push(input);
try {
let res: any = await fetch('/api/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({prompt: input}),
});
res = await res.json();
console.log(res);
setResponse(res.result);
} catch (err) {
console.error(err);
}
};

return (
<div className='container'>
<form onSubmit={handleSubmit}>
<div className='form-group'>
<label>Input:</label>
<input
className='form-control'
type='text'
value={input}
onChange={handleInput}
/>
</div>
<button className='btn btn-primary' type='submit'>
Submit
</button>
</form>
<div className='form-group'>
<label>Response:</label>
<textarea
className='form-control'
rows={5}
value={response}
readOnly></textarea>
</div>
</div>
);
}

export default Chatbot;
13 changes: 13 additions & 0 deletions src/components/ui/MoiLinkTree/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import MoiLinkTree from '.';
export default {
title: 'Components/UI/MoiLinkTree',
component: MoiLinkTree,
};

const Template = (args) => {
return <MoiLinkTree {...args} />;
};

export const Default = Template.bind({});

71 changes: 71 additions & 0 deletions src/components/ui/MoiLinkTree/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {useRouter} from 'next/router';
import styled from 'styled-components';
export const Button = styled.button`
background-color: #fefefe;
color: #000;
border: 1px solid #000;
padding: 0.5rem;
border-radius: 5px;
min-width: 200px;
`;
const links: {label: string; url: string}[] = [
{
label: 'Store',
url: 'https://moikaslookout.etsy.com',
},
{
label: 'Github',
url: 'https://github.com/moikapy',
},
{
label: 'Twitter',
url: 'https://twitter.com/moikaslookout',
},
{
label: 'Discord',
url: 'https://discord.gg/3Z5Y4Y4',
},
{
label: 'Twitch',
url: 'https://twitch.tv/moikapy',
},
{
label: 'Youtube',
url: 'https://youtube.com/moikapy',
},
{
label: 'Instagram',
url: 'https://instagram.com/moikapy',
},
];
export default function MoiLinkTree() {
const router = useRouter();
return (
<>
<style jsx>{`
.mlt {
max-width: 800px;
// background:#000;
}
`}</style>
<div className='mlt d-flex flex-column align-items-center'>
<h1 className=''>Welcome to Moika's Lookout!!</h1>
<p className='text-capitalize'>
A Simple Link Tree To Take you to all of our official links
</p>
{links.map((link) => {
return (
<div className='m-2'>
<Button
onClick={() => {
router.push(link?.url);
}}>
{link?.label}
</Button>
</div>
);
})}
</div>
</>
);
}
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8525,6 +8525,15 @@ axios@^0.27.2:
follow-redirects "^1.14.9"
form-data "^4.0.0"

axios@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.3.tgz#31a3d824c0ebf754a004b585e5f04a5f87e6c4ff"
integrity sha512-pdDkMYJeuXLZ6Xj/Q5J3Phpe+jbGdsSzlQaFVkMQzRUL05+6+tetX8TV3p4HrU4kzuO9bt+io/yGQxuyxA/xcw==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axobject-query@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-3.1.1.tgz#3b6e5c6d4e43ca7ba51c5babf99d22a9c68485e1"
Expand Down Expand Up @@ -12631,7 +12640,7 @@ focus-lock@^0.8.0:
dependencies:
tslib "^1.9.3"

follow-redirects@^1.10.0, follow-redirects@^1.14.0, follow-redirects@^1.14.7, follow-redirects@^1.14.8, follow-redirects@^1.14.9:
follow-redirects@^1.10.0, follow-redirects@^1.14.0, follow-redirects@^1.14.7, follow-redirects@^1.14.8, follow-redirects@^1.14.9, follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
Expand Down Expand Up @@ -18032,6 +18041,14 @@ open@^8.4.0:
is-docker "^2.1.1"
is-wsl "^2.2.0"

openai@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/openai/-/openai-3.1.0.tgz#13bfb228cf777155b882c2deb3a03bc5094cb7b3"
integrity sha512-v5kKFH5o+8ld+t0arudj833Mgm3GcgBnbyN9946bj6u7bvel4Yg6YFz2A4HLIYDzmMjIo0s6vSG9x73kOwvdCg==
dependencies:
axios "^0.26.0"
form-data "^4.0.0"

opencollective-postinstall@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259"
Expand Down Expand Up @@ -19283,6 +19300,11 @@ proxy-compare@2.4.0:
resolved "https://registry.yarnpkg.com/proxy-compare/-/proxy-compare-2.4.0.tgz#90f6abffe734ef86d8e37428c5026268606a9c1b"
integrity sha512-FD8KmQUQD6Mfpd0hywCOzcon/dbkFP8XBd9F1ycbKtvVsfv6TsFUKJ2eC0Iz2y+KzlkdT1Z8SY6ZSgm07zOyqg==

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

prr@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"
Expand Down

0 comments on commit 8c836f3

Please sign in to comment.