feat: improve prompts

This commit is contained in:
Udhay-Adithya
2025-09-05 16:41:35 +05:30
parent 7e13a48199
commit 6bbbe6ccc3
5 changed files with 175 additions and 211 deletions

View File

@@ -1,4 +1,5 @@
import '../view/widgets/chat_bubble.dart';
/// Role of a chat message author.
enum MessageRole { user, system }
class ChatState {
final Map<String, List<ChatMessage>> chatSessions; // requestId -> messages

View File

@@ -1,8 +1,10 @@
import 'package:apidash/dashbot/core/utils/safe_parse_json_message.dart';
import 'package:apidash_design_system/tokens/tokens.dart';
import '../../../../core/utils/dashbot_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import '../../models/chat_models.dart';
class ChatBubble extends StatelessWidget {
final String message;
@@ -36,6 +38,22 @@ class ChatBubble extends StatelessWidget {
),
);
}
// Parse agent JSON when role is system and show only the "explnation" field.
String renderedMessage = message;
if (role == MessageRole.system) {
try {
final Map<String, dynamic> parsed = MessageJson.safeParse(message);
if (parsed.containsKey('explnation')) {
final exp = parsed['explnation'];
if (exp is String && exp.isNotEmpty) {
renderedMessage = exp;
}
}
} catch (_) {
// Fallback to raw message
}
}
return Align(
alignment: role == MessageRole.user
? Alignment.centerRight
@@ -62,7 +80,7 @@ class ChatBubble extends StatelessWidget {
borderRadius: BorderRadius.circular(16.0),
),
child: MarkdownBody(
data: message.isEmpty ? " " : message,
data: renderedMessage.isEmpty ? " " : renderedMessage,
selectable: true,
styleSheet: MarkdownStyleSheet.fromTheme(
Theme.of(context),
@@ -91,5 +109,3 @@ class ChatBubble extends StatelessWidget {
);
}
}
enum MessageRole { user, system }

View File

@@ -7,7 +7,6 @@ import 'package:apidash/models/models.dart';
import 'package:nanoid/nanoid.dart';
import '../../../core/constants/dashbot_prompts.dart' as dash;
import '../view/widgets/chat_bubble.dart';
import '../models/chat_models.dart';
import '../repository/chat_remote_repository.dart';
@@ -47,7 +46,7 @@ class ChatViewmodel extends StateNotifier<ChatState> {
if (ai == null) {
debugPrint('[Chat] No AI model configured');
_appendSystem(
'AI model is not configured. Please set one in AI Request tab.',
'AI model is not configured. Please set one.',
type,
);
return;
@@ -261,7 +260,7 @@ class ChatViewmodel extends StateNotifier<ChatState> {
body: http?.body,
);
case ChatMessageType.general:
return null;
return prompts.generalInteractionPrompt();
}
}
}