feat: show active local model in Flutter UI
This commit is contained in:
@@ -22,6 +22,13 @@ class ApiRepository {
|
|||||||
void setBaseUrl(String value) =>
|
void setBaseUrl(String value) =>
|
||||||
_baseUrl = value.replaceFirst(RegExp(r'/+$'), '');
|
_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 {
|
Future<String> _userId() async {
|
||||||
final cached = _cachedUserId;
|
final cached = _cachedUserId;
|
||||||
if (cached != null) return cached;
|
if (cached != null) return cached;
|
||||||
|
|||||||
@@ -6,10 +6,20 @@ import 'chat_state.dart';
|
|||||||
class ChatCubit extends Cubit<ChatState> {
|
class ChatCubit extends Cubit<ChatState> {
|
||||||
ChatCubit(this._api) : super(ChatState(apiBaseUrl: _api.baseUrl)) {
|
ChatCubit(this._api) : super(ChatState(apiBaseUrl: _api.baseUrl)) {
|
||||||
_loadHistory();
|
_loadHistory();
|
||||||
|
_loadModelName();
|
||||||
}
|
}
|
||||||
|
|
||||||
final ApiRepository _api;
|
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 {
|
Future<void> _loadHistory() async {
|
||||||
try {
|
try {
|
||||||
final conversations = await _api.listConversations();
|
final conversations = await _api.listConversations();
|
||||||
@@ -172,5 +182,6 @@ class ChatCubit extends Cubit<ChatState> {
|
|||||||
if (url.isEmpty) return;
|
if (url.isEmpty) return;
|
||||||
_api.setBaseUrl(url);
|
_api.setBaseUrl(url);
|
||||||
emit(state.copyWith(apiBaseUrl: _api.baseUrl, clearError: true));
|
emit(state.copyWith(apiBaseUrl: _api.baseUrl, clearError: true));
|
||||||
|
_loadModelName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class ChatState {
|
|||||||
this.isLoadingHistory = true,
|
this.isLoadingHistory = true,
|
||||||
this.isSending = false,
|
this.isSending = false,
|
||||||
this.error,
|
this.error,
|
||||||
|
this.modelName = 'جارٍ اكتشاف النموذج…',
|
||||||
required this.apiBaseUrl,
|
required this.apiBaseUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,6 +70,7 @@ class ChatState {
|
|||||||
final bool isLoadingHistory;
|
final bool isLoadingHistory;
|
||||||
final bool isSending;
|
final bool isSending;
|
||||||
final String? error;
|
final String? error;
|
||||||
|
final String modelName;
|
||||||
final String apiBaseUrl;
|
final String apiBaseUrl;
|
||||||
|
|
||||||
ChatState copyWith({
|
ChatState copyWith({
|
||||||
@@ -80,6 +82,7 @@ class ChatState {
|
|||||||
bool? isSending,
|
bool? isSending,
|
||||||
String? error,
|
String? error,
|
||||||
bool clearError = false,
|
bool clearError = false,
|
||||||
|
String? modelName,
|
||||||
String? apiBaseUrl,
|
String? apiBaseUrl,
|
||||||
}) => ChatState(
|
}) => ChatState(
|
||||||
messages: messages ?? this.messages,
|
messages: messages ?? this.messages,
|
||||||
@@ -91,6 +94,7 @@ class ChatState {
|
|||||||
isLoadingHistory: isLoadingHistory ?? this.isLoadingHistory,
|
isLoadingHistory: isLoadingHistory ?? this.isLoadingHistory,
|
||||||
isSending: isSending ?? this.isSending,
|
isSending: isSending ?? this.isSending,
|
||||||
error: clearError ? null : (error ?? this.error),
|
error: clearError ? null : (error ?? this.error),
|
||||||
|
modelName: modelName ?? this.modelName,
|
||||||
apiBaseUrl: apiBaseUrl ?? this.apiBaseUrl,
|
apiBaseUrl: apiBaseUrl ?? this.apiBaseUrl,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,8 +293,8 @@ class _ChatPageState extends State<ChatPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 7),
|
const SizedBox(height: 7),
|
||||||
const Text(
|
Text(
|
||||||
'qwen2.5:1.5b-instruct-q4_K_M',
|
chat.modelName,
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
style: TextStyle(fontSize: 10, color: Color(0xFF718078)),
|
style: TextStyle(fontSize: 10, color: Color(0xFF718078)),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user