2024-07-15 15:23:23 +08:00
|
|
|
use client_api::entity::ai_dto::{CompletionType, LocalAIConfig, RepeatedRelatedQuestion};
|
2024-08-06 07:56:13 +08:00
|
|
|
use flowy_ai_pub::cloud::{
|
2024-11-14 00:51:07 +08:00
|
|
|
ChatCloudService, ChatMessage, ChatMessageMetadata, ChatMessageType, MessageCursor,
|
|
|
|
RepeatedChatMessage, StreamAnswer, StreamComplete, SubscriptionPlan,
|
2024-08-06 07:56:13 +08:00
|
|
|
};
|
2024-06-03 14:27:28 +08:00
|
|
|
use flowy_error::FlowyError;
|
|
|
|
use lib_infra::async_trait::async_trait;
|
2024-08-12 15:43:17 +08:00
|
|
|
use serde_json::Value;
|
|
|
|
use std::collections::HashMap;
|
2024-08-08 12:07:00 +08:00
|
|
|
use std::path::Path;
|
2024-06-03 14:27:28 +08:00
|
|
|
|
|
|
|
pub(crate) struct DefaultChatCloudServiceImpl;
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl ChatCloudService for DefaultChatCloudServiceImpl {
|
2024-08-14 10:33:23 +08:00
|
|
|
async fn create_chat(
|
2024-06-03 14:27:28 +08:00
|
|
|
&self,
|
|
|
|
_uid: &i64,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_chat_id: &str,
|
2024-08-14 10:33:23 +08:00
|
|
|
) -> Result<(), FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("Chat is not supported in local server."))
|
2024-06-03 14:27:28 +08:00
|
|
|
}
|
|
|
|
|
2024-08-09 21:55:20 +08:00
|
|
|
async fn create_question(
|
2024-06-09 14:02:32 +08:00
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_chat_id: &str,
|
|
|
|
_message: &str,
|
|
|
|
_message_type: ChatMessageType,
|
2024-08-09 21:55:20 +08:00
|
|
|
_metadata: &[ChatMessageMetadata],
|
|
|
|
) -> Result<ChatMessage, FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("Chat is not supported in local server."))
|
2024-06-09 14:02:32 +08:00
|
|
|
}
|
|
|
|
|
2024-08-11 20:39:25 +08:00
|
|
|
async fn create_answer(
|
2024-06-09 14:02:32 +08:00
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_chat_id: &str,
|
|
|
|
_message: &str,
|
|
|
|
_question_id: i64,
|
2024-08-06 07:56:13 +08:00
|
|
|
_metadata: Option<serde_json::Value>,
|
2024-08-11 20:39:25 +08:00
|
|
|
) -> Result<ChatMessage, FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("Chat is not supported in local server."))
|
2024-06-09 14:02:32 +08:00
|
|
|
}
|
|
|
|
|
2024-08-06 07:56:13 +08:00
|
|
|
async fn stream_answer(
|
2024-06-09 14:02:32 +08:00
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_chat_id: &str,
|
|
|
|
_message_id: i64,
|
|
|
|
) -> Result<StreamAnswer, FlowyError> {
|
2024-06-03 14:27:28 +08:00
|
|
|
Err(FlowyError::not_support().with_context("Chat is not supported in local server."))
|
|
|
|
}
|
|
|
|
|
2024-08-11 20:39:25 +08:00
|
|
|
async fn get_chat_messages(
|
2024-06-03 14:27:28 +08:00
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_chat_id: &str,
|
|
|
|
_offset: MessageCursor,
|
|
|
|
_limit: u64,
|
2024-08-11 20:39:25 +08:00
|
|
|
) -> Result<RepeatedChatMessage, FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("Chat is not supported in local server."))
|
2024-06-03 14:27:28 +08:00
|
|
|
}
|
|
|
|
|
2024-07-25 19:41:16 +08:00
|
|
|
async fn get_related_message(
|
2024-06-03 14:27:28 +08:00
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_chat_id: &str,
|
|
|
|
_message_id: i64,
|
2024-07-25 19:41:16 +08:00
|
|
|
) -> Result<RepeatedRelatedQuestion, FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("Chat is not supported in local server."))
|
2024-06-03 14:27:28 +08:00
|
|
|
}
|
|
|
|
|
2024-08-06 07:56:13 +08:00
|
|
|
async fn get_answer(
|
2024-06-03 14:27:28 +08:00
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_chat_id: &str,
|
|
|
|
_question_message_id: i64,
|
2024-06-30 17:38:39 +08:00
|
|
|
) -> Result<ChatMessage, FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("Chat is not supported in local server."))
|
2024-06-03 14:27:28 +08:00
|
|
|
}
|
2024-06-25 01:59:38 +02:00
|
|
|
|
|
|
|
async fn stream_complete(
|
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_text: &str,
|
|
|
|
_complete_type: CompletionType,
|
|
|
|
) -> Result<StreamComplete, FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("complete text is not supported in local server."))
|
|
|
|
}
|
2024-07-15 15:23:23 +08:00
|
|
|
|
|
|
|
async fn index_file(
|
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
2024-08-08 12:07:00 +08:00
|
|
|
_file_path: &Path,
|
2024-07-15 15:23:23 +08:00
|
|
|
_chat_id: &str,
|
2024-08-12 15:43:17 +08:00
|
|
|
_metadata: Option<HashMap<String, Value>>,
|
2024-07-15 15:23:23 +08:00
|
|
|
) -> Result<(), FlowyError> {
|
|
|
|
Err(FlowyError::not_support().with_context("indexing file is not supported in local server."))
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_local_ai_config(&self, _workspace_id: &str) -> Result<LocalAIConfig, FlowyError> {
|
|
|
|
Err(
|
|
|
|
FlowyError::not_support()
|
|
|
|
.with_context("Get local ai config is not supported in local server."),
|
|
|
|
)
|
|
|
|
}
|
2024-09-01 17:48:07 +08:00
|
|
|
|
|
|
|
async fn get_workspace_plan(
|
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
) -> Result<Vec<SubscriptionPlan>, FlowyError> {
|
|
|
|
Err(
|
|
|
|
FlowyError::not_support()
|
|
|
|
.with_context("Get local ai config is not supported in local server."),
|
|
|
|
)
|
|
|
|
}
|
2024-06-03 14:27:28 +08:00
|
|
|
}
|