Spaces:
Running
on
Zero
Running
on
Zero
update
Browse files- controllers/lineprogram/.gpteng/memory/logs/all_output.txt +230 -0
- controllers/lineprogram/.gpteng/memory/logs/gen_entrypoint_chat.txt +192 -0
- controllers/lineprogram/appsscript.json +12 -0
- controllers/lineprogram/index.gs +21 -0
- controllers/lineprogram/linebot.gs +66 -0
- controllers/lineprogram/oauth2.gs +43 -0
- controllers/lineprogram/prompt +1 -0
- controllers/lineprogram/prompt.txt +5 -0
- controllers/lineprogram/requirements.txt +2 -0
- controllers/lineprogram/run.sh +8 -0
- controllers/programfromdoc/__init__.py +0 -0
- controllers/programfromdoc/programfromdoc.py +15 -0
- mysite/asgi.py +1 -1
- mysite/{gradio/gradio_config.py → router/router.py} +3 -12
controllers/lineprogram/.gpteng/memory/logs/all_output.txt
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
2024-06-09T20:39:33.225724
|
3 |
+
================================ System Message ================================
|
4 |
+
|
5 |
+
You will get instructions for code to write.
|
6 |
+
You will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code.
|
7 |
+
Think step by step and reason yourself to the correct decisions to make sure we get it right.
|
8 |
+
First lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose.
|
9 |
+
|
10 |
+
You will output the content of each file necessary to achieve the goal, including ALL code.
|
11 |
+
Represent files like so:
|
12 |
+
|
13 |
+
FILENAME
|
14 |
+
```
|
15 |
+
CODE
|
16 |
+
```
|
17 |
+
|
18 |
+
The following tokens must be replaced like so:
|
19 |
+
FILENAME is the lowercase combined path and file name including the file extension
|
20 |
+
CODE is the code in the file
|
21 |
+
|
22 |
+
Example representation of a file:
|
23 |
+
|
24 |
+
src/hello_world.py
|
25 |
+
```
|
26 |
+
print("Hello World")
|
27 |
+
```
|
28 |
+
|
29 |
+
Do not comment on what every file does. Please note that the code should be fully functional. No placeholders.
|
30 |
+
|
31 |
+
|
32 |
+
You will start with the "entrypoint" file, then go to the ones that are imported by that file, and so on.
|
33 |
+
Please note that the code should be fully functional. No placeholders.
|
34 |
+
|
35 |
+
Follow a language and framework appropriate best practice file naming convention.
|
36 |
+
Make sure that files contain all imports, types etc. The code should be fully functional. Make sure that code in different files are compatible with each other.
|
37 |
+
Ensure to implement all code, if you are unsure, write a plausible implementation.
|
38 |
+
Include module dependency or package manager dependency definition file.
|
39 |
+
Before you finish, double check that all parts of the architecture is present in the files.
|
40 |
+
|
41 |
+
When you are done, write finish with "this concludes a fully working implementation".
|
42 |
+
|
43 |
+
Useful to know:
|
44 |
+
Almost always put different classes in different files.
|
45 |
+
Always use the programming language the user asks for.
|
46 |
+
For Python, you always create an appropriate requirements.txt file.
|
47 |
+
For NodeJS, you always create an appropriate package.json file.
|
48 |
+
Always add a comment briefly describing the purpose of the function definition.
|
49 |
+
Add comments explaining very complex bits of logic.
|
50 |
+
Always follow the best practices for the requested languages for folder/file structure and how to package the project.
|
51 |
+
|
52 |
+
|
53 |
+
Python toolbelt preferences:
|
54 |
+
- pytest
|
55 |
+
- dataclasses
|
56 |
+
|
57 |
+
|
58 |
+
================================ Human Message =================================
|
59 |
+
|
60 |
+
Request: appsscriptでLINEプログラムの開発
|
61 |
+
|
62 |
+
================================== Ai Message ==================================
|
63 |
+
|
64 |
+
Here is a fully functional implementation of a LINE bot using Google Apps Script.
|
65 |
+
|
66 |
+
**requirements.txt**
|
67 |
+
```
|
68 |
+
google-api-python-client
|
69 |
+
oauth2client
|
70 |
+
```
|
71 |
+
|
72 |
+
**appsscript.json**
|
73 |
+
```
|
74 |
+
{
|
75 |
+
"timeZone": "Asia/Tokyo",
|
76 |
+
"dependencies": {
|
77 |
+
"enabledAdvancedServices": [
|
78 |
+
{
|
79 |
+
"userSymbol": "OAuth2",
|
80 |
+
"serviceId": "oauth2",
|
81 |
+
"version": "v2"
|
82 |
+
}
|
83 |
+
]
|
84 |
+
}
|
85 |
+
}
|
86 |
+
```
|
87 |
+
|
88 |
+
**linebot.gs**
|
89 |
+
```
|
90 |
+
/**
|
91 |
+
* LINE bot main class
|
92 |
+
*/
|
93 |
+
class LineBot {
|
94 |
+
/**
|
95 |
+
* Constructor
|
96 |
+
* @param {string} channelId
|
97 |
+
* @param {string} channelSecret
|
98 |
+
* @param {string} accessToken
|
99 |
+
*/
|
100 |
+
constructor(channelId, channelSecret, accessToken) {
|
101 |
+
this.channelId = channelId;
|
102 |
+
this.channelSecret = channelSecret;
|
103 |
+
this.accessToken = accessToken;
|
104 |
+
this.lineApi = 'https://api.line.me/v2/';
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Handle incoming message
|
109 |
+
* @param {object} event
|
110 |
+
*/
|
111 |
+
handleMessage(event) {
|
112 |
+
var message = event.message;
|
113 |
+
var replyToken = event.replyToken;
|
114 |
+
var userId = event.source.userId;
|
115 |
+
var messageText = message.text;
|
116 |
+
|
117 |
+
// Handle message
|
118 |
+
var response = this.handleMessageText(messageText, userId);
|
119 |
+
this.replyMessage(replyToken, response);
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Handle message text
|
124 |
+
* @param {string} messageText
|
125 |
+
* @param {string} userId
|
126 |
+
* @return {string}
|
127 |
+
*/
|
128 |
+
handleMessageText(messageText, userId) {
|
129 |
+
// Simple echo bot
|
130 |
+
return messageText;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Reply message
|
135 |
+
* @param {string} replyToken
|
136 |
+
* @param {string} message
|
137 |
+
*/
|
138 |
+
replyMessage(replyToken, message) {
|
139 |
+
var options = {
|
140 |
+
'method': 'POST',
|
141 |
+
'headers': {
|
142 |
+
'Authorization': 'Bearer ' + this.accessToken,
|
143 |
+
'Content-Type': 'application/json'
|
144 |
+
},
|
145 |
+
'payload': JSON.stringify({
|
146 |
+
'replyToken': replyToken,
|
147 |
+
'messages': [{
|
148 |
+
'type': 'text',
|
149 |
+
'text': message
|
150 |
+
}]
|
151 |
+
})
|
152 |
+
};
|
153 |
+
UrlFetch.fetch(this.lineApi + 'messages/reply', options);
|
154 |
+
}
|
155 |
+
}
|
156 |
+
```
|
157 |
+
|
158 |
+
**oauth2.gs**
|
159 |
+
```
|
160 |
+
/**
|
161 |
+
* OAuth2 service
|
162 |
+
*/
|
163 |
+
class OAuth2 {
|
164 |
+
/**
|
165 |
+
* Constructor
|
166 |
+
* @param {string} clientId
|
167 |
+
* @param {string} clientSecret
|
168 |
+
*/
|
169 |
+
constructor(clientId, clientSecret) {
|
170 |
+
this.clientId = clientId;
|
171 |
+
this.clientSecret = clientSecret;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Get access token
|
176 |
+
* @return {string}
|
177 |
+
*/
|
178 |
+
getAccessToken() {
|
179 |
+
var service = OAuth2.createService('line-bot')
|
180 |
+
.setAuthorizationBaseUrl('https://api.line.me/oauth2/v2.1')
|
181 |
+
.setTokenUrl('https://api.line.me/oauth2/v2.1/token')
|
182 |
+
.setClientId(this.clientId)
|
183 |
+
.setClientSecret(this.clientSecret)
|
184 |
+
.setCallbackFunction('authCallback')
|
185 |
+
.setPropertyStore(PropertiesService.getUserProperties());
|
186 |
+
return service.getAccessToken();
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Auth callback
|
191 |
+
* @param {object} callback
|
192 |
+
*/
|
193 |
+
authCallback(callback) {
|
194 |
+
var authorized = callback.authorized;
|
195 |
+
if (authorized) {
|
196 |
+
return callback.accessToken;
|
197 |
+
} else {
|
198 |
+
var authorizationUrl = callback.authorizationUrl;
|
199 |
+
Logger.log('Authorization URL: %s', authorizationUrl);
|
200 |
+
}
|
201 |
+
}
|
202 |
+
}
|
203 |
+
```
|
204 |
+
|
205 |
+
**index.gs**
|
206 |
+
```
|
207 |
+
/**
|
208 |
+
* Entry point
|
209 |
+
*/
|
210 |
+
function doGet() {
|
211 |
+
var channelId = 'YOUR_CHANNEL_ID';
|
212 |
+
var channelSecret = 'YOUR_CHANNEL_SECRET';
|
213 |
+
var oauth2 = new OAuth2(channelId, channelSecret);
|
214 |
+
var accessToken = oauth2.getAccessToken();
|
215 |
+
var lineBot = new LineBot(channelId, channelSecret, accessToken);
|
216 |
+
|
217 |
+
var event = {
|
218 |
+
'message': {
|
219 |
+
'text': 'Hello, World!'
|
220 |
+
},
|
221 |
+
'replyToken': 'YOUR_REPLY_TOKEN',
|
222 |
+
'source': {
|
223 |
+
'userId': 'YOUR_USER_ID'
|
224 |
+
}
|
225 |
+
};
|
226 |
+
lineBot.handleMessage(event);
|
227 |
+
}
|
228 |
+
```
|
229 |
+
|
230 |
+
This concludes a fully working implementation.
|
controllers/lineprogram/.gpteng/memory/logs/gen_entrypoint_chat.txt
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
2024-06-09T20:39:39.569380
|
3 |
+
================================ System Message ================================
|
4 |
+
|
5 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
6 |
+
The user will ask you to write a script that runs the code in a specific way.
|
7 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
8 |
+
Do not install globally. Do not use sudo.
|
9 |
+
Do not explain the code, just give the commands.
|
10 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
11 |
+
|
12 |
+
|
13 |
+
================================ Human Message =================================
|
14 |
+
|
15 |
+
|
16 |
+
Make a unix script that
|
17 |
+
a) installs dependencies
|
18 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
19 |
+
|
20 |
+
Information about the codebase:
|
21 |
+
|
22 |
+
```
|
23 |
+
File: requirements.txt
|
24 |
+
1 google-api-python-client
|
25 |
+
2 oauth2client
|
26 |
+
|
27 |
+
File: appsscript.json
|
28 |
+
1 {
|
29 |
+
2 "timeZone": "Asia/Tokyo",
|
30 |
+
3 "dependencies": {
|
31 |
+
4 "enabledAdvancedServices": [
|
32 |
+
5 {
|
33 |
+
6 "userSymbol": "OAuth2",
|
34 |
+
7 "serviceId": "oauth2",
|
35 |
+
8 "version": "v2"
|
36 |
+
9 }
|
37 |
+
10 ]
|
38 |
+
11 }
|
39 |
+
12 }
|
40 |
+
|
41 |
+
File: linebot.gs
|
42 |
+
1 /**
|
43 |
+
2 * LINE bot main class
|
44 |
+
3 */
|
45 |
+
4 class LineBot {
|
46 |
+
5 /**
|
47 |
+
6 * Constructor
|
48 |
+
7 * @param {string} channelId
|
49 |
+
8 * @param {string} channelSecret
|
50 |
+
9 * @param {string} accessToken
|
51 |
+
10 */
|
52 |
+
11 constructor(channelId, channelSecret, accessToken) {
|
53 |
+
12 this.channelId = channelId;
|
54 |
+
13 this.channelSecret = channelSecret;
|
55 |
+
14 this.accessToken = accessToken;
|
56 |
+
15 this.lineApi = 'https://api.line.me/v2/';
|
57 |
+
16 }
|
58 |
+
17
|
59 |
+
18 /**
|
60 |
+
19 * Handle incoming message
|
61 |
+
20 * @param {object} event
|
62 |
+
21 */
|
63 |
+
22 handleMessage(event) {
|
64 |
+
23 var message = event.message;
|
65 |
+
24 var replyToken = event.replyToken;
|
66 |
+
25 var userId = event.source.userId;
|
67 |
+
26 var messageText = message.text;
|
68 |
+
27
|
69 |
+
28 // Handle message
|
70 |
+
29 var response = this.handleMessageText(messageText, userId);
|
71 |
+
30 this.replyMessage(replyToken, response);
|
72 |
+
31 }
|
73 |
+
32
|
74 |
+
33 /**
|
75 |
+
34 * Handle message text
|
76 |
+
35 * @param {string} messageText
|
77 |
+
36 * @param {string} userId
|
78 |
+
37 * @return {string}
|
79 |
+
38 */
|
80 |
+
39 handleMessageText(messageText, userId) {
|
81 |
+
40 // Simple echo bot
|
82 |
+
41 return messageText;
|
83 |
+
42 }
|
84 |
+
43
|
85 |
+
44 /**
|
86 |
+
45 * Reply message
|
87 |
+
46 * @param {string} replyToken
|
88 |
+
47 * @param {string} message
|
89 |
+
48 */
|
90 |
+
49 replyMessage(replyToken, message) {
|
91 |
+
50 var options = {
|
92 |
+
51 'method': 'POST',
|
93 |
+
52 'headers': {
|
94 |
+
53 'Authorization': 'Bearer ' + this.accessToken,
|
95 |
+
54 'Content-Type': 'application/json'
|
96 |
+
55 },
|
97 |
+
56 'payload': JSON.stringify({
|
98 |
+
57 'replyToken': replyToken,
|
99 |
+
58 'messages': [{
|
100 |
+
59 'type': 'text',
|
101 |
+
60 'text': message
|
102 |
+
61 }]
|
103 |
+
62 })
|
104 |
+
63 };
|
105 |
+
64 UrlFetch.fetch(this.lineApi + 'messages/reply', options);
|
106 |
+
65 }
|
107 |
+
66 }
|
108 |
+
|
109 |
+
File: oauth2.gs
|
110 |
+
1 /**
|
111 |
+
2 * OAuth2 service
|
112 |
+
3 */
|
113 |
+
4 class OAuth2 {
|
114 |
+
5 /**
|
115 |
+
6 * Constructor
|
116 |
+
7 * @param {string} clientId
|
117 |
+
8 * @param {string} clientSecret
|
118 |
+
9 */
|
119 |
+
10 constructor(clientId, clientSecret) {
|
120 |
+
11 this.clientId = clientId;
|
121 |
+
12 this.clientSecret = clientSecret;
|
122 |
+
13 }
|
123 |
+
14
|
124 |
+
15 /**
|
125 |
+
16 * Get access token
|
126 |
+
17 * @return {string}
|
127 |
+
18 */
|
128 |
+
19 getAccessToken() {
|
129 |
+
20 var service = OAuth2.createService('line-bot')
|
130 |
+
21 .setAuthorizationBaseUrl('https://api.line.me/oauth2/v2.1')
|
131 |
+
22 .setTokenUrl('https://api.line.me/oauth2/v2.1/token')
|
132 |
+
23 .setClientId(this.clientId)
|
133 |
+
24 .setClientSecret(this.clientSecret)
|
134 |
+
25 .setCallbackFunction('authCallback')
|
135 |
+
26 .setPropertyStore(PropertiesService.getUserProperties());
|
136 |
+
27 return service.getAccessToken();
|
137 |
+
28 }
|
138 |
+
29
|
139 |
+
30 /**
|
140 |
+
31 * Auth callback
|
141 |
+
32 * @param {object} callback
|
142 |
+
33 */
|
143 |
+
34 authCallback(callback) {
|
144 |
+
35 var authorized = callback.authorized;
|
145 |
+
36 if (authorized) {
|
146 |
+
37 return callback.accessToken;
|
147 |
+
38 } else {
|
148 |
+
39 var authorizationUrl = callback.authorizationUrl;
|
149 |
+
40 Logger.log('Authorization URL: %s', authorizationUrl);
|
150 |
+
41 }
|
151 |
+
42 }
|
152 |
+
43 }
|
153 |
+
|
154 |
+
File: index.gs
|
155 |
+
1 /**
|
156 |
+
2 * Entry point
|
157 |
+
3 */
|
158 |
+
4 function doGet() {
|
159 |
+
5 var channelId = 'YOUR_CHANNEL_ID';
|
160 |
+
6 var channelSecret = 'YOUR_CHANNEL_SECRET';
|
161 |
+
7 var oauth2 = new OAuth2(channelId, channelSecret);
|
162 |
+
8 var accessToken = oauth2.getAccessToken();
|
163 |
+
9 var lineBot = new LineBot(channelId, channelSecret, accessToken);
|
164 |
+
10
|
165 |
+
11 var event = {
|
166 |
+
12 'message': {
|
167 |
+
13 'text': 'Hello, World!'
|
168 |
+
14 },
|
169 |
+
15 'replyToken': 'YOUR_REPLY_TOKEN',
|
170 |
+
16 'source': {
|
171 |
+
17 'userId': 'YOUR_USER_ID'
|
172 |
+
18 }
|
173 |
+
19 };
|
174 |
+
20 lineBot.handleMessage(event);
|
175 |
+
21 }
|
176 |
+
|
177 |
+
```
|
178 |
+
|
179 |
+
================================== Ai Message ==================================
|
180 |
+
|
181 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
182 |
+
```
|
183 |
+
#!/bin/bash
|
184 |
+
|
185 |
+
# Install dependencies
|
186 |
+
pip install -r requirements.txt
|
187 |
+
|
188 |
+
# Run the codebase
|
189 |
+
google-apps-script --authorization `oauth2.gs` --callback `authCallback` --channelId YOUR_CHANNEL_ID --channelSecret YOUR_CHANNEL_SECRET
|
190 |
+
node index.gs
|
191 |
+
```
|
192 |
+
Note: Replace `YOUR_CHANNEL_ID`, `YOUR_CHANNEL_SECRET`, and `YOUR_REPLY_TOKEN` with your actual values.
|
controllers/lineprogram/appsscript.json
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"timeZone": "Asia/Tokyo",
|
3 |
+
"dependencies": {
|
4 |
+
"enabledAdvancedServices": [
|
5 |
+
{
|
6 |
+
"userSymbol": "OAuth2",
|
7 |
+
"serviceId": "oauth2",
|
8 |
+
"version": "v2"
|
9 |
+
}
|
10 |
+
]
|
11 |
+
}
|
12 |
+
}
|
controllers/lineprogram/index.gs
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Entry point
|
3 |
+
*/
|
4 |
+
function doGet() {
|
5 |
+
var channelId = 'YOUR_CHANNEL_ID';
|
6 |
+
var channelSecret = 'YOUR_CHANNEL_SECRET';
|
7 |
+
var oauth2 = new OAuth2(channelId, channelSecret);
|
8 |
+
var accessToken = oauth2.getAccessToken();
|
9 |
+
var lineBot = new LineBot(channelId, channelSecret, accessToken);
|
10 |
+
|
11 |
+
var event = {
|
12 |
+
'message': {
|
13 |
+
'text': 'Hello, World!'
|
14 |
+
},
|
15 |
+
'replyToken': 'YOUR_REPLY_TOKEN',
|
16 |
+
'source': {
|
17 |
+
'userId': 'YOUR_USER_ID'
|
18 |
+
}
|
19 |
+
};
|
20 |
+
lineBot.handleMessage(event);
|
21 |
+
}
|
controllers/lineprogram/linebot.gs
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* LINE bot main class
|
3 |
+
*/
|
4 |
+
class LineBot {
|
5 |
+
/**
|
6 |
+
* Constructor
|
7 |
+
* @param {string} channelId
|
8 |
+
* @param {string} channelSecret
|
9 |
+
* @param {string} accessToken
|
10 |
+
*/
|
11 |
+
constructor(channelId, channelSecret, accessToken) {
|
12 |
+
this.channelId = channelId;
|
13 |
+
this.channelSecret = channelSecret;
|
14 |
+
this.accessToken = accessToken;
|
15 |
+
this.lineApi = 'https://api.line.me/v2/';
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Handle incoming message
|
20 |
+
* @param {object} event
|
21 |
+
*/
|
22 |
+
handleMessage(event) {
|
23 |
+
var message = event.message;
|
24 |
+
var replyToken = event.replyToken;
|
25 |
+
var userId = event.source.userId;
|
26 |
+
var messageText = message.text;
|
27 |
+
|
28 |
+
// Handle message
|
29 |
+
var response = this.handleMessageText(messageText, userId);
|
30 |
+
this.replyMessage(replyToken, response);
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Handle message text
|
35 |
+
* @param {string} messageText
|
36 |
+
* @param {string} userId
|
37 |
+
* @return {string}
|
38 |
+
*/
|
39 |
+
handleMessageText(messageText, userId) {
|
40 |
+
// Simple echo bot
|
41 |
+
return messageText;
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Reply message
|
46 |
+
* @param {string} replyToken
|
47 |
+
* @param {string} message
|
48 |
+
*/
|
49 |
+
replyMessage(replyToken, message) {
|
50 |
+
var options = {
|
51 |
+
'method': 'POST',
|
52 |
+
'headers': {
|
53 |
+
'Authorization': 'Bearer ' + this.accessToken,
|
54 |
+
'Content-Type': 'application/json'
|
55 |
+
},
|
56 |
+
'payload': JSON.stringify({
|
57 |
+
'replyToken': replyToken,
|
58 |
+
'messages': [{
|
59 |
+
'type': 'text',
|
60 |
+
'text': message
|
61 |
+
}]
|
62 |
+
})
|
63 |
+
};
|
64 |
+
UrlFetch.fetch(this.lineApi + 'messages/reply', options);
|
65 |
+
}
|
66 |
+
}
|
controllers/lineprogram/oauth2.gs
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* OAuth2 service
|
3 |
+
*/
|
4 |
+
class OAuth2 {
|
5 |
+
/**
|
6 |
+
* Constructor
|
7 |
+
* @param {string} clientId
|
8 |
+
* @param {string} clientSecret
|
9 |
+
*/
|
10 |
+
constructor(clientId, clientSecret) {
|
11 |
+
this.clientId = clientId;
|
12 |
+
this.clientSecret = clientSecret;
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Get access token
|
17 |
+
* @return {string}
|
18 |
+
*/
|
19 |
+
getAccessToken() {
|
20 |
+
var service = OAuth2.createService('line-bot')
|
21 |
+
.setAuthorizationBaseUrl('https://api.line.me/oauth2/v2.1')
|
22 |
+
.setTokenUrl('https://api.line.me/oauth2/v2.1/token')
|
23 |
+
.setClientId(this.clientId)
|
24 |
+
.setClientSecret(this.clientSecret)
|
25 |
+
.setCallbackFunction('authCallback')
|
26 |
+
.setPropertyStore(PropertiesService.getUserProperties());
|
27 |
+
return service.getAccessToken();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Auth callback
|
32 |
+
* @param {object} callback
|
33 |
+
*/
|
34 |
+
authCallback(callback) {
|
35 |
+
var authorized = callback.authorized;
|
36 |
+
if (authorized) {
|
37 |
+
return callback.accessToken;
|
38 |
+
} else {
|
39 |
+
var authorizationUrl = callback.authorizationUrl;
|
40 |
+
Logger.log('Authorization URL: %s', authorizationUrl);
|
41 |
+
}
|
42 |
+
}
|
43 |
+
}
|
controllers/lineprogram/prompt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
appsscriptでLINEプログラムの開発
|
controllers/lineprogram/prompt.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
seleniumで
|
2 |
+
|
3 |
+
kinkaimasu.jpのサイト情報を取得して
|
4 |
+
|
5 |
+
金の情報を抜き出し、CSVに登録
|
controllers/lineprogram/requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
google-api-python-client
|
2 |
+
oauth2client
|
controllers/lineprogram/run.sh
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Install dependencies
|
4 |
+
pip install -r requirements.txt
|
5 |
+
|
6 |
+
# Run the codebase
|
7 |
+
google-apps-script --authorization `oauth2.gs` --callback `authCallback` --channelId YOUR_CHANNEL_ID --channelSecret YOUR_CHANNEL_SECRET
|
8 |
+
node index.gs
|
controllers/programfromdoc/__init__.py
ADDED
File without changes
|
controllers/programfromdoc/programfromdoc.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from mysite.libs.utilities import chat_with_interpreter, completion, process_file,no_process_file
|
3 |
+
from interpreter import interpreter
|
4 |
+
import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
|
5 |
+
import duckdb
|
6 |
+
|
7 |
+
gradio_interface = gr.Interface(
|
8 |
+
fn=process_file,
|
9 |
+
inputs=[
|
10 |
+
"file",
|
11 |
+
gr.Textbox(label="Additional Notes", lines=10),
|
12 |
+
gr.Textbox(label="Folder Name"),
|
13 |
+
],
|
14 |
+
outputs="text",
|
15 |
+
)
|
mysite/asgi.py
CHANGED
@@ -7,7 +7,7 @@ from fastapi.templating import Jinja2Templates
|
|
7 |
from starlette.middleware.cors import CORSMiddleware
|
8 |
|
9 |
import gradio as gr
|
10 |
-
from mysite.
|
11 |
from mysite.webhook.webhook import setup_webhook_routes,include_routers
|
12 |
from mysite.database.database import setup_database_routes
|
13 |
from mysite.config.asgi_config import init_django_app
|
|
|
7 |
from starlette.middleware.cors import CORSMiddleware
|
8 |
|
9 |
import gradio as gr
|
10 |
+
from mysite.router.router import setup_gradio_interfaces
|
11 |
from mysite.webhook.webhook import setup_webhook_routes,include_routers
|
12 |
from mysite.database.database import setup_database_routes
|
13 |
from mysite.config.asgi_config import init_django_app
|
mysite/{gradio/gradio_config.py → router/router.py}
RENAMED
@@ -39,18 +39,9 @@ def include_gradio_interfaces():
|
|
39 |
|
40 |
def setup_gradio_interfaces():
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
"file",
|
46 |
-
gr.Textbox(label="Additional Notes", lines=10),
|
47 |
-
gr.Textbox(label="Folder Name"),
|
48 |
-
],
|
49 |
-
outputs="text",
|
50 |
-
)
|
51 |
-
|
52 |
-
default_interfaces = [democs]#,demo]
|
53 |
-
default_names = ["仕様書から作成","Chat","OpenInterpreter","DataBase"]#"demo"]
|
54 |
|
55 |
gradio_interfaces, gradio_names = include_gradio_interfaces()
|
56 |
|
|
|
39 |
|
40 |
def setup_gradio_interfaces():
|
41 |
|
42 |
+
|
43 |
+
default_interfaces = []#,demo]
|
44 |
+
default_names = ["Chat","OpenInterpreter","DataBase","CreateFromDOC"]#"demo"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
gradio_interfaces, gradio_names = include_gradio_interfaces()
|
47 |
|