增加ollama块

This commit is contained in:
Irene-Maxine
2025-03-09 23:05:36 +08:00
parent c18326aca4
commit a6b05daefe
9 changed files with 329 additions and 3 deletions

View File

@@ -1790,4 +1790,20 @@ export const educore_ble_keyboard_input = {
this.setNextStatement(true);
this.setInputsInline(true);
}
};
export const get_keyboard_light = {
init: function () {
this.setColour(ACTUATOR_ONBOARD_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_GET + Blockly.Msg.MIXLY_KEYBOARD_LIGHT)
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_NumLock, "0"],
[Blockly.Msg.MIXLY_CapsLock, "1"],
[Blockly.Msg.MIXLY_ScorllLock, "2"]
]),'key');
this.setOutput(true);
this.setInputsInline(true);
}
};

View File

@@ -621,4 +621,119 @@ export const iot_wificonnect = iot_wifi_connect;
export const iot_onenetconnect = iot_onenet_connect;
export const iot_onenetdisconnect = iot_onenet_disconnect;
export const iot_checkonenet = iot_onenet_check;
export const iot_publish = iot_onenet_publish;
export const iot_publish = iot_onenet_publish;
export const IOT_CONNECT_OLLAMA = {
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_CONNECT_OLLAMA);
this.appendValueInput('SERVER')
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput('NAME')
.appendField(Blockly.Msg.MODEL_NAME)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput('NUMBER')
.appendField(Blockly.Msg.MIXLY_SET_MAXIMUM_HISTORICAL_SESSIONS_NUM);
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const use_ollama_llm_to_chat = {
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_LLM_CHAT);
this.appendValueInput('TOPIC')
.appendField(Blockly.Msg.MIXLY_MIXGO_ESPNOW_SEND);
this.appendValueInput('METHOD')
.appendField(Blockly.Msg.MIXLY_LLM_CONTENT_CALLBACK);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const use_ollama_llm_to_chat_return = {
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_LLM_CHAT);
this.appendValueInput('TOPIC')
.appendField(Blockly.Msg.MIXLY_MIXGO_ESPNOW_SEND);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXPY_REQUESTS_GET_RESULT)
this.setInputsInline(true);
this.setOutput(true);
}
};
// export const ollama_set_timeout = {
// init: function () {
// this.setColour(IOT_HUE);
// this.appendValueInput("VAR")
// .appendField('Ollama ' + Blockly.Msg.MIXLY_OLLAMA_SET_TIMEOUT);
// this.setInputsInline(true);
// this.setPreviousStatement(true);
// this.setNextStatement(true);
// }
// }
// export const ollama_set_max_retries = {
// init: function () {
// this.setColour(IOT_HUE);
// this.appendValueInput("VAR")
// .appendField('Ollama ' + Blockly.Msg.MIXLY_OLLAMA_SET_MAX_RETRIES);
// this.setInputsInline(true);
// this.setPreviousStatement(true);
// this.setNextStatement(true);
// }
// }
// export const ollama_set_custom_url = {
// init: function () {
// this.setColour(IOT_HUE);
// this.appendValueInput("TEXT")
// .appendField('Ollama ' + Blockly.Msg.MIXLY_OLLAMA_SET_CUSTOM_URL);
// this.setInputsInline(true);
// this.setPreviousStatement(true);
// this.setNextStatement(true);
// }
// }
// export const ollama_select_model = {
// init: function () {
// this.setColour(IOT_HUE);
// this.appendValueInput("TEXT")
// .appendField('Ollama ' + Blockly.Msg.MIXLY_SELECT_MODEL);
// this.setInputsInline(true);
// this.setPreviousStatement(true);
// this.setNextStatement(true);
// }
// }
// export const ollama_clear_user_history = {
// init: function () {
// this.setColour(IOT_HUE);
// this.appendDummyInput()
// .appendField('Ollama ' + Blockly.Msg.MIXLY_CLEAR_USER_HISTORY);
// this.setInputsInline(true);
// this.setPreviousStatement(true);
// this.setNextStatement(true);
// }
// }
export const ollama_empty_history = {
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField('Ollama ' + Blockly.Msg.MIXLY_EMPTY_HISTORY);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
}

View File

@@ -2227,7 +2227,7 @@ export const weigh_sensor_get_weight = {
this.appendValueInput('SUB')
.appendField(Blockly.Msg.MIXLY_GET + Blockly.Msg.MIXLY_WEIGH_SENSOR)
this.appendDummyInput()
.appendField(Blockly.Msg.blockpy_set_of + Blockly.Msg.MIXLY_DATA)
.appendField(Blockly.Msg.blockpy_set_of + Blockly.Msg.MIXLY_DATA + '(g)')
this.setOutput(true);
this.setInputsInline(true);
}

View File

@@ -1038,6 +1038,7 @@ export const sensor_mixgo_cc_mmc5603_get_magnetic = {
});
}
};
export const sensor_mixgo_cc_mmc5603_get_angle = {
init: function () {
this.setColour(SENSOR_ONBOARD_HUE);
@@ -1045,7 +1046,6 @@ export const sensor_mixgo_cc_mmc5603_get_angle = {
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_GET_COMPASS + Blockly.Msg.MIXLY_MICROBIT_JS_BY_ANGLE)
this.setOutput(true, Number);
this.setInputsInline(true);
}
};
@@ -1737,4 +1737,14 @@ export const CI130X_SET_SYSTEM_CMD_SANT = {
this.setNextStatement(true);
this.setInputsInline(true);
}
};
export const sensor_get_the_coprocessor_version = {
init: function () {
this.setColour(SENSOR_ONBOARD_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_GET + Blockly.Msg.MIXLY_THE_COPROCESSOR_VERSION)
this.setOutput(true);
this.setInputsInline(true);
}
};

View File

@@ -765,4 +765,13 @@ export const educore_ble_keyboard_input = function (_, generator) {
var sub = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
var code = sub+".keyboard_send("+ ge + ")\n";
return code;
}
export const get_keyboard_light = function (_,generator){
var version = Boards.getSelectedBoardKey().split(':')[2]
generator.definitions_['import_' + version + '_onboard_bot'] = 'from ' + version + ' import onboard_bot';
var key = this.getFieldValue('key');
var code = "onboard_bot.hid_keyboard_state()["+ key +']';
return [code,generator.ORDER_ATOMIC]
}

View File

@@ -233,4 +233,69 @@ export const iot_mqtt_data = function (_, generator) {
var key = this.getFieldValue('key');
var code = 'mqtt_client.' + key;
return [code, generator.ORDER_ATOMIC];
}
export const IOT_CONNECT_OLLAMA = function(_,generator) {
generator.definitions_['import_Ollama'] = "from ollama import Ollama";
var ser = generator.valueToCode(this, 'SERVER', generator.ORDER_ATOMIC);
var name = generator.valueToCode(this, 'NAME', generator.ORDER_ATOMIC);
var num = generator.valueToCode(this, 'NUMBER', generator.ORDER_ATOMIC);
var code = 'llm = Ollama(' + ser + ', ' + name + ','+ num +')\n';
return code;
}
export const use_ollama_llm_to_chat = function (_, generator) {
generator.definitions_['import_Ollama'] = "from ollama import Ollama";
var topic = generator.valueToCode(this, 'TOPIC', generator.ORDER_ATOMIC);
var method = generator.valueToCode(this, 'METHOD', generator.ORDER_ATOMIC);
var code = 'llm.chat(' + topic + ',' + method + ')\n';
return code;
}
export const use_ollama_llm_to_chat_return = function (_, generator) {
generator.definitions_['import_Ollama'] = "from ollama import Ollama";
var topic = generator.valueToCode(this, 'TOPIC', generator.ORDER_ATOMIC);
var code = 'llm.chat(' + topic + ')';
return [code,generator.ORDER_ATOMIC];
}
// export const ollama_set_timeout = function (_,generator) {
// generator.definitions_['import_Ollama'] = "from ollama import Ollama";
// var t = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
// var code = 'llm.set_timeout(' + t + ')\n';
// return code;
// }
// export const ollama_set_max_retries = function (_,generator) {
// generator.definitions_['import_Ollama'] = "from ollama import Ollama";
// var t = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
// var code = 'llm.set_max_retries(' + t + ')\n';
// return code;
// }
// export const ollama_set_custom_url = function (_,generator) {
// generator.definitions_['import_Ollama'] = "from ollama import Ollama";
// var t = generator.valueToCode(this, 'TEXT', generator.ORDER_ATOMIC);
// var code = 'llm.set_custom_url(' + t + ')\n';
// return code;
// }
// export const ollama_select_model = function (_,generator) {
// generator.definitions_['import_Ollama'] = "from ollama import Ollama";
// var t = generator.valueToCode(this, 'TEXT', generator.ORDER_ATOMIC);
// var code = 'llm.select_model(' + t + ')\n';
// return code;
// }
// export const ollama_clear_user_history = function (_,generator) {
// generator.definitions_['import_Ollama'] = "from ollama import Ollama";
// var code = 'llm.clear_user_history()\n';
// return code;
// }
export const ollama_empty_history = function (_,generator) {
generator.definitions_['import_Ollama'] = "from ollama import Ollama";
var code = 'llm.empty_history()\n';
return code;
}

View File

@@ -924,4 +924,11 @@ export const CI130X_SET_SYSTEM_CMD_SANT = function (_, generator) {
var cmd = this.getFieldValue('cmd');
var code = 'onboard_asr.sys_cmd(' + cmd + ')\n';
return code;
}
export const sensor_get_the_coprocessor_version = function(_,generator){
var version = Boards.getSelectedBoardKey().split(':')[2];
generator.definitions_['import_' + version + '_onboard_bot'] = 'from ' + version + ' import onboard_bot';
var code = 'onboard_bot.version()';
return [code, generator.ORDER_ATOMIC];
}

View File

@@ -1431,6 +1431,7 @@
<block type="sensor_mixgo_cc_mmc5603_calibrate_compass" m-show="micropython:esp32c2:mixgo_mini"></block>
<block type="sensor_mixgo_cc_mmc5603_get_magnetic" m-show="micropython:esp32c2:mixgo_mini"></block>
<block type="sensor_mixgo_cc_mmc5603_get_angle" m-show="micropython:esp32c2:mixgo_mini"></block>
<block type="sensor_get_the_coprocessor_version" m-show="micropython:esp32c2:mixgo_mini"></block>
<block type="rfid_readid" m-show='micropython:esp32c3:mixgo_cc'>
<value name="SUB">
<shadow type="variables_get">
@@ -1699,6 +1700,7 @@
</shadow>
</value>
</block>
<block type = "get_keyboard_light"></block>
<block type="analog_keyboard_input" m-show="micropython:esp32c2:mixgo_mini">
<value name="special">
<block type="special_key">
@@ -2335,6 +2337,92 @@
</value>
</block>
<block type="iot_mqtt_data"></block>
<block type="IOT_CONNECT_OLLAMA">
<value name="SERVER">
<shadow type="text">
<field name="TEXT">192.168.1.1</field>
</shadow>
</value>
<value name="NAME">
<shadow type="text">
<field name="TEXT">qwen2.5-coder:0.5b</field>
</shadow>
</value>
<value name="NUMBER">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
</block>
<block type="use_ollama_llm_to_chat">
<value name="TOPIC">
<shadow type="text">
<field name="TEXT">content</field>
</shadow>
</value>
<value name="METHOD">
<shadow type="factory_block_return">
<field name="VALUE">content_callback</field>
</shadow>
</value>
</block>
<block type="procedures_defnoreturn">
<mutation>
<arg name="content"></arg>
</mutation>
<field name="NAME">content_callback</field>
<statement name="STACK">
<block type="system_print_end">
<value name="VAR">
<block type="variables_get">
<field name="VAR">content</field>
</block>
</value>
<value name="END">
<shadow type="text">
<field name="TEXT"></field>
</shadow>
</value>
</block>
</statement>
</block>
<block type="use_ollama_llm_to_chat_return">
<value name="TOPIC">
<shadow type="text">
<field name="TEXT">请介绍一下米思齐?</field>
</shadow>
</value>
</block>
<!-- <block type="ollama_set_timeout">
<value name="VAR">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
</block>
<block type="ollama_set_max_retries">
<value name="VAR">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
</block>
<block type="ollama_set_custom_url">
<value name="TEXT">
<shadow type="text">
<field name="TEXT">192.168.1.1</field>
</shadow>
</value>
</block>
<block type="ollama_select_model">
<value name="TEXT">
<shadow type="text">
<field name="TEXT">qwen2.5-coder:0.5b</field>
</shadow>
</value>
</block> -->
<block type="ollama_empty_history"></block>
<!-- <block type="ollama_clear_user_history"></block> -->
</category>
<category id="catOnenet" colour="#78AAE0">
<block type="iot_wifi_connect">