mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
AI Configuration Widgets simplified & separated
This commit is contained in:
@@ -25,10 +25,9 @@ void main() async {
|
|||||||
settingsModel = settingsModel?.copyWithPath(workspaceFolderPath: null);
|
settingsModel = settingsModel?.copyWithPath(workspaceFolderPath: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load all LLM
|
//Load all LLMs
|
||||||
LLMManager.fetchAvailableLLMs().then((_) {
|
await LLMManager.fetchAvailableLLMs();
|
||||||
LLMManager.loadAvailableLLMs().then((_) {});
|
await LLMManager.loadAvailableLLMs();
|
||||||
});
|
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
ProviderScope(
|
ProviderScope(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:apidash_design_system/widgets/textfield_outlined.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:genai/genai.dart';
|
import 'package:genai/genai.dart';
|
||||||
|
import 'package:genai/widgets/ai_config_widgets.dart';
|
||||||
|
|
||||||
class AIRequestConfigSection extends ConsumerStatefulWidget {
|
class AIRequestConfigSection extends ConsumerStatefulWidget {
|
||||||
const AIRequestConfigSection({super.key});
|
const AIRequestConfigSection({super.key});
|
||||||
@@ -45,85 +46,46 @@ class _AIRequestConfigSectionState
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
el.configDescription,
|
el.configDescription,
|
||||||
style: TextStyle(color: Colors.white30),
|
|
||||||
),
|
),
|
||||||
SizedBox(height: 5),
|
SizedBox(height: 5),
|
||||||
if (el.configType == LLMModelConfigurationType.boolean) ...[
|
if (el.configType == LLMModelConfigurationType.boolean) ...[
|
||||||
Switch(
|
BooleanAIConfig(
|
||||||
value: el.configValue.value as bool,
|
configuration: el,
|
||||||
onChanged: (x) {
|
onConfigUpdated: (x) {
|
||||||
el.configValue.value = x;
|
|
||||||
updateRequestModel(el);
|
updateRequestModel(el);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
] else if (el.configType ==
|
] else if (el.configType ==
|
||||||
LLMModelConfigurationType.numeric) ...[
|
LLMModelConfigurationType.numeric) ...[
|
||||||
ADOutlinedTextField(
|
WritableAIConfig(
|
||||||
initialValue: el.configValue.value.toString(),
|
configuration: el,
|
||||||
onChanged: (x) {
|
onConfigUpdated: (x) {
|
||||||
if (x.isEmpty) x = '0';
|
|
||||||
if (num.tryParse(x) == null) return;
|
|
||||||
el.configValue.value = num.parse(x);
|
|
||||||
updateRequestModel(el);
|
updateRequestModel(el);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
)
|
numeric: true,
|
||||||
|
),
|
||||||
] else if (el.configType ==
|
] else if (el.configType ==
|
||||||
LLMModelConfigurationType.text) ...[
|
LLMModelConfigurationType.text) ...[
|
||||||
ADOutlinedTextField(
|
WritableAIConfig(
|
||||||
initialValue: el.configValue.value.toString(),
|
configuration: el,
|
||||||
onChanged: (x) {
|
onConfigUpdated: (x) {
|
||||||
el.configValue.value = x;
|
|
||||||
updateRequestModel(el);
|
updateRequestModel(el);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
] else if (el.configType ==
|
] else if (el.configType ==
|
||||||
LLMModelConfigurationType.slider) ...[
|
LLMModelConfigurationType.slider) ...[
|
||||||
Row(
|
SliderAIConfig(
|
||||||
children: [
|
configuration: el,
|
||||||
Expanded(
|
onSliderUpdated: (x) {
|
||||||
child: Slider(
|
updateRequestModel(x);
|
||||||
min: (el.configValue.value as (
|
|
||||||
double,
|
|
||||||
double,
|
|
||||||
double
|
|
||||||
))
|
|
||||||
.$1,
|
|
||||||
value: (el.configValue.value as (
|
|
||||||
double,
|
|
||||||
double,
|
|
||||||
double
|
|
||||||
))
|
|
||||||
.$2,
|
|
||||||
max: (el.configValue.value as (
|
|
||||||
double,
|
|
||||||
double,
|
|
||||||
double
|
|
||||||
))
|
|
||||||
.$3,
|
|
||||||
onChanged: (x) {
|
|
||||||
final z = el.configValue.value as (
|
|
||||||
double,
|
|
||||||
double,
|
|
||||||
double
|
|
||||||
);
|
|
||||||
el.configValue.value = (z.$1, x, z.$3);
|
|
||||||
updateRequestModel(el);
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
Text((el.configValue.value as (double, double, double))
|
|
||||||
.$2
|
|
||||||
.toStringAsFixed(2)),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
// Divider(color: Colors.white10),
|
|
||||||
// SizedBox(height: 10),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ class AIRequestPromptSection extends ConsumerWidget {
|
|||||||
padding: const EdgeInsets.only(left: 25.0),
|
padding: const EdgeInsets.only(left: 25.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'System Prompt',
|
'System Prompt',
|
||||||
style: TextStyle(color: Colors.white54),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
kVSpacer10,
|
kVSpacer10,
|
||||||
@@ -55,7 +54,6 @@ class AIRequestPromptSection extends ConsumerWidget {
|
|||||||
padding: const EdgeInsets.only(left: 25.0),
|
padding: const EdgeInsets.only(left: 25.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'User Prompt / Input',
|
'User Prompt / Input',
|
||||||
style: TextStyle(color: Colors.white54),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
kVSpacer10,
|
kVSpacer10,
|
||||||
|
|||||||
90
packages/genai/lib/widgets/ai_config_widgets.dart
Normal file
90
packages/genai/lib/widgets/ai_config_widgets.dart
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:genai/llm_config.dart';
|
||||||
|
|
||||||
|
class SliderAIConfig extends StatelessWidget {
|
||||||
|
final LLMModelConfiguration configuration;
|
||||||
|
final Function(LLMModelConfiguration) onSliderUpdated;
|
||||||
|
const SliderAIConfig({
|
||||||
|
super.key,
|
||||||
|
required this.configuration,
|
||||||
|
required this.onSliderUpdated,
|
||||||
|
});
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
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;
|
||||||
|
const WritableAIConfig({
|
||||||
|
super.key,
|
||||||
|
this.numeric = false,
|
||||||
|
required this.configuration,
|
||||||
|
required this.onConfigUpdated,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return TextFormField(
|
||||||
|
initialValue: configuration.configValue.value.toString(),
|
||||||
|
onChanged: (x) {
|
||||||
|
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;
|
||||||
|
const BooleanAIConfig({
|
||||||
|
super.key,
|
||||||
|
required this.configuration,
|
||||||
|
required this.onConfigUpdated,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Switch(
|
||||||
|
value: configuration.configValue.value as bool,
|
||||||
|
onChanged: (x) {
|
||||||
|
configuration.configValue.value = x;
|
||||||
|
onConfigUpdated(configuration);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,12 +14,7 @@ class DefaultLLMSelectorButton extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return ElevatedButton(
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Chip(label: Text(defaultLLM?.selectedLLM.modelName ?? 'none')),
|
|
||||||
SizedBox(height: 10),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final saveObject = await showDialog(
|
final saveObject = await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -34,9 +29,7 @@ class DefaultLLMSelectorButton extends StatelessWidget {
|
|||||||
if (saveObject == null) return;
|
if (saveObject == null) return;
|
||||||
onDefaultLLMUpdated(saveObject);
|
onDefaultLLMUpdated(saveObject);
|
||||||
},
|
},
|
||||||
icon: Icon(Icons.edit),
|
child: Text(defaultLLM?.selectedLLM.modelName ?? 'Select Model'),
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user