MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / _convert_value

Method _convert_value

gui/env_manager.py:505–527  ·  view source on GitHub ↗

Convert a string value based on type hint.

(self, value: str, type_hint: str)

Source from the content-addressed store, hash-verified

503 os.environ[key] = value
504
505 def _convert_value(self, value: str, type_hint: str) -> Any:
506 """Convert a string value based on type hint."""
507 try:
508 if type_hint == "bool":
509 return value.lower() in ("true", "1", "yes", "on")
510 elif type_hint == "int":
511 return int(value)
512 elif type_hint == "float":
513 return float(value)
514 elif type_hint.startswith("choice:"):
515 # Return as-is, validation is done elsewhere
516 return value
517 else:
518 return value
519 except (ValueError, TypeError):
520 # Return schema default on conversion error
521 if type_hint == "bool":
522 return False
523 elif type_hint == "int":
524 return 0
525 elif type_hint == "float":
526 return 0.0
527 return value
528
529
530# Singleton instance

Callers 1

getMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected