mirror of
https://github.com/AppFlowy-IO/AppFlowy-Cloud.git
synced 2025-04-19 03:24:42 -04:00
chore: support completion with format (#1211)
This commit is contained in:
parent
6a816341bf
commit
6648851c61
2 changed files with 48 additions and 1 deletions
|
@ -447,7 +447,16 @@ pub struct SimilarityResponse {
|
|||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct CompletionMetadata {
|
||||
/// A unique identifier for the object.
|
||||
pub object_id: String,
|
||||
/// The workspace identifier.
|
||||
///
|
||||
/// This field must be provided when generating images.
|
||||
pub workspace_id: Option<String>,
|
||||
/// A list of relevant document IDs.
|
||||
///
|
||||
/// When using completions for document-related tasks, this should include the document ID.
|
||||
/// In some cases, `object_id` may be the same as the document ID.
|
||||
pub rag_ids: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
|
@ -459,6 +468,8 @@ pub struct CompleteTextParams {
|
|||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<CompletionMetadata>,
|
||||
#[serde(default)]
|
||||
pub format: ResponseFormat,
|
||||
}
|
||||
|
||||
impl CompleteTextParams {
|
||||
|
@ -472,6 +483,7 @@ impl CompleteTextParams {
|
|||
completion_type: Some(completion_type),
|
||||
custom_prompt: None,
|
||||
metadata,
|
||||
format: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,35 @@
|
|||
use crate::appflowy_ai_client;
|
||||
use appflowy_ai_client::client::collect_stream_text;
|
||||
use appflowy_ai_client::dto::{CompleteTextParams, CompletionType};
|
||||
use appflowy_ai_client::dto::{
|
||||
CompleteTextParams, CompletionMetadata, CompletionType, OutputContent, OutputLayout,
|
||||
ResponseFormat,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn completion_image_test() {
|
||||
let client = appflowy_ai_client();
|
||||
let params = CompleteTextParams {
|
||||
text: "A yellow cat".to_string(),
|
||||
completion_type: Some(CompletionType::ImproveWriting),
|
||||
custom_prompt: None,
|
||||
metadata: Some(CompletionMetadata {
|
||||
object_id: uuid::Uuid::new_v4().to_string(),
|
||||
workspace_id: Some(uuid::Uuid::new_v4().to_string()),
|
||||
rag_ids: None,
|
||||
}),
|
||||
format: ResponseFormat {
|
||||
output_content: OutputContent::IMAGE,
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let stream = client
|
||||
.stream_completion_text(params, "gpt-4o-mini")
|
||||
.await
|
||||
.unwrap();
|
||||
let text = collect_stream_text(stream).await;
|
||||
assert!(text.contains("http://localhost:8000"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn continue_writing_test() {
|
||||
let client = appflowy_ai_client();
|
||||
|
@ -9,6 +38,10 @@ async fn continue_writing_test() {
|
|||
completion_type: Some(CompletionType::ImproveWriting),
|
||||
custom_prompt: None,
|
||||
metadata: None,
|
||||
format: ResponseFormat {
|
||||
output_layout: OutputLayout::SimpleTable,
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let stream = client
|
||||
.stream_completion_text(params, "gpt-4o-mini")
|
||||
|
@ -27,6 +60,7 @@ async fn improve_writing_test() {
|
|||
completion_type: Some(CompletionType::ImproveWriting),
|
||||
custom_prompt: None,
|
||||
metadata: None,
|
||||
format: ResponseFormat::default(),
|
||||
};
|
||||
let stream = client
|
||||
.stream_completion_text(params, "gpt-4o-mini")
|
||||
|
@ -47,6 +81,7 @@ async fn make_text_shorter_text() {
|
|||
completion_type: Some(CompletionType::MakeShorter),
|
||||
custom_prompt: None,
|
||||
metadata: None,
|
||||
format: ResponseFormat::default(),
|
||||
};
|
||||
let stream = client
|
||||
.stream_completion_text(params, "gpt-4o-mini")
|
||||
|
|
Loading…
Add table
Reference in a new issue