use crate::generated::{
AskQuestionData, AskQuestionDataSourcesCitationsItem, AskRequest, SearchPassagesRequest,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SourceFormat {
None,
Json,
Inline,
Footnotes,
Expanded,
}
impl SourceFormat {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
SourceFormat::None => "none",
SourceFormat::Json => "json",
SourceFormat::Inline => "inline",
SourceFormat::Footnotes => "footnotes",
SourceFormat::Expanded => "expanded",
}
}
}
impl AskRequest {
#[must_use]
pub fn new(notebook_id: impl Into<String>, question: impl Into<String>) -> Self {
Self {
question: question.into(),
notebook_id: Some(notebook_id.into()),
source_format: Some(SourceFormat::Json.as_str().to_owned()),
..Self::default()
}
}
#[must_use]
pub fn in_session(mut self, session_id: impl Into<String>) -> Self {
self.session_id = Some(session_id.into());
self
}
#[must_use]
pub fn at_url(mut self, notebook_url: impl Into<String>) -> Self {
self.notebook_url = Some(notebook_url.into());
self.notebook_id = None;
self
}
#[must_use]
pub fn with_source_format(mut self, format: SourceFormat) -> Self {
self.source_format = Some(format.as_str().to_owned());
self
}
}
impl AskQuestionData {
pub fn citations(&self) -> impl Iterator<Item = &AskQuestionDataSourcesCitationsItem> {
self.sources.citations.iter()
}
}
impl SearchPassagesRequest {
#[must_use]
pub fn new(query: impl Into<String>) -> Self {
Self {
query: query.into(),
..Self::default()
}
}
#[must_use]
pub fn limit(mut self, limit: i64) -> Self {
self.limit = Some(limit);
self
}
#[must_use]
pub fn in_sources(mut self, source_ids: impl IntoIterator<Item = String>) -> Self {
self.source_ids = Some(source_ids.into_iter().collect());
self
}
}