-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerators.ts
37 lines (32 loc) · 1.39 KB
/
generators.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Blockly.Python['import_ai'] = function() {
var code = 'import ai\n';
return code;
};
Blockly.Python['ai_init'] = function(block) {
var chatbot = Blockly.Python.nameDB_.getName(block.getFieldValue('chatbot'), Blockly.VARIABLE_CATEGORY_NAME);
var parameters = Blockly.Python.valueToCode(block, 'parameters', 0);
var code = `${chatbot} = ai.Assistant(${parameters})\n`;
return code;
};
Blockly.Python['ai_setup'] = function(block) {
var chatbot = Blockly.Python.nameDB_.getName(block.getFieldValue('chatbot'), Blockly.VARIABLE_CATEGORY_NAME);
var code = `await ${chatbot}.setup()\n`;
return code;
};
Blockly.Python['ai_add_prompt'] = function(block) {
var chatbot = Blockly.Python.nameDB_.getName(block.getFieldValue('chatbot'), Blockly.VARIABLE_CATEGORY_NAME);
var parameters = Blockly.Python.valueToCode(block, 'parameters', 0);
var code = `await ${chatbot}.add_prompt(${parameters})\n`;
return code;
};
Blockly.Python['ai_ask'] = function(block) {
var chatbot = Blockly.Python.nameDB_.getName(block.getFieldValue('chatbot'), Blockly.VARIABLE_CATEGORY_NAME);
var parameters = Blockly.Python.valueToCode(block, 'parameters', 0);
var code = `await ${chatbot}.ask(${parameters})`;
return [code, 0];
};
Blockly.Python['ai_model'] = function(block) {
var model = block.getFieldValue('model');
var code = `model=${model}`;
return [code, 0];
};