mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
100 lines
2.7 KiB
Dart
100 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:genai/llm_config.dart';
|
|
|
|
class SliderAIConfig extends StatelessWidget {
|
|
final LLMModelConfiguration configuration;
|
|
final Function(LLMModelConfiguration) onSliderUpdated;
|
|
final bool readonly;
|
|
const SliderAIConfig({
|
|
super.key,
|
|
required this.configuration,
|
|
required this.onSliderUpdated,
|
|
this.readonly = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: Slider(
|
|
min: (configuration.configValue.value as (double, double, double))
|
|
.$1,
|
|
value: (configuration.configValue.value as (double, double, double))
|
|
.$2,
|
|
max: (configuration.configValue.value as (double, double, double))
|
|
.$3,
|
|
onChanged: (x) {
|
|
if (readonly) return;
|
|
final z =
|
|
configuration.configValue.value as (double, double, double);
|
|
configuration.configValue.value = (z.$1, x, z.$3);
|
|
onSliderUpdated(configuration);
|
|
},
|
|
),
|
|
),
|
|
Text(
|
|
(configuration.configValue.value as (double, double, double)).$2
|
|
.toStringAsFixed(2),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class WritableAIConfig extends StatelessWidget {
|
|
final bool numeric;
|
|
final LLMModelConfiguration configuration;
|
|
final Function(LLMModelConfiguration) onConfigUpdated;
|
|
final bool readonly;
|
|
const WritableAIConfig({
|
|
super.key,
|
|
this.numeric = false,
|
|
required this.configuration,
|
|
required this.onConfigUpdated,
|
|
this.readonly = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextFormField(
|
|
initialValue: configuration.configValue.value.toString(),
|
|
onChanged: (x) {
|
|
if (readonly) return;
|
|
if (numeric) {
|
|
if (x.isEmpty) x = '0';
|
|
if (num.tryParse(x) == null) return;
|
|
configuration.configValue.value = num.parse(x);
|
|
} else {
|
|
configuration.configValue.value = x;
|
|
}
|
|
onConfigUpdated(configuration);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class BooleanAIConfig extends StatelessWidget {
|
|
final LLMModelConfiguration configuration;
|
|
final Function(LLMModelConfiguration) onConfigUpdated;
|
|
final bool readonly;
|
|
const BooleanAIConfig({
|
|
super.key,
|
|
required this.configuration,
|
|
required this.onConfigUpdated,
|
|
this.readonly = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Switch(
|
|
value: configuration.configValue.value as bool,
|
|
onChanged: (x) {
|
|
if (readonly) return;
|
|
configuration.configValue.value = x;
|
|
onConfigUpdated(configuration);
|
|
},
|
|
);
|
|
}
|
|
}
|