feat: show active local model in Flutter UI

This commit is contained in:
Hamza Ayed
2026-09-30 08:02:53 +03:00
parent 874c7152d1
commit 1295e4aea3
4 changed files with 24 additions and 2 deletions
@@ -22,6 +22,13 @@ class ApiRepository {
void setBaseUrl(String value) =>
_baseUrl = value.replaceFirst(RegExp(r'/+$'), '');
Future<String> getModelName() async {
final response = await http.get(Uri.parse('$_baseUrl/health'));
_checkStatus(response);
final data = jsonDecode(response.body) as Map<String, dynamic>;
return data['model'] as String? ?? 'نموذج غير معروف';
}
Future<String> _userId() async {
final cached = _cachedUserId;
if (cached != null) return cached;
@@ -6,10 +6,20 @@ import 'chat_state.dart';
class ChatCubit extends Cubit<ChatState> {
ChatCubit(this._api) : super(ChatState(apiBaseUrl: _api.baseUrl)) {
_loadHistory();
_loadModelName();
}
final ApiRepository _api;
Future<void> _loadModelName() async {
try {
final modelName = await _api.getModelName();
if (!isClosed) emit(state.copyWith(modelName: modelName));
} catch (_) {
if (!isClosed) emit(state.copyWith(modelName: 'تعذر الاتصال بالخادم'));
}
}
Future<void> _loadHistory() async {
try {
final conversations = await _api.listConversations();
@@ -172,5 +182,6 @@ class ChatCubit extends Cubit<ChatState> {
if (url.isEmpty) return;
_api.setBaseUrl(url);
emit(state.copyWith(apiBaseUrl: _api.baseUrl, clearError: true));
_loadModelName();
}
}
@@ -60,6 +60,7 @@ class ChatState {
this.isLoadingHistory = true,
this.isSending = false,
this.error,
this.modelName = 'جارٍ اكتشاف النموذج…',
required this.apiBaseUrl,
});
@@ -69,6 +70,7 @@ class ChatState {
final bool isLoadingHistory;
final bool isSending;
final String? error;
final String modelName;
final String apiBaseUrl;
ChatState copyWith({
@@ -80,6 +82,7 @@ class ChatState {
bool? isSending,
String? error,
bool clearError = false,
String? modelName,
String? apiBaseUrl,
}) => ChatState(
messages: messages ?? this.messages,
@@ -91,6 +94,7 @@ class ChatState {
isLoadingHistory: isLoadingHistory ?? this.isLoadingHistory,
isSending: isSending ?? this.isSending,
error: clearError ? null : (error ?? this.error),
modelName: modelName ?? this.modelName,
apiBaseUrl: apiBaseUrl ?? this.apiBaseUrl,
);
}
@@ -293,8 +293,8 @@ class _ChatPageState extends State<ChatPage> {
],
),
const SizedBox(height: 7),
const Text(
'qwen2.5:1.5b-instruct-q4_K_M',
Text(
chat.modelName,
textDirection: TextDirection.ltr,
style: TextStyle(fontSize: 10, color: Color(0xFF718078)),
),