Skip to content

Commit

Permalink
Merge pull request #33 from guchengxi1994/master
Browse files Browse the repository at this point in the history
feat: [template] file chat based on kimi
  • Loading branch information
guchengxi1994 authored May 15, 2024
2 parents 359dd7a + f69cbb8 commit f4c40a4
Show file tree
Hide file tree
Showing 16 changed files with 529 additions and 156 deletions.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion lib/llm/template_editor/components/chain_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _ChainFlowState extends ConsumerState<ChainFlow> {
final ScrollController controller2 = ScrollController();

late double childrenHeight = 0;
List<(String, AttributeType)> items = [];
List<(String, AttributeType, String?)> items = [];

init() async {
items =
Expand Down
21 changes: 14 additions & 7 deletions lib/llm/template_editor/notifiers/chain_flow_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,37 @@ class ChainFlowNotifier extends Notifier<ChainFlowState> {
/// FIXME
/// BUG
/// 不灵活的实现方案
Future<List<(String, int, int?, AttributeType)>> toRust() async {
List<(String, int, int?, AttributeType)> result = [];
Future<List<(String, int, int?, AttributeType, String?)>> toRust() async {
List<(String, int, int?, AttributeType, String?)> result = [];
final items = await templateToPrompts(template: state.content);
final itemTuple = items
.mapIndexed((index, element) => ((index, element.$1, element.$2)))
.mapIndexed(
(index, element) => ((index, element.$1, element.$2, element.$3)))
.toList();

List<int> ids = [];
for (final i in state.items) {
ids.addAll(i.ids);
for (int j = 0; j < i.ids.length; j++) {
if (j < i.ids.length - 1) {
result
.add((i.contents[j], i.ids[j], ids[j + 1], AttributeType.prompt));
result.add((
i.contents[j],
i.ids[j],
ids[j + 1],
AttributeType.prompt,
null
));
} else {
result.add((i.contents[j], i.ids[j], null, AttributeType.prompt));
result
.add((i.contents[j], i.ids[j], null, AttributeType.prompt, null));
}
}
}

itemTuple.retainWhere((element) => !ids.contains(element.$1));

for (final t in itemTuple) {
result.add((t.$2, t.$1, null, t.$3));
result.add((t.$2, t.$1, null, t.$3, t.$4));
}

return result;
Expand Down
4 changes: 3 additions & 1 deletion lib/llm/template_editor/template_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class _TemplateEditorState extends ConsumerState<TemplateEditor> {
heroTag: null,
child: const Icon(Bootstrap.file_word),
onPressed: () async {
// print(_editorState.document.toJson());
ref
.read(chainFlowProvider.notifier)
.changeContent(jsonEncode(_editorState.document.toJson()));
Expand All @@ -151,7 +152,8 @@ class _TemplateEditorState extends ConsumerState<TemplateEditor> {
return const LoadingDialog();
});

generateFromTemplate(v: l).then((value) async {
generateFromTemplate(v: l, enablePlugin: true)
.then((value) async {
final md = await optimizeDoc(s: _editorState.toStr());
setState(
() {
Expand Down
9 changes: 6 additions & 3 deletions lib/src/rust/api/llm_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ Future<void> sequentialChainChat(
Future<String?> templateRenderer({required String template, dynamic hint}) =>
RustLib.instance.api.templateRenderer(template: template, hint: hint);

Future<List<(String, AttributeType)>> templateToPrompts(
Future<List<(String, AttributeType, String?)>> templateToPrompts(
{required String template, dynamic hint}) =>
RustLib.instance.api.templateToPrompts(template: template, hint: hint);

Future<void> generateFromTemplate(
{required List<(String, int, int?, AttributeType)> v, dynamic hint}) =>
RustLib.instance.api.generateFromTemplate(v: v, hint: hint);
{required List<(String, int, int?, AttributeType, String?)> v,
required bool enablePlugin,
dynamic hint}) =>
RustLib.instance.api
.generateFromTemplate(v: v, enablePlugin: enablePlugin, hint: hint);

Future<String> optimizeDoc({required String s, dynamic hint}) =>
RustLib.instance.api.optimizeDoc(s: s, hint: hint);
Expand Down
Loading

0 comments on commit f4c40a4

Please sign in to comment.