Skip to content

Commit

Permalink
chore: v2 stream message
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Aug 12, 2024
1 parent a8670d7 commit 324c230
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions appflowy-local-ai/src/ai_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ impl AIPluginOperation {
chat_id: &str,
message: &str,
metadata: serde_json::Value,
) -> Result<ReceiverStream<Result<Bytes, PluginError>>, PluginError> {
) -> Result<ReceiverStream<Result<serde_json::Value, PluginError>>, PluginError> {
let plugin = self.get_plugin()?;
let params = json!({
"chat_id": chat_id,
"method": "stream_answer_v2",
"params": { "content": message, "metadata": metadata }
});
plugin.stream_request::<ChatStreamResponseParser>("handle", &params)
plugin.stream_request::<ChatStreamResponseV2Parser>("handle", &params)
}

pub async fn get_related_questions(&self, chat_id: &str) -> Result<Vec<String>, PluginError> {
Expand Down Expand Up @@ -224,6 +224,15 @@ impl ResponseParser for ChatStreamResponseParser {
}
}

pub struct ChatStreamResponseV2Parser;
impl ResponseParser for ChatStreamResponseV2Parser {
type ValueType = serde_json::Value;

fn parse_json(json: JsonValue) -> Result<Self::ValueType, RemoteError> {
Ok(json)
}
}

pub struct ChatRelatedQuestionsResponseParser;
impl ResponseParser for ChatRelatedQuestionsResponseParser {
type ValueType = Vec<String>;
Expand Down
4 changes: 3 additions & 1 deletion appflowy-local-ai/src/chat_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ impl AppFlowyLocalAI {
self.wait_until_plugin_ready().await?;
let plugin = self.get_ai_plugin().await?;
let operation = AIPluginOperation::new(plugin);
let stream = operation.stream_message(chat_id, message, metadata).await?;
let stream = operation
.stream_message_v2(chat_id, message, metadata)
.await?;
Ok(stream)
}

Expand Down

0 comments on commit 324c230

Please sign in to comment.