Merge pull request #292 from cogwheel0/align-chat-creation
feat(api_service): Add extended assistant message fields for OpenWebUI
This commit is contained in:
@@ -114,14 +114,17 @@ List<Map<String, dynamic>> _convertCodeExecutionsToOpenWebUIFormat(
|
|||||||
// Convert the result if present
|
// Convert the result if present
|
||||||
if (exec.result != null) {
|
if (exec.result != null) {
|
||||||
final execResult = <String, dynamic>{};
|
final execResult = <String, dynamic>{};
|
||||||
if (exec.result!.output != null) execResult['output'] = exec.result!.output;
|
if (exec.result!.output != null)
|
||||||
|
execResult['output'] = exec.result!.output;
|
||||||
if (exec.result!.error != null) execResult['error'] = exec.result!.error;
|
if (exec.result!.error != null) execResult['error'] = exec.result!.error;
|
||||||
if (exec.result!.files.isNotEmpty) {
|
if (exec.result!.files.isNotEmpty) {
|
||||||
execResult['files'] = exec.result!.files
|
execResult['files'] = exec.result!.files
|
||||||
.map((f) => <String, dynamic>{
|
.map(
|
||||||
if (f.name != null) 'name': f.name,
|
(f) => <String, dynamic>{
|
||||||
if (f.url != null) 'url': f.url,
|
if (f.name != null) 'name': f.name,
|
||||||
})
|
if (f.url != null) 'url': f.url,
|
||||||
|
},
|
||||||
|
)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
if (execResult.isNotEmpty) {
|
if (execResult.isNotEmpty) {
|
||||||
@@ -939,11 +942,30 @@ class ApiService {
|
|||||||
'role': msg.role,
|
'role': msg.role,
|
||||||
'content': msg.content,
|
'content': msg.content,
|
||||||
'timestamp': msg.timestamp.millisecondsSinceEpoch ~/ 1000,
|
'timestamp': msg.timestamp.millisecondsSinceEpoch ~/ 1000,
|
||||||
|
// Assistant message fields
|
||||||
|
if (msg.role == 'assistant' && msg.model != null) 'model': msg.model,
|
||||||
|
if (msg.role == 'assistant' && msg.model != null)
|
||||||
|
'modelName': msg.model,
|
||||||
|
if (msg.role == 'assistant') 'modelIdx': 0,
|
||||||
|
if (msg.role == 'assistant') 'done': true,
|
||||||
|
// User message fields
|
||||||
if (msg.role == 'user' && model != null) 'models': [model],
|
if (msg.role == 'user' && model != null) 'models': [model],
|
||||||
if (msg.attachmentIds != null && msg.attachmentIds!.isNotEmpty)
|
if (msg.attachmentIds != null && msg.attachmentIds!.isNotEmpty)
|
||||||
'attachment_ids': List<String>.from(msg.attachmentIds!),
|
'attachment_ids': List<String>.from(msg.attachmentIds!),
|
||||||
if (_sanitizeFilesForWebUI(msg.files) != null)
|
if (_sanitizeFilesForWebUI(msg.files) != null)
|
||||||
'files': _sanitizeFilesForWebUI(msg.files),
|
'files': _sanitizeFilesForWebUI(msg.files),
|
||||||
|
// Assistant message extended fields
|
||||||
|
if (msg.statusHistory.isNotEmpty)
|
||||||
|
'statusHistory': msg.statusHistory.map((s) => s.toJson()).toList(),
|
||||||
|
if (msg.followUps.isNotEmpty)
|
||||||
|
'followUps': List<String>.from(msg.followUps),
|
||||||
|
if (msg.codeExecutions.isNotEmpty)
|
||||||
|
'code_executions': _convertCodeExecutionsToOpenWebUIFormat(
|
||||||
|
msg.codeExecutions,
|
||||||
|
),
|
||||||
|
if (msg.sources.isNotEmpty)
|
||||||
|
'sources': _convertSourcesToOpenWebUIFormat(msg.sources),
|
||||||
|
if (msg.usage != null) 'usage': msg.usage,
|
||||||
// Preserve error field for OpenWebUI compatibility
|
// Preserve error field for OpenWebUI compatibility
|
||||||
if (msg.error != null) 'error': msg.error!.toJson(),
|
if (msg.error != null) 'error': msg.error!.toJson(),
|
||||||
};
|
};
|
||||||
@@ -961,11 +983,30 @@ class ApiService {
|
|||||||
'role': msg.role,
|
'role': msg.role,
|
||||||
'content': msg.content,
|
'content': msg.content,
|
||||||
'timestamp': msg.timestamp.millisecondsSinceEpoch ~/ 1000,
|
'timestamp': msg.timestamp.millisecondsSinceEpoch ~/ 1000,
|
||||||
|
// Assistant message fields
|
||||||
|
if (msg.role == 'assistant' && msg.model != null) 'model': msg.model,
|
||||||
|
if (msg.role == 'assistant' && msg.model != null)
|
||||||
|
'modelName': msg.model,
|
||||||
|
if (msg.role == 'assistant') 'modelIdx': 0,
|
||||||
|
if (msg.role == 'assistant') 'done': true,
|
||||||
|
// User message fields
|
||||||
if (msg.role == 'user' && model != null) 'models': [model],
|
if (msg.role == 'user' && model != null) 'models': [model],
|
||||||
if (msg.attachmentIds != null && msg.attachmentIds!.isNotEmpty)
|
if (msg.attachmentIds != null && msg.attachmentIds!.isNotEmpty)
|
||||||
'attachment_ids': List<String>.from(msg.attachmentIds!),
|
'attachment_ids': List<String>.from(msg.attachmentIds!),
|
||||||
if (_sanitizeFilesForWebUI(msg.files) != null)
|
if (_sanitizeFilesForWebUI(msg.files) != null)
|
||||||
'files': _sanitizeFilesForWebUI(msg.files),
|
'files': _sanitizeFilesForWebUI(msg.files),
|
||||||
|
// Assistant message extended fields
|
||||||
|
if (msg.statusHistory.isNotEmpty)
|
||||||
|
'statusHistory': msg.statusHistory.map((s) => s.toJson()).toList(),
|
||||||
|
if (msg.followUps.isNotEmpty)
|
||||||
|
'followUps': List<String>.from(msg.followUps),
|
||||||
|
if (msg.codeExecutions.isNotEmpty)
|
||||||
|
'code_executions': _convertCodeExecutionsToOpenWebUIFormat(
|
||||||
|
msg.codeExecutions,
|
||||||
|
),
|
||||||
|
if (msg.sources.isNotEmpty)
|
||||||
|
'sources': _convertSourcesToOpenWebUIFormat(msg.sources),
|
||||||
|
if (msg.usage != null) 'usage': msg.usage,
|
||||||
// Preserve error field for OpenWebUI compatibility
|
// Preserve error field for OpenWebUI compatibility
|
||||||
if (msg.error != null) 'error': msg.error!.toJson(),
|
if (msg.error != null) 'error': msg.error!.toJson(),
|
||||||
});
|
});
|
||||||
@@ -1080,8 +1121,9 @@ class ApiService {
|
|||||||
if (msg.followUps.isNotEmpty)
|
if (msg.followUps.isNotEmpty)
|
||||||
'followUps': List<String>.from(msg.followUps),
|
'followUps': List<String>.from(msg.followUps),
|
||||||
if (msg.codeExecutions.isNotEmpty)
|
if (msg.codeExecutions.isNotEmpty)
|
||||||
'code_executions':
|
'code_executions': _convertCodeExecutionsToOpenWebUIFormat(
|
||||||
_convertCodeExecutionsToOpenWebUIFormat(msg.codeExecutions),
|
msg.codeExecutions,
|
||||||
|
),
|
||||||
// Convert sources back to OpenWebUI format (with document array)
|
// Convert sources back to OpenWebUI format (with document array)
|
||||||
if (msg.sources.isNotEmpty)
|
if (msg.sources.isNotEmpty)
|
||||||
'sources': _convertSourcesToOpenWebUIFormat(msg.sources),
|
'sources': _convertSourcesToOpenWebUIFormat(msg.sources),
|
||||||
@@ -1122,8 +1164,9 @@ class ApiService {
|
|||||||
if (msg.followUps.isNotEmpty)
|
if (msg.followUps.isNotEmpty)
|
||||||
'followUps': List<String>.from(msg.followUps),
|
'followUps': List<String>.from(msg.followUps),
|
||||||
if (msg.codeExecutions.isNotEmpty)
|
if (msg.codeExecutions.isNotEmpty)
|
||||||
'code_executions':
|
'code_executions': _convertCodeExecutionsToOpenWebUIFormat(
|
||||||
_convertCodeExecutionsToOpenWebUIFormat(msg.codeExecutions),
|
msg.codeExecutions,
|
||||||
|
),
|
||||||
// Convert sources back to OpenWebUI format (with document array)
|
// Convert sources back to OpenWebUI format (with document array)
|
||||||
if (msg.sources.isNotEmpty)
|
if (msg.sources.isNotEmpty)
|
||||||
'sources': _convertSourcesToOpenWebUIFormat(msg.sources),
|
'sources': _convertSourcesToOpenWebUIFormat(msg.sources),
|
||||||
@@ -1161,8 +1204,9 @@ class ApiService {
|
|||||||
if (ver.followUps.isNotEmpty)
|
if (ver.followUps.isNotEmpty)
|
||||||
'followUps': List<String>.from(ver.followUps),
|
'followUps': List<String>.from(ver.followUps),
|
||||||
if (ver.codeExecutions.isNotEmpty)
|
if (ver.codeExecutions.isNotEmpty)
|
||||||
'code_executions':
|
'code_executions': _convertCodeExecutionsToOpenWebUIFormat(
|
||||||
_convertCodeExecutionsToOpenWebUIFormat(ver.codeExecutions),
|
ver.codeExecutions,
|
||||||
|
),
|
||||||
// Convert sources back to OpenWebUI format (with document array)
|
// Convert sources back to OpenWebUI format (with document array)
|
||||||
if (ver.sources.isNotEmpty)
|
if (ver.sources.isNotEmpty)
|
||||||
'sources': _convertSourcesToOpenWebUIFormat(ver.sources),
|
'sources': _convertSourcesToOpenWebUIFormat(ver.sources),
|
||||||
|
|||||||
Reference in New Issue
Block a user