Skip to content

Commit

Permalink
Allow system prompt updates, fix aggressive mem cleanup, fix phone tu…
Browse files Browse the repository at this point in the history
…ning option maxheight
  • Loading branch information
1runeberg committed Aug 23, 2024
1 parent 46b2174 commit 9a4ab1d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
6 changes: 5 additions & 1 deletion confichat/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions confichat/lib/ui_advanced_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ class AdvancedOptionsState extends State<AdvancedOptions> {
const SizedBox(height: 24),

ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 500.0,
),
constraints: BoxConstraints(
maxHeight: AppData.instance.getUserDeviceType(context) == UserDeviceType.phone ? 250.0 : 500, ),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [

const Text('Scroll down to see more tuning options', style: TextStyle(fontStyle: FontStyle.italic)),
const Text('Scroll to see more tuning options', style: TextStyle(fontStyle: FontStyle.italic)),
const SizedBox(height: 16),

_buildSliderWithTooltip(
Expand Down Expand Up @@ -317,6 +316,7 @@ class AdvancedOptionsState extends State<AdvancedOptions> {
widget.api.probability = probability;
widget.api.maxTokens = maxTokens;
widget.api.stopSequences = stopSequenceController.text.split(',').map((s) => s.trim()).toList();
widget.api.systemPrompt = systemPromptController.text;
}

}
26 changes: 19 additions & 7 deletions confichat/lib/ui_canvass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class CanvassState extends State<Canvass> {
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AdvancedOptions(api: widget.appData.api, enableSystemPrompt: chatData.isEmpty);
return AdvancedOptions(api: widget.appData.api, enableSystemPrompt: true);
},
);
},
Expand Down Expand Up @@ -732,8 +732,6 @@ class CanvassState extends State<Canvass> {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(SnackBar(backgroundColor: Theme.of(context).colorScheme.error, content: Text('Unable to save encrypted chat session: ${e.toString()}')));
} finally{
// Cleanup
encryptionKeyController.dispose();
// ignore: use_build_context_synchronously
Navigator.of(context).pop();
}
Expand All @@ -755,8 +753,6 @@ class CanvassState extends State<Canvass> {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(SnackBar(backgroundColor: Theme.of(context).colorScheme.primaryContainer, content: const Text('Chat session updated.')));

// Cleanup
encryptionKeyController.dispose();
// ignore: use_build_context_synchronously
Navigator.of(context).pop();
}
Expand All @@ -766,8 +762,6 @@ class CanvassState extends State<Canvass> {
ElevatedButton(
child: const Text('Cancel'),
onPressed: () {
// Cleanup
encryptionKeyController.dispose();
Navigator.of(context).pop();
},
),
Expand Down Expand Up @@ -828,6 +822,24 @@ class CanvassState extends State<Canvass> {
"content": widget.appData.api.systemPrompt
});
});
} else if(chatData.isNotEmpty
&& widget.appData.api.systemPrompt.isNotEmpty
&& chatData[0].containsKey('role')
&& chatData[0].containsKey('content')) {

setState(() {
if( chatData[0]['role'] == 'system') {
// update system prompt
chatData[0]['content'] = widget.appData.api.systemPrompt;
} else {
// Add system prompt
chatData.insert( 0, {
"role": "system",
"content": widget.appData.api.systemPrompt
});
}
});

}

// Add prompt to messages
Expand Down
2 changes: 1 addition & 1 deletion confichat/lib/ui_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class SidebarState extends State<Sidebar> {
itemBuilder: (context) => [

// Allow updates if there are unsaved messages
if(widget.appData.haveUnsavedMessages)
if(widget.appData.haveUnsavedMessages )
const PopupMenuItem(
value: 'update',
child: Text('Update'),
Expand Down

0 comments on commit 9a4ab1d

Please sign in to comment.