use crate::client::Client;
use crate::error::Error;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Chunk {
pub id: i64,
pub collection_id: i64,
pub document_id: i64,
pub content: String,
#[serde(default)]
pub metadata: Option<serde_json::Value>,
#[serde(default)]
pub created: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Chunks {
pub data: Vec<Chunk>,
}
impl Client {
pub async fn document_chunks(
&self,
document_id: impl std::fmt::Display,
) -> Result<Chunks, Error> {
let url = self.endpoint_with_segment("/v1/chunks", &document_id.to_string())?;
self.get_json(url).await
}
pub async fn chunk(
&self,
document_id: impl std::fmt::Display,
chunk_id: impl std::fmt::Display,
) -> Result<Chunk, Error> {
let url = self.endpoint_with_segments(
"/v1/chunks",
&[&document_id.to_string(), &chunk_id.to_string()],
)?;
self.get_json(url).await
}
}