feat: Stream chat message (#5498)

* chore: stream message

* chore: stream message

* chore: fix streaming

* chore: fix clippy
This commit is contained in:
Nathan.fooo
2024-06-09 14:02:32 +08:00
committed by GitHub
parent 94060a0a99
commit bb3e9d5bd8
46 changed files with 1691 additions and 870 deletions

View File

@ -30,6 +30,7 @@ use tokio::sync::RwLock;
use crate::integrate::server::ServerProvider;
pub struct FolderDepsResolver();
#[allow(clippy::too_many_arguments)]
impl FolderDepsResolver {
pub async fn resolve(
authenticate_user: Weak<AuthenticateUser>,

View File

@ -18,6 +18,7 @@ use collab_integrate::collab_builder::{
};
use flowy_chat_pub::cloud::{
ChatCloudService, ChatMessage, ChatMessageStream, MessageCursor, RepeatedChatMessage,
StreamAnswer,
};
use flowy_database_pub::cloud::{
CollabDocStateByOid, DatabaseCloudService, DatabaseSnapshot, SummaryRowContent,
@ -476,6 +477,60 @@ impl ChatCloudService for ServerProvider {
.await
}
fn send_question(
&self,
workspace_id: &str,
chat_id: &str,
message: &str,
message_type: ChatMessageType,
) -> FutureResult<ChatMessage, FlowyError> {
let workspace_id = workspace_id.to_string();
let chat_id = chat_id.to_string();
let message = message.to_string();
let server = self.get_server();
FutureResult::new(async move {
server?
.chat_service()
.send_question(&workspace_id, &chat_id, &message, message_type)
.await
})
}
fn save_answer(
&self,
workspace_id: &str,
chat_id: &str,
message: &str,
question_id: i64,
) -> FutureResult<ChatMessage, FlowyError> {
let workspace_id = workspace_id.to_string();
let chat_id = chat_id.to_string();
let message = message.to_string();
let server = self.get_server();
FutureResult::new(async move {
server?
.chat_service()
.save_answer(&workspace_id, &chat_id, &message, question_id)
.await
})
}
async fn stream_answer(
&self,
workspace_id: &str,
chat_id: &str,
message_id: i64,
) -> Result<StreamAnswer, FlowyError> {
let workspace_id = workspace_id.to_string();
let chat_id = chat_id.to_string();
let server = self.get_server()?;
server
.chat_service()
.stream_answer(&workspace_id, &chat_id, message_id)
.await
}
fn get_chat_messages(
&self,
workspace_id: &str,