Skip to content

Commit 5ce2ac4

Browse files
committed
fixed shadow bug in frontend and created controller
1 parent 65edd81 commit 5ce2ac4

File tree

7 files changed

+245
-31
lines changed

7 files changed

+245
-31
lines changed

.gitignore

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
############################
2+
# OS X
3+
############################
4+
5+
.DS_Store
6+
.AppleDouble
7+
.LSOverride
8+
Icon
9+
.Spotlight-V100
10+
.Trashes
11+
._*
12+
13+
14+
############################
15+
# Linux
16+
############################
17+
18+
*~
19+
20+
21+
############################
22+
# Windows
23+
############################
24+
25+
Thumbs.db
26+
ehthumbs.db
27+
Desktop.ini
28+
$RECYCLE.BIN/
29+
*.cab
30+
*.msi
31+
*.msm
32+
*.msp
33+
34+
35+
############################
36+
# Packages
37+
############################
38+
39+
*.7z
40+
*.csv
41+
*.dat
42+
*.dmg
43+
*.gz
44+
*.iso
45+
*.jar
46+
*.rar
47+
*.tar
48+
*.zip
49+
*.com
50+
*.class
51+
*.dll
52+
*.exe
53+
*.o
54+
*.seed
55+
*.so
56+
*.swo
57+
*.swp
58+
*.swn
59+
*.swm
60+
*.out
61+
*.pid
62+
63+
64+
############################
65+
# Logs and databases
66+
############################
67+
68+
.tmp
69+
*.log
70+
*.sql
71+
*.sqlite
72+
*.sqlite3
73+
74+
75+
############################
76+
# Misc.
77+
############################
78+
79+
*#
80+
ssl
81+
.idea
82+
nbproject
83+
public/uploads/*
84+
!public/uploads/.gitkeep
85+
86+
############################
87+
# Node.js
88+
############################
89+
90+
lib-cov
91+
lcov.info
92+
pids
93+
logs
94+
results
95+
node_modules
96+
.node_history
97+
98+
############################
99+
# Tests
100+
############################
101+
102+
testApp
103+
coverage
104+
105+
############################
106+
# Strapi
107+
############################
108+
109+
.env
110+
license.txt
111+
exports
112+
*.cache
113+
dist
114+
build
115+
.strapi-updater.json

admin/src/components/Input/index.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,32 @@ export default function Index({
5858
}
5959

6060
return (
61-
<Box>
62-
<Stack spacing={1}>
63-
<Stack spacing={1}>
64-
<TextInput
65-
placeholder="Please write a prompt for content to generate"
66-
label="Prompt" name="Prompt"
67-
onChange={e => setPrompt(e.target.value)} value={prompt} />
61+
<Stack spacing={1}>
62+
<TextInput
63+
placeholder="Please write a prompt for content to generate"
64+
label="Prompt"
65+
name="Prompt"
66+
onChange={(e) => setPrompt(e.target.value)}
67+
value={prompt}
68+
/>
69+
<Stack padding={4} spacing={2}>
70+
<Textarea
71+
placeholder="Generated text"
72+
label="Content"
73+
name="content"
74+
onChange={(e) =>
75+
onChange({
76+
target: { name, value: e.target.value, type: attribute.type },
77+
})
78+
}
79+
>
80+
{value}
81+
</Textarea>
82+
<Stack horizontal spacing={4}>
83+
<Button onClick={aiClick}>Generate</Button>
84+
<Button onClick={() => clearGeneratedText()}>Clear</Button>
6885
</Stack>
69-
<Box as="p" padding={4}>
70-
<Textarea
71-
placeholder="Generated text"
72-
label="Content"
73-
name="content"
74-
onChange={e => onChange({ target: { name, value: e.target.value, type: attribute.type } })}>
75-
{value}
76-
</Textarea>
77-
</Box>
7886
</Stack>
79-
<Box padding={4}>
80-
<TwoColsLayout
81-
startCol={<Button onClick={aiClick}>Generate</Button>}
82-
endCol={<Button onClick={() => clearGeneratedText()}>Clear</Button>
83-
}
84-
/>
85-
</Box>
86-
</Box>
87+
</Stack>
8788
)
8889
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"kind": "plugin",
99
"displayName": "AI Text Generation"
1010
},
11-
"dependencies": {},
11+
"dependencies": {
12+
"axios": "^1.2.2"
13+
},
1214
"author": {
1315
"name": "A Strapi developer"
1416
},
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

33
module.exports = ({ strapi }) => ({
4-
index(ctx) {
5-
ctx.body = strapi
4+
async generate(ctx) {
5+
ctx.body = await strapi
66
.plugin('ai-text-generation')
77
.service('myService')
8-
.getWelcomeMessage();
8+
.generate(ctx.request.body.prompt);
99
},
1010
});

server/routes/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = [
22
{
3-
method: 'GET',
4-
path: '/',
5-
handler: 'myController.index',
3+
method: 'POST',
4+
path: '/generate',
5+
handler: 'myController.generate',
66
config: {
77
policies: [],
88
},

server/services/my-service.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
'use strict';
22

3+
const axios = require('axios');
4+
5+
36
module.exports = ({ strapi }) => ({
47
getWelcomeMessage() {
58
return 'Welcome to Strapi 🚀';
69
},
10+
11+
async generate(prompt) {
12+
try {
13+
const response = await axios(
14+
{
15+
url: 'https://api.openai.com/v1/completions',
16+
method: 'POST',
17+
headers: {
18+
'Content-Type': 'application/json',
19+
'Authorization': `Bearer ${strapi.plugin('ai-text-generation').config('accessToken')}` //functionality to be added
20+
},
21+
data: JSON.stringify({
22+
'model': 'text-davinci-001',
23+
'prompt': `${prompt}`,
24+
'temperature': 0.4,
25+
'max_tokens': 64,
26+
'top_p': 1,
27+
'frequency_penalty': 0,
28+
'presence_penalty': 0
29+
})
30+
})
31+
32+
33+
const result = await response.data;
34+
console.log('response:', response.data)
35+
return result;
36+
}
37+
catch (err){
38+
console.log(err.response)
39+
}
40+
41+
}
42+
743
});

yarn.lock

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
asynckit@^0.4.0:
6+
version "0.4.0"
7+
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
8+
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
9+
10+
axios@^1.2.2:
11+
version "1.2.2"
12+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.2.tgz#72681724c6e6a43a9fea860fc558127dbe32f9f1"
13+
integrity sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==
14+
dependencies:
15+
follow-redirects "^1.15.0"
16+
form-data "^4.0.0"
17+
proxy-from-env "^1.1.0"
18+
19+
combined-stream@^1.0.8:
20+
version "1.0.8"
21+
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
22+
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
23+
dependencies:
24+
delayed-stream "~1.0.0"
25+
26+
delayed-stream@~1.0.0:
27+
version "1.0.0"
28+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
29+
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
30+
31+
follow-redirects@^1.15.0:
32+
version "1.15.2"
33+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
34+
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
35+
36+
form-data@^4.0.0:
37+
version "4.0.0"
38+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
39+
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
40+
dependencies:
41+
asynckit "^0.4.0"
42+
combined-stream "^1.0.8"
43+
mime-types "^2.1.12"
44+
45+
mime-db@1.52.0:
46+
version "1.52.0"
47+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
48+
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
49+
50+
mime-types@^2.1.12:
51+
version "2.1.35"
52+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
53+
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
54+
dependencies:
55+
mime-db "1.52.0"
56+
57+
proxy-from-env@^1.1.0:
58+
version "1.1.0"
59+
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
60+
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

0 commit comments

Comments
 (0)