chore: support completion with format (#1211)
This commit is contained in:
parent
6a816341bf
commit
6648851c61
|
|
@ -447,7 +447,16 @@ pub struct SimilarityResponse {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct CompletionMetadata {
|
pub struct CompletionMetadata {
|
||||||
|
/// A unique identifier for the object.
|
||||||
pub object_id: String,
|
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>>,
|
pub rag_ids: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -459,6 +468,8 @@ pub struct CompleteTextParams {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub metadata: Option<CompletionMetadata>,
|
pub metadata: Option<CompletionMetadata>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub format: ResponseFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompleteTextParams {
|
impl CompleteTextParams {
|
||||||
|
|
@ -472,6 +483,7 @@ impl CompleteTextParams {
|
||||||
completion_type: Some(completion_type),
|
completion_type: Some(completion_type),
|
||||||
custom_prompt: None,
|
custom_prompt: None,
|
||||||
metadata,
|
metadata,
|
||||||
|
format: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,35 @@
|
||||||
use crate::appflowy_ai_client;
|
use crate::appflowy_ai_client;
|
||||||
use appflowy_ai_client::client::collect_stream_text;
|
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]
|
#[tokio::test]
|
||||||
async fn continue_writing_test() {
|
async fn continue_writing_test() {
|
||||||
let client = appflowy_ai_client();
|
let client = appflowy_ai_client();
|
||||||
|
|
@ -9,6 +38,10 @@ async fn continue_writing_test() {
|
||||||
completion_type: Some(CompletionType::ImproveWriting),
|
completion_type: Some(CompletionType::ImproveWriting),
|
||||||
custom_prompt: None,
|
custom_prompt: None,
|
||||||
metadata: None,
|
metadata: None,
|
||||||
|
format: ResponseFormat {
|
||||||
|
output_layout: OutputLayout::SimpleTable,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
};
|
};
|
||||||
let stream = client
|
let stream = client
|
||||||
.stream_completion_text(params, "gpt-4o-mini")
|
.stream_completion_text(params, "gpt-4o-mini")
|
||||||
|
|
@ -27,6 +60,7 @@ async fn improve_writing_test() {
|
||||||
completion_type: Some(CompletionType::ImproveWriting),
|
completion_type: Some(CompletionType::ImproveWriting),
|
||||||
custom_prompt: None,
|
custom_prompt: None,
|
||||||
metadata: None,
|
metadata: None,
|
||||||
|
format: ResponseFormat::default(),
|
||||||
};
|
};
|
||||||
let stream = client
|
let stream = client
|
||||||
.stream_completion_text(params, "gpt-4o-mini")
|
.stream_completion_text(params, "gpt-4o-mini")
|
||||||
|
|
@ -47,6 +81,7 @@ async fn make_text_shorter_text() {
|
||||||
completion_type: Some(CompletionType::MakeShorter),
|
completion_type: Some(CompletionType::MakeShorter),
|
||||||
custom_prompt: None,
|
custom_prompt: None,
|
||||||
metadata: None,
|
metadata: None,
|
||||||
|
format: ResponseFormat::default(),
|
||||||
};
|
};
|
||||||
let stream = client
|
let stream = client
|
||||||
.stream_completion_text(params, "gpt-4o-mini")
|
.stream_completion_text(params, "gpt-4o-mini")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue