Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 9 additions & 62 deletions app/lib/backend/http/api/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Future<List<ServerMessage>> getMessagesServer({
Future<List<ServerMessage>> clearChatServer({String? pluginId}) async {
if (pluginId == 'no_selected') pluginId = null;
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/messages?plugin_id=${pluginId ?? ''}',
url: '${Env.apiBaseUrl}v2/messages?plugin_id=${pluginId ?? ''}',
headers: {},
method: 'DELETE',
body: '',
Expand All @@ -53,32 +53,6 @@ Future<List<ServerMessage>> clearChatServer({String? pluginId}) async {
}
}

Future<ServerMessage> sendMessageServer(String text, {String? appId, List<String>? fileIds}) {
var url = '${Env.apiBaseUrl}v1/messages?plugin_id=$appId';
if (appId == null || appId.isEmpty || appId == 'null' || appId == 'no_selected') {
url = '${Env.apiBaseUrl}v1/messages';
}
return makeApiCall(
url: url,
headers: {},
method: 'POST',
body: jsonEncode({'text': text, 'file_ids': fileIds}),
).then((response) {
if (response == null) throw Exception('Failed to send message');
if (response.statusCode == 200) {
return ServerMessage.fromJson(jsonDecode(response.body));
} else {
Logger.error('Failed to send message ${response.body}');
CrashReporting.reportHandledCrash(
Exception('Failed to send message ${response.body}'),
StackTrace.current,
level: NonFatalExceptionLevel.error,
);
return ServerMessage.failedMessage();
}
});
}

ServerMessageChunk? parseMessageChunk(String line, String messageId) {
if (line.startsWith('think: ')) {
return ServerMessageChunk(messageId, line.substring(7).replaceAll("__CRLF__", "\n"), MessageChunkType.think);
Expand Down Expand Up @@ -164,7 +138,7 @@ Stream<ServerMessageChunk> sendMessageStreamServer(String text, {String? appId,

Future<ServerMessage> getInitialAppMessage(String? appId) {
return makeApiCall(
url: '${Env.apiBaseUrl}v1/initial-message?plugin_id=$appId',
url: '${Env.apiBaseUrl}v2/initial-message?app_id=$appId',
headers: {},
method: 'POST',
body: '',
Expand Down Expand Up @@ -235,36 +209,10 @@ Stream<ServerMessageChunk> sendVoiceMessageStreamServer(List<File> files) async*
}
}

Future<List<ServerMessage>> sendVoiceMessageServer(List<File> files) async {
var request = http.MultipartRequest(
'POST',
Uri.parse('${Env.apiBaseUrl}v1/voice-messages'),
);
for (var file in files) {
request.files.add(await http.MultipartFile.fromPath('files', file.path, filename: basename(file.path)));
}
request.headers.addAll({'Authorization': await getAuthHeader()});

try {
var streamedResponse = await request.send();
var response = await http.Response.fromStream(streamedResponse);
if (response.statusCode == 200) {
debugPrint('sendVoiceMessageServer response body: ${jsonDecode(response.body)}');
return ((jsonDecode(response.body) ?? []) as List<dynamic>).map((m) => ServerMessage.fromJson(m)).toList();
} else {
debugPrint('Failed to upload sample. Status code: ${response.statusCode} ${response.body}');
throw Exception('Failed to upload sample. Status code: ${response.statusCode}');
}
} catch (e) {
debugPrint('An error occurred uploadSample: $e');
throw Exception('An error occurred uploadSample: $e');
}
}

Future<List<MessageFile>?> uploadFilesServer(List<File> files, {String? appId}) async {
var url = '${Env.apiBaseUrl}v1/files?plugin_id=$appId';
var url = '${Env.apiBaseUrl}v2/files?app_id=$appId';
if (appId == null || appId.isEmpty || appId == 'null' || appId == 'no_selected') {
url = '${Env.apiBaseUrl}v1/files';
url = '${Env.apiBaseUrl}v2/files';
}
var request = http.MultipartRequest(
'POST',
Expand Down Expand Up @@ -301,7 +249,7 @@ Future<List<MessageFile>?> uploadFilesServer(List<File> files, {String? appId})

Future reportMessageServer(String messageId) async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/messages/$messageId/report',
url: '${Env.apiBaseUrl}v2/messages/$messageId/report',
headers: {},
method: 'POST',
body: '',
Expand All @@ -312,20 +260,19 @@ Future reportMessageServer(String messageId) async {
}
}


Future<String> transcribeVoiceMessage(File audioFile) async {
try {
var request = http.MultipartRequest(
'POST',
Uri.parse('${Env.apiBaseUrl}v1/voice-message/transcribe'),
Uri.parse('${Env.apiBaseUrl}v2/voice-message/transcribe'),
);

request.headers.addAll({'Authorization': await getAuthHeader()});
request.files.add(await http.MultipartFile.fromPath('files', audioFile.path));

var streamedResponse = await request.send();
var response = await http.Response.fromStream(streamedResponse);

if (response.statusCode == 200) {
final data = jsonDecode(response.body);
return data['transcript'] ?? '';
Expand Down
12 changes: 0 additions & 12 deletions app/lib/providers/message_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -412,18 +412,6 @@ class MessageProvider extends ChangeNotifier {
setShowTypingIndicator(false);
}

Future sendMessageToServer(String text, String? appId) async {
setShowTypingIndicator(true);
messages.insert(0, ServerMessage.empty(appId: appId));
List<String> fileIds = uploadedFiles.map((e) => e.id).toList();
var mes = await sendMessageServer(text, appId: appId, fileIds: fileIds);
if (messages[0].id == '0000') {
messages[0] = mes;
}
setShowTypingIndicator(false);
notifyListeners();
}

Future sendInitialAppMessage(App? app) async {
setSendingMessage(true);
ServerMessage message = await getInitialAppMessage(app?.id);
Expand Down
4 changes: 2 additions & 2 deletions backend/database/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ def batch_delete_messages(parent_doc_ref, batch_size=450, plugin_id: Optional[st
last_doc = docs_list[-1]


def clear_chat(uid: str, plugin_id: Optional[str] = None, chat_session_id: Optional[str] = None):
def clear_chat(uid: str, app_id: Optional[str] = None, chat_session_id: Optional[str] = None):
try:
user_ref = db.collection('users').document(uid)
print(f"Deleting messages for user: {uid}")
if not user_ref.get().exists:
return {"message": "User not found"}
batch_delete_messages(user_ref, plugin_id=plugin_id, chat_session_id=chat_session_id)
batch_delete_messages(user_ref, plugin_id=app_id, chat_session_id=chat_session_id)
return None
except Exception as e:
return {"message": str(e)}
Expand Down
99 changes: 0 additions & 99 deletions backend/database/processing_conversations.py

This file was deleted.

2 changes: 1 addition & 1 deletion backend/database/vector_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pinecone import Pinecone

from models.conversation import Conversation
from utils.llm import embeddings
from utils.llm.clients import embeddings

if os.getenv('PINECONE_API_KEY') is not None:
pc = Pinecone(api_key=os.getenv('PINECONE_API_KEY', ''))
Expand Down
3 changes: 1 addition & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from modal import Image, App, asgi_app, Secret
from routers import workflow, chat, firmware, plugins, transcribe, notifications, \
speech_profile, agents, users, processing_conversations, trends, sync, apps, custom_auth, \
speech_profile, agents, users, trends, sync, apps, custom_auth, \
payment, integration, conversations, memories, mcp

from utils.other.timeout import TimeoutMiddleware
Expand All @@ -31,7 +31,6 @@
app.include_router(integration.router)
app.include_router(agents.router)
app.include_router(users.router)
app.include_router(processing_conversations.router)
app.include_router(trends.router)

app.include_router(firmware.router)
Expand Down
104 changes: 0 additions & 104 deletions backend/models/plugin.py

This file was deleted.

Loading