Skip to content

Commit

Permalink
feat(transformers): builder and clone for MetadataQACode
Browse files Browse the repository at this point in the history
  • Loading branch information
timonv committed Jun 16, 2024
1 parent c074cc0 commit e18e7fa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion swiftide/src/transformers/metadata_qa_code.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use derive_builder::Builder;
use std::sync::Arc;

use crate::{ingestion::IngestionNode, SimplePrompt, Transformer};
Expand All @@ -8,15 +9,27 @@ use indoc::indoc;
/// `MetadataQACode` is responsible for generating questions and answers based on code chunks.
/// This struct integrates with the ingestion pipeline to enhance the metadata of each code chunk
/// by adding relevant questions and answers.
#[derive(Debug)]
#[derive(Debug, Clone, Builder)]
#[builder(setter(into, strip_option))]
pub struct MetadataQACode {
#[builder(setter(custom))]
client: Arc<dyn SimplePrompt>,
#[builder(default = "default_prompt()")]
prompt: String,
#[builder(default = "5")]
num_questions: usize,
#[builder(default)]
concurrency: Option<usize>,
}

impl MetadataQACode {
pub fn builder() -> MetadataQACodeBuilder {
MetadataQACodeBuilder::default()
}

pub fn from_client(client: impl SimplePrompt + 'static) -> MetadataQACodeBuilder {
MetadataQACodeBuilder::default().client(client).to_owned()
}
/// Creates a new instance of `MetadataQACode`.
///
/// # Arguments
Expand Down Expand Up @@ -85,6 +98,13 @@ fn default_prompt() -> String {
.to_string()
}

impl MetadataQACodeBuilder {
pub fn client(&mut self, client: impl SimplePrompt + 'static) -> &mut Self {
self.client = Some(Arc::new(client));
self
}
}

#[async_trait]
impl Transformer for MetadataQACode {
/// Asynchronously transforms an `IngestionNode` by generating questions and answers for its code chunk.
Expand Down

0 comments on commit e18e7fa

Please sign in to comment.