owenkaplinsky commited on
Commit
21aa146
·
1 Parent(s): c0bd4ef

Fix bug; add float type

Browse files
project/chat.py CHANGED
@@ -790,7 +790,7 @@ def create_gradio_interface():
790
  "type": "object",
791
  "properties": {
792
  "name": { "type": "string" },
793
- "type": { "type": "string", "enum": ["string", "integer", "list"] }
794
  },
795
  "required": ["name", "type"]
796
  }
@@ -801,7 +801,7 @@ def create_gradio_interface():
801
  "type": "object",
802
  "properties": {
803
  "name": { "type": "string" },
804
- "type": { "type": "string", "enum": ["string", "integer", "list"] }
805
  },
806
  "required": ["name", "type"]
807
  }
 
790
  "type": "object",
791
  "properties": {
792
  "name": { "type": "string" },
793
+ "type": { "type": "string", "enum": ["string", "integer", "float", "list"] }
794
  },
795
  "required": ["name", "type"]
796
  }
 
801
  "type": "object",
802
  "properties": {
803
  "name": { "type": "string" },
804
+ "type": { "type": "string", "enum": ["string", "integer", "float", "list"] }
805
  },
806
  "required": ["name", "type"]
807
  }
project/src/blocks/text.js CHANGED
@@ -301,6 +301,7 @@ Blockly.Extensions.registerMutator(
301
  const name = this.inputNames_[j] || type;
302
  let check = null;
303
  if (type === 'integer') check = 'Number';
 
304
  if (type === 'string') check = 'String';
305
 
306
  const existingRefBlock = this.inputRefBlocks_.get(name);
@@ -370,6 +371,7 @@ Blockly.Extensions.registerMutator(
370
  const name = this.outputNames_[j] || ('output' + j);
371
  let check = null;
372
  if (type === 'integer') check = 'Number';
 
373
  if (type === 'string') check = 'String';
374
 
375
  const returnInput = this.appendValueInput('R' + j);
@@ -430,6 +432,7 @@ Blockly.Extensions.registerMutator(
430
  const name = this.inputNames_[j] || ('arg' + j);
431
  let check = null;
432
  if (type === 'integer') check = 'Number';
 
433
  if (type === 'string') check = 'String';
434
 
435
  const input = this.appendValueInput('X' + j);
@@ -459,6 +462,7 @@ Blockly.Extensions.registerMutator(
459
  const name = this.outputNames_[j] || ('output' + j);
460
  let check = null;
461
  if (type === 'integer') check = 'Number';
 
462
  if (type === 'string') check = 'String';
463
 
464
  const returnInput = this.appendValueInput('R' + j);
@@ -497,6 +501,7 @@ const container_input = {
497
  options: [
498
  ["String", "string"],
499
  ["Integer", "integer"],
 
500
  ["List", "list"],
501
  ]
502
  },
@@ -517,6 +522,7 @@ const container_output = {
517
  options: [
518
  ["String", "string"],
519
  ["Integer", "integer"],
 
520
  ["List", "list"],
521
  ]
522
  },
 
301
  const name = this.inputNames_[j] || type;
302
  let check = null;
303
  if (type === 'integer') check = 'Number';
304
+ if (type === 'float') check = 'Number';
305
  if (type === 'string') check = 'String';
306
 
307
  const existingRefBlock = this.inputRefBlocks_.get(name);
 
371
  const name = this.outputNames_[j] || ('output' + j);
372
  let check = null;
373
  if (type === 'integer') check = 'Number';
374
+ if (type === 'float') check = 'Number';
375
  if (type === 'string') check = 'String';
376
 
377
  const returnInput = this.appendValueInput('R' + j);
 
432
  const name = this.inputNames_[j] || ('arg' + j);
433
  let check = null;
434
  if (type === 'integer') check = 'Number';
435
+ if (type === 'float') check = 'Number';
436
  if (type === 'string') check = 'String';
437
 
438
  const input = this.appendValueInput('X' + j);
 
462
  const name = this.outputNames_[j] || ('output' + j);
463
  let check = null;
464
  if (type === 'integer') check = 'Number';
465
+ if (type === 'float') check = 'Number';
466
  if (type === 'string') check = 'String';
467
 
468
  const returnInput = this.appendValueInput('R' + j);
 
501
  options: [
502
  ["String", "string"],
503
  ["Integer", "integer"],
504
+ ["Float", "float"],
505
  ["List", "list"],
506
  ]
507
  },
 
522
  options: [
523
  ["String", "string"],
524
  ["Integer", "integer"],
525
+ ["Float", "float"],
526
  ["List", "list"],
527
  ]
528
  },
project/src/generators/python.js CHANGED
@@ -31,6 +31,9 @@ forBlock['create_mcp'] = function (block, generator) {
31
  case 'integer':
32
  pyType = 'int';
33
  break;
 
 
 
34
  case 'string':
35
  pyType = 'str';
36
  break;
@@ -68,6 +71,8 @@ forBlock['create_mcp'] = function (block, generator) {
68
  const outputType = block.outputTypes_[r] || 'string';
69
  if (outputType === 'integer' && returnValue) {
70
  returnValue = `int(${returnValue})`;
 
 
71
  }
72
 
73
  returnValues.push(returnValue || 'None');
@@ -101,6 +106,9 @@ forBlock['create_mcp'] = function (block, generator) {
101
  case 'integer':
102
  gradioInputs.push('gr.Number()');
103
  break;
 
 
 
104
  case 'string':
105
  gradioInputs.push('gr.Textbox()');
106
  break;
@@ -124,6 +132,9 @@ forBlock['create_mcp'] = function (block, generator) {
124
  case 'integer':
125
  gradioOutputs.push('gr.Number()');
126
  break;
 
 
 
127
  case 'string':
128
  gradioOutputs.push('gr.Textbox()');
129
  break;
@@ -179,6 +190,9 @@ forBlock['func_def'] = function (block, generator) {
179
  case 'integer':
180
  pyType = 'int';
181
  break;
 
 
 
182
  case 'string':
183
  pyType = 'str';
184
  break;
@@ -214,6 +228,8 @@ forBlock['func_def'] = function (block, generator) {
214
  const outputType = block.outputTypes_[r] || 'string';
215
  if (outputType === 'integer' && returnValue) {
216
  returnValue = `int(${returnValue})`;
 
 
217
  }
218
 
219
  returnValues.push(returnValue || 'None');
@@ -248,6 +264,9 @@ forBlock['func_def'] = function (block, generator) {
248
  case 'integer':
249
  pyType = 'int';
250
  break;
 
 
 
251
  case 'string':
252
  pyType = 'str';
253
  break;
 
31
  case 'integer':
32
  pyType = 'int';
33
  break;
34
+ case 'float':
35
+ pyType = 'float';
36
+ break;
37
  case 'string':
38
  pyType = 'str';
39
  break;
 
71
  const outputType = block.outputTypes_[r] || 'string';
72
  if (outputType === 'integer' && returnValue) {
73
  returnValue = `int(${returnValue})`;
74
+ } else if (outputType === 'float' && returnValue) {
75
+ returnValue = `float(${returnValue})`;
76
  }
77
 
78
  returnValues.push(returnValue || 'None');
 
106
  case 'integer':
107
  gradioInputs.push('gr.Number()');
108
  break;
109
+ case 'float':
110
+ gradioInputs.push('gr.Number()');
111
+ break;
112
  case 'string':
113
  gradioInputs.push('gr.Textbox()');
114
  break;
 
132
  case 'integer':
133
  gradioOutputs.push('gr.Number()');
134
  break;
135
+ case 'float':
136
+ gradioOutputs.push('gr.Number()');
137
+ break;
138
  case 'string':
139
  gradioOutputs.push('gr.Textbox()');
140
  break;
 
190
  case 'integer':
191
  pyType = 'int';
192
  break;
193
+ case 'float':
194
+ pyType = 'float';
195
+ break;
196
  case 'string':
197
  pyType = 'str';
198
  break;
 
228
  const outputType = block.outputTypes_[r] || 'string';
229
  if (outputType === 'integer' && returnValue) {
230
  returnValue = `int(${returnValue})`;
231
+ } else if (outputType === 'float' && returnValue) {
232
+ returnValue = `float(${returnValue})`;
233
  }
234
 
235
  returnValues.push(returnValue || 'None');
 
264
  case 'integer':
265
  pyType = 'int';
266
  break;
267
+ case 'float':
268
+ pyType = 'float';
269
+ break;
270
  case 'string':
271
  pyType = 'str';
272
  break;
project/src/index.js CHANGED
@@ -398,15 +398,20 @@ const setupUnifiedStream = () => {
398
  try {
399
  // Parse and create blocks recursively
400
  function parseAndCreateBlock(spec, shouldPosition = false) {
401
- // Match block_name(inputs(...))
402
- const blockMatch = spec.match(/^(\w+)\s*\((.+)\)$/s);
403
 
404
  if (!blockMatch) {
405
  throw new Error(`Invalid block specification format: ${spec}`);
406
  }
407
 
408
  const blockType = blockMatch[1];
409
- const content = blockMatch[2].trim();
 
 
 
 
 
410
 
411
  console.log('[SSE CREATE] Parsing block:', blockType, 'with content:', content);
412
 
 
398
  try {
399
  // Parse and create blocks recursively
400
  function parseAndCreateBlock(spec, shouldPosition = false) {
401
+ // Match block_name(inputs(...)) with proper parenthesis matching
402
+ const blockMatch = spec.match(/^(\w+)\s*\((.*)$/s);
403
 
404
  if (!blockMatch) {
405
  throw new Error(`Invalid block specification format: ${spec}`);
406
  }
407
 
408
  const blockType = blockMatch[1];
409
+ let content = blockMatch[2].trim();
410
+
411
+ // Remove the last closing parenthesis and trim
412
+ if (content.endsWith(')')) {
413
+ content = content.slice(0, -1).trim();
414
+ }
415
 
416
  console.log('[SSE CREATE] Parsing block:', blockType, 'with content:', content);
417
 
project/test.py CHANGED
@@ -165,6 +165,21 @@ def execute_blockly_logic(user_inputs):
165
  typed_args.append([arg])
166
  elif anno == str or anno == inspect._empty:
167
  typed_args.append(str(arg))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  else:
169
  typed_args.append(arg)
170
  except Exception:
@@ -223,14 +238,24 @@ def build_interface():
223
  param = param.strip()
224
  if ':' in param:
225
  name, type_hint = param.split(':')
 
 
 
 
 
 
 
 
 
 
226
  params.append({
227
  'name': name.strip(),
228
- 'type': type_hint.strip()
229
  })
230
  else:
231
  params.append({
232
  'name': param,
233
- 'type': 'str'
234
  })
235
 
236
  # Detect output count (out_amt = N)
@@ -254,7 +279,14 @@ def build_interface():
254
  out_types = []
255
  else:
256
  out_types = []
257
- out_types = ["str" if t == "string" else "int" if t == "integer" else t for t in out_types]
 
 
 
 
 
 
 
258
 
259
  # Update visibility + clear output fields
260
  output_updates = []
 
165
  typed_args.append([arg])
166
  elif anno == str or anno == inspect._empty:
167
  typed_args.append(str(arg))
168
+ else:
169
+ # Handle remaining type cases
170
+ typed_args.append(arg)
171
+ except ValueError:
172
+ # If type conversion fails, try to coerce intelligently
173
+ if anno == float:
174
+ try:
175
+ typed_args.append(float(arg))
176
+ except Exception:
177
+ typed_args.append(arg)
178
+ elif anno == int:
179
+ try:
180
+ typed_args.append(int(float(arg))) # Allow "3.5" to become 3
181
+ except Exception:
182
+ typed_args.append(arg)
183
  else:
184
  typed_args.append(arg)
185
  except Exception:
 
238
  param = param.strip()
239
  if ':' in param:
240
  name, type_hint = param.split(':')
241
+ type_hint = type_hint.strip()
242
+ # Convert Python type hints to display names
243
+ if 'int' in type_hint:
244
+ display_type = 'integer'
245
+ elif 'float' in type_hint:
246
+ display_type = 'float'
247
+ elif 'list' in type_hint:
248
+ display_type = 'list'
249
+ else:
250
+ display_type = 'string'
251
  params.append({
252
  'name': name.strip(),
253
+ 'type': display_type
254
  })
255
  else:
256
  params.append({
257
  'name': param,
258
+ 'type': 'string'
259
  })
260
 
261
  # Detect output count (out_amt = N)
 
279
  out_types = []
280
  else:
281
  out_types = []
282
+ # Convert output types: handle string, integer, float, list
283
+ out_types = [
284
+ "string" if t == "str" else
285
+ "integer" if t == "int" else
286
+ "float" if t == "float" else
287
+ "list" if t == "list" else t
288
+ for t in out_types
289
+ ]
290
 
291
  # Update visibility + clear output fields
292
  output_updates = []