From 4908699574749124327075a7f6bc4c8a74059f4f Mon Sep 17 00:00:00 2001 From: Shiv Date: Sat, 18 Jun 2022 23:02:56 +0530 Subject: [PATCH 1/8] create lexy Signed-off-by: Shiv --- next.config.js | 1 + package.json | 1 + pages/api/lexy.js | 22 ++++++++++++ pages/lexy.js | 63 +++++++++++++++++++++++++++++++++++ styles/form-elements/Input.js | 3 ++ yarn.lock | 19 ++++++++++- 6 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 pages/api/lexy.js create mode 100644 pages/lexy.js diff --git a/next.config.js b/next.config.js index fc826606..a4fee172 100644 --- a/next.config.js +++ b/next.config.js @@ -6,6 +6,7 @@ module.exports = { webpack: function (config, options) { config.experiments = { topLevelAwait: true, + layers: true, } return config }, diff --git a/package.json b/package.json index 4ba16f37..01c4b64b 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "moralis": "^1.8.0", "next": "12.1.0", "node": "^17.4.0", + "openai": "^3.0.0", "react": "17.0.2", "react-dom": "17.0.2", "react-hook-form": "^7.30.0", diff --git a/pages/api/lexy.js b/pages/api/lexy.js new file mode 100644 index 00000000..0fe3886d --- /dev/null +++ b/pages/api/lexy.js @@ -0,0 +1,22 @@ +import { Configuration, OpenAIApi } from 'openai' + +const configuration = new Configuration({ + apiKey: process.env.OPENAI_API_KEY, +}) +const openai = new OpenAIApi(configuration) + +export default async function (req, res) { + const completion = await openai.createCompletion({ + model: 'text-davinci-002', + prompt: generatePrompt(req.body.question), + temperature: 1, + max_tokens: 2000, + stop: [' Human:', ' Lexy:'], + }) + console.log(completion.data.choices[0].text) + res.status(200).json({ result: completion.data.choices[0].text }) +} + +function generatePrompt(question) { + return `The following is a conversation with a female lawyer based in New York who specializes in crypto law. Her name is named Lexy. She has deep legal and technical knowledge. She is helpful, creative, intelligent, and very friendly. \n\nHuman: Hello, who are you?\nLexy: I am a bot created by KALI using OpenAI. How can I help you today?\nHuman: What is a UNA?\nLexy: A UNA is an "Unincorporated Non-Profit Association" that limits liabilities for its members without requiring state filling or registration for its members. It is essentially a partnership with a non-profit motive. It can pay taxes on their behalf and hold property in its own name. \nHuman: ${question}` +} diff --git a/pages/lexy.js b/pages/lexy.js new file mode 100644 index 00000000..59ec3509 --- /dev/null +++ b/pages/lexy.js @@ -0,0 +1,63 @@ +import React, { useState } from 'react' +import Layout from '../components/layout' +import { Flex, Box, Button } from '../styles/elements' +import { Form, Input } from '../styles/form-elements' +export default function lexy() { + const [question, setQuestion] = useState('') + const [answer, setAnswer] = useState() + const [loading, setLoading] = useState(false) + + async function submit(e) { + e.preventDefault() + setLoading(true) + const response = await fetch('/api/lexy', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ question: question }), + }) + const data = await response.json() + setAnswer(data.result) + // setQuestion('') + setLoading(false) + } + + return ( + + + + {answer} + +
+ setQuestion(e.target.value)} + /> + +
+
+
+ ) +} diff --git a/styles/form-elements/Input.js b/styles/form-elements/Input.js index fb486484..4fd6f2aa 100644 --- a/styles/form-elements/Input.js +++ b/styles/form-elements/Input.js @@ -91,6 +91,9 @@ const Input = styled('input', { }, }, textarea: { + display: 'flex', + alignItems: 'flex-start', + justifyContent: 'flex-start', padding: '0.5rem', width: '97%', minHeight: '10vh', diff --git a/yarn.lock b/yarn.lock index 5deb0c83..bce7a1aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2821,7 +2821,7 @@ axe-core@^4.3.5: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.2.tgz#dcf7fb6dea866166c3eab33d68208afe4d5f670c" integrity sha512-LVAaGp/wkkgYJcjmHsoKx4juT1aQvJyPcW09MLCjVTh3V2cc6PnyempiLMNH5iMdfIX/zdbjUx2KDjMLCTdPeA== -axios@0.26.1: +axios@0.26.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== @@ -4587,6 +4587,15 @@ form-data@^3.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" +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" + form-data@~2.3.2: version "2.3.3" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6" @@ -6123,6 +6132,14 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0: dependencies: wrappy "1" +openai@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/openai/-/openai-3.0.0.tgz#0816f1d72ee37820c9ff14d93d597431489fec37" + integrity sha512-YNAPZKzBfE6MnR5Ro/z3uKbg7T3F3W1FoTCtYheKRdEjZeheMX49QYFeL990gBFAhuGziEZCUdhnNT+eIrxX/Q== + dependencies: + axios "^0.26.0" + form-data "^4.0.0" + optionator@^0.9.1: version "0.9.1" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" From 61f6351574ed2907ef803eca9d11c283ae045df4 Mon Sep 17 00:00:00 2001 From: Shiv Date: Sat, 18 Jun 2022 23:06:39 +0530 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=90=9B=20fix=20syntax=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Shiv --- pages/lexy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pages/lexy.js b/pages/lexy.js index 59ec3509..82a4a3d7 100644 --- a/pages/lexy.js +++ b/pages/lexy.js @@ -2,7 +2,8 @@ import React, { useState } from 'react' import Layout from '../components/layout' import { Flex, Box, Button } from '../styles/elements' import { Form, Input } from '../styles/form-elements' -export default function lexy() { + +export default function LexyPage() { const [question, setQuestion] = useState('') const [answer, setAnswer] = useState() const [loading, setLoading] = useState(false) From 6375a0640acc959d195dcc3d163fde10fd8fe553 Mon Sep 17 00:00:00 2001 From: Shiv Date: Sun, 19 Jun 2022 01:41:04 +0530 Subject: [PATCH 3/8] update texting UI Signed-off-by: Shiv --- components/lexy/Send.js | 39 ++++++++++++++++++++++++ components/lexy/Text.js | 19 ++++++++++++ components/lexy/Texts.js | 19 ++++++++++++ components/lexy/index.js | 66 ++++++++++++++++++++++++++++++++++++++++ pages/api/lexy.js | 2 +- pages/lexy.js | 59 ++--------------------------------- 6 files changed, 147 insertions(+), 57 deletions(-) create mode 100644 components/lexy/Send.js create mode 100644 components/lexy/Text.js create mode 100644 components/lexy/Texts.js create mode 100644 components/lexy/index.js diff --git a/components/lexy/Send.js b/components/lexy/Send.js new file mode 100644 index 00000000..40032a41 --- /dev/null +++ b/components/lexy/Send.js @@ -0,0 +1,39 @@ +import React from 'react' +import { styled } from '../../styles/stitches.config' +import { Flex, Text, Button } from '../../styles/elements' +import { Form, Input } from '../../styles/form-elements' +import { PaperPlaneIcon } from '@radix-ui/react-icons' + +const Icon = styled(PaperPlaneIcon, { + transform: 'rotate(330deg)', +}) +export default function Send({ loading, submit, question, setQuestion }) { + return ( +
+ setQuestion(e.target.value)} + css={{ + fontFamily: 'Regular', + }} + /> + +
+ ) +} diff --git a/components/lexy/Text.js b/components/lexy/Text.js new file mode 100644 index 00000000..8570ea3b --- /dev/null +++ b/components/lexy/Text.js @@ -0,0 +1,19 @@ +import React from 'react' +import { Flex, Box } from '../../styles/elements' + +export default function Text({ text }) { + return ( + + {text?.text} + + ) +} diff --git a/components/lexy/Texts.js b/components/lexy/Texts.js new file mode 100644 index 00000000..b50a06ce --- /dev/null +++ b/components/lexy/Texts.js @@ -0,0 +1,19 @@ +import React from 'react' +import { Flex } from '../../styles/elements' +import Text from './Text' + +export default function Texts({ texts }) { + console.log('texts', texts) + return ( + + {texts.map((text, index) => ( + + ))} + + ) +} diff --git a/components/lexy/index.js b/components/lexy/index.js new file mode 100644 index 00000000..325d6aeb --- /dev/null +++ b/components/lexy/index.js @@ -0,0 +1,66 @@ +import { useState } from 'react' +import Send from './Send' +import Texts from './Texts' +import { Flex } from '../../styles/elements' + +export default function Lexy() { + const [texts, setTexts] = useState([ + { + name: 'Lexy', + text: 'Hi! I am Lexy. Ask me questions :)', + }, + ]) + const [question, setQuestion] = useState() + const [answer, setAnswer] = useState() + const [loading, setLoading] = useState(false) + + async function submit(e) { + e.preventDefault() + let textsArray = texts + let questionObj = {} + questionObj['name'] = 'Human' + questionObj['text'] = question + texts.push(questionObj) + + setLoading(true) + console.log('question', question) + const response = await fetch('/api/lexy', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ question: question }), + }) + const data = await response.json() + console.log('data', data.result) + setAnswer(data.result) + let answerObj = {} + answerObj['name'] = 'Lexy' + answerObj['text'] = data.result + textsArray.push(answerObj) + setTexts(textsArray) + setQuestion('') + setLoading(false) + } + + return ( + + + + + ) +} diff --git a/pages/api/lexy.js b/pages/api/lexy.js index 0fe3886d..7b349ad8 100644 --- a/pages/api/lexy.js +++ b/pages/api/lexy.js @@ -18,5 +18,5 @@ export default async function (req, res) { } function generatePrompt(question) { - return `The following is a conversation with a female lawyer based in New York who specializes in crypto law. Her name is named Lexy. She has deep legal and technical knowledge. She is helpful, creative, intelligent, and very friendly. \n\nHuman: Hello, who are you?\nLexy: I am a bot created by KALI using OpenAI. How can I help you today?\nHuman: What is a UNA?\nLexy: A UNA is an "Unincorporated Non-Profit Association" that limits liabilities for its members without requiring state filling or registration for its members. It is essentially a partnership with a non-profit motive. It can pay taxes on their behalf and hold property in its own name. \nHuman: ${question}` + return `The following is a conversation with a female lawyer based in New York who specializes in crypto law. Her name is named Lexy. She has deep legal and technical knowledge. She is helpful, creative, intelligent, and very friendly. \n\nHuman: Hello, who are you?\nLexy: I am a legal chatbot created by KALI using OpenAI. How can I help you today?\nHuman: What is a UNA?\nLexy: A UNA is an "Unincorporated Non-Profit Association" that limits liabilities for its members without requiring state filling or registration for its members. It is essentially a partnership with a non-profit motive. It can pay taxes on their behalf and hold property in its own name. \nHuman: ${question}` } diff --git a/pages/lexy.js b/pages/lexy.js index 82a4a3d7..2bf71639 100644 --- a/pages/lexy.js +++ b/pages/lexy.js @@ -1,64 +1,11 @@ -import React, { useState } from 'react' +import React from 'react' import Layout from '../components/layout' -import { Flex, Box, Button } from '../styles/elements' -import { Form, Input } from '../styles/form-elements' +import Lexy from '../components/lexy/index' export default function LexyPage() { - const [question, setQuestion] = useState('') - const [answer, setAnswer] = useState() - const [loading, setLoading] = useState(false) - - async function submit(e) { - e.preventDefault() - setLoading(true) - const response = await fetch('/api/lexy', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ question: question }), - }) - const data = await response.json() - setAnswer(data.result) - // setQuestion('') - setLoading(false) - } - return ( - - - {answer} - -
- setQuestion(e.target.value)} - /> - -
-
+
) } From 948cdcb014e2232dfb22c8292c3338398c1492fe Mon Sep 17 00:00:00 2001 From: Shiv Date: Sun, 19 Jun 2022 01:44:59 +0530 Subject: [PATCH 4/8] add create DAO button Signed-off-by: Shiv --- pages/lexy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pages/lexy.js b/pages/lexy.js index 2bf71639..16388f0b 100644 --- a/pages/lexy.js +++ b/pages/lexy.js @@ -1,11 +1,13 @@ import React from 'react' import Layout from '../components/layout' import Lexy from '../components/lexy/index' +import NewDaoSquare from '../components/my-daos/NewDaoSquare' export default function LexyPage() { return ( + ) } From 750039a8838ca5dc661a147d4715a15046b9ce47 Mon Sep 17 00:00:00 2001 From: Shiv Date: Sun, 19 Jun 2022 01:59:23 +0530 Subject: [PATCH 5/8] update text Signed-off-by: Shiv --- components/lexy/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/lexy/index.js b/components/lexy/index.js index 325d6aeb..1716ec5f 100644 --- a/components/lexy/index.js +++ b/components/lexy/index.js @@ -36,7 +36,7 @@ export default function Lexy() { setAnswer(data.result) let answerObj = {} answerObj['name'] = 'Lexy' - answerObj['text'] = data.result + answerObj['text'] = data.result.slice(6, -1) textsArray.push(answerObj) setTexts(textsArray) setQuestion('') From 0135572e0d5be714c0bebdbb4738ff8e2a7ccd42 Mon Sep 17 00:00:00 2001 From: Shiv Date: Sun, 19 Jun 2022 02:44:40 +0530 Subject: [PATCH 6/8] update text Signed-off-by: Shiv --- components/lexy/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/lexy/index.js b/components/lexy/index.js index 1716ec5f..4d11df84 100644 --- a/components/lexy/index.js +++ b/components/lexy/index.js @@ -36,7 +36,7 @@ export default function Lexy() { setAnswer(data.result) let answerObj = {} answerObj['name'] = 'Lexy' - answerObj['text'] = data.result.slice(6, -1) + answerObj['text'] = data.result.slice(7) textsArray.push(answerObj) setTexts(textsArray) setQuestion('') From b723c1ac0c092de5e16fba8e0228cd96926d831b Mon Sep 17 00:00:00 2001 From: Shiv Date: Mon, 20 Jun 2022 22:55:01 +0530 Subject: [PATCH 7/8] update lexy Signed-off-by: Shiv --- components/lexy/Claim.js | 34 ++++++++++++++++++++++++++++++++ components/lexy/Counter.js | 33 +++++++++++++++++++++++++++++++ components/lexy/Send.js | 2 ++ components/lexy/Text.js | 25 +++++++++++++++++++---- components/lexy/Vote.js | 14 +++++++++++++ components/lexy/index.js | 36 ++++++++++++++++++++++------------ components/my-daos/DaoCard.js | 1 - pages/api/lexy.js | 12 ++++++------ public/img/lexy.jpeg | Bin 0 -> 28144 bytes public/img/preview.png | Bin 0 -> 7693 bytes 10 files changed, 134 insertions(+), 23 deletions(-) create mode 100644 components/lexy/Claim.js create mode 100644 components/lexy/Counter.js create mode 100644 components/lexy/Vote.js create mode 100644 public/img/lexy.jpeg create mode 100644 public/img/preview.png diff --git a/components/lexy/Claim.js b/components/lexy/Claim.js new file mode 100644 index 00000000..a1a55340 --- /dev/null +++ b/components/lexy/Claim.js @@ -0,0 +1,34 @@ +import React from 'react' +import { useAccount, useContractWrite } from 'wagmi' +import { Button } from '../../styles/elements' + +// create a react component called Claim that renders a button that when clicked calls the claim function +export default function Claim() { + const { data: account } = useAccount() + const { isLoading: isClaimPending, writeAsync } = useContractWrite( + { + addressOrName: '', + contractInterface: '', + }, + 'claim', + ) + + const claim = async () => { + // claim function calls the claim function in the KaliToken contract on polygon using wagmi's useContractWrite hook + if (!account) return + } + return ( + + ) +} diff --git a/components/lexy/Counter.js b/components/lexy/Counter.js new file mode 100644 index 00000000..85b4affb --- /dev/null +++ b/components/lexy/Counter.js @@ -0,0 +1,33 @@ +import React from 'react' +import Claim from './Claim' +import { useAccount } from 'wagmi' +import { Flex, Box, Button } from '../../styles/elements' + +// a counter component that receieve a count prop +export default function Counter({ count }) { + const { data: account } = useAccount() + const claim = async () => { + if (!account) return + } + + return ( + + {count} KALI + + + ) +} diff --git a/components/lexy/Send.js b/components/lexy/Send.js index 40032a41..3a3e3cac 100644 --- a/components/lexy/Send.js +++ b/components/lexy/Send.js @@ -7,6 +7,7 @@ import { PaperPlaneIcon } from '@radix-ui/react-icons' const Icon = styled(PaperPlaneIcon, { transform: 'rotate(330deg)', }) + export default function Send({ loading, submit, question, setQuestion }) { return (
@@ -18,6 +19,7 @@ export default function Send({ loading, submit, question, setQuestion }) { onChange={(e) => setQuestion(e.target.value)} css={{ fontFamily: 'Regular', + borderRadius: '10px', }} />