-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
332 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::sync::Arc; | ||
|
||
use async_stream::stream; | ||
use async_trait::async_trait; | ||
use futures::stream::BoxStream; | ||
use serde_json::json; | ||
use tabby_common::index::structured_doc::fields; | ||
use tabby_inference::Embedding; | ||
use tokio::task::JoinHandle; | ||
|
||
use super::{build_tokens, BuildStructuredDoc}; | ||
|
||
pub struct PullRequest { | ||
pub link: String, | ||
pub title: String, | ||
pub body: String, | ||
pub diff: String, | ||
pub state: String, | ||
} | ||
|
||
#[async_trait] | ||
impl BuildStructuredDoc for PullRequest { | ||
fn should_skip(&self) -> bool { | ||
false | ||
} | ||
|
||
async fn build_attributes(&self) -> serde_json::Value { | ||
json!({ | ||
fields::pull::LINK: self.link, | ||
fields::pull::TITLE: self.title, | ||
fields::pull::BODY: self.body, | ||
fields::pull::DIFF: self.diff, | ||
fields::pull::STATE: self.state, | ||
}) | ||
} | ||
|
||
async fn build_chunk_attributes( | ||
&self, | ||
embedding: Arc<dyn Embedding>, | ||
) -> BoxStream<JoinHandle<(Vec<String>, serde_json::Value)>> { | ||
let text = format!("{}\n\n{}\n\n{}", self.title, self.body, self.diff); | ||
let s = stream! { | ||
yield tokio::spawn(async move { | ||
let tokens = build_tokens(embedding, &text).await; | ||
let chunk_attributes = json!({}); | ||
(tokens, chunk_attributes) | ||
}) | ||
}; | ||
|
||
Box::pin(s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.